diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-01 01:57:06 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-01 01:57:06 +0000 |
commit | c5dcec789e5513ef1cfd8ef468cd2a46cdaf01f5 (patch) | |
tree | f3a166ae1d6f2c69619871b4c326f70cf706a0d7 /railties/lib/rails_generator/commands.rb | |
parent | 98a9b6521886009187afd324e0cdad64902e0e97 (diff) | |
download | rails-c5dcec789e5513ef1cfd8ef468cd2a46cdaf01f5.tar.gz rails-c5dcec789e5513ef1cfd8ef468cd2a46cdaf01f5.tar.bz2 rails-c5dcec789e5513ef1cfd8ef468cd2a46cdaf01f5.zip |
resource and scaffold_resource generators add a restful route to config/routes.rb
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5379 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator/commands.rb')
-rw-r--r-- | railties/lib/rails_generator/commands.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 0d039838d3..9bc20b1c79 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -83,6 +83,12 @@ module Rails "%.#{padding}d" % next_migration_number end + def gsub_file(relative_destination, regexp, *args, &block) + path = destination_path(relative_destination) + content = File.read(path).gsub(regexp, *args, &block) + File.open(path, 'wb') { |file| file.write(content) } + end + private # Ask the user interactively whether to force collision. def force_file_collision?(destination) @@ -316,6 +322,16 @@ module Rails template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options) end + def route_resources(*resources) + resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') + sentinel = 'ActionController::Routing::Routes.draw do |map|' + + logger.route "map.resources #{resource_list}" + gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| + "#{match}\n map.resources #{resource_list}\n" + end + end + private # Raise a usage error with an informative WordNet suggestion. # Thanks to Florian Gross (flgr). @@ -438,6 +454,13 @@ end_message file(relative_source, file_path, template_options) end end + + def route_resources(*resources) + resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') + look_for = "\n map.resources #{resource_list}\n" + logger.route "map.resources #{resource_list}" + gsub_file 'config/routes.rb', /(#{look_for})/mi, '' + end end @@ -475,6 +498,11 @@ end_message migration_directory relative_destination logger.migration_template file_name end + + def route_resources(*resources) + resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') + logger.route "map.resources #{resource_list}" + end end # Update generator's action manifest. |