Permalink
Browse files

resource and scaffold_resource generators add a restful route to conf…

…ig/routes.rb

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5379 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 98a9b65 commit c5dcec789e5513ef1cfd8ef468cd2a46cdaf01f5 @jeremy jeremy committed Nov 1, 2006
View
@@ -1,5 +1,7 @@
*SVN*
+* resource and scaffold_resource generators add a restful route to config/routes.rb [Jeremy Kemper]
+
* Revert environment changes for autoload_paths. [Koz]
* Update to latest Prototype, which doesn't serialize disabled form elements, adds clone() to arrays, empty/non-string Element.update() and adds a fixes excessive error reporting in WebKit beta versions [Thomas Fuchs]
@@ -83,6 +83,12 @@ def next_migration_string(padding = 3)
"%.#{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 @@ def migration_template(relative_source, relative_destination, template_options =
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 @@ def migration_template(relative_source, relative_destination, template_options =
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 @@ def migration_template(relative_source, relative_destination, options = {})
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.
@@ -26,7 +26,7 @@ def initialize(runtime_args, runtime_options = {})
end
def manifest
- recorded_session = record do |m|
+ record do |m|
# Check for class naming collisions.
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
m.class_collisions(class_path, "#{class_name}")
@@ -60,18 +60,9 @@ def manifest
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
)
end
- end
-
- puts
- puts ("-" * 70)
- puts "Don't forget the restful route in config/routes.rb"
- puts
- puts " map.resources :#{controller_file_name}"
- puts
- puts ("-" * 70)
- puts
- recorded_session
+ m.route_resources controller_file_name
+ end
end
protected
@@ -26,7 +26,7 @@ def initialize(runtime_args, runtime_options = {})
end
def manifest
- recorded_session = record do |m|
+ record do |m|
# Check for class naming collisions.
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
m.class_collisions(class_path, "#{class_name}")
@@ -67,18 +67,9 @@ def manifest
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
)
end
- end
-
- puts
- puts ("-" * 70)
- puts "Don't forget the restful route in config/routes.rb"
- puts
- puts " map.resources :#{controller_file_name}"
- puts
- puts ("-" * 70)
- puts
- recorded_session
+ m.route_resources controller_file_name
+ end
end
protected

0 comments on commit c5dcec7

Please sign in to comment.