diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-24 15:46:29 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-24 21:02:30 +0200 |
commit | bac0826b1fa5f39274d61ad51304548c725a304f (patch) | |
tree | a8389dc480a95838925e51954a5e0a2dc658c54c /railties/lib/rails | |
parent | e83634081a9222446df608106c8df5a6831d64db (diff) | |
download | rails-bac0826b1fa5f39274d61ad51304548c725a304f.tar.gz rails-bac0826b1fa5f39274d61ad51304548c725a304f.tar.bz2 rails-bac0826b1fa5f39274d61ad51304548c725a304f.zip |
Refactor namespaced generators to use module_namespacing block helper
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties/lib/rails')
5 files changed, 16 insertions, 15 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 7fae505883..6db294290a 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -17,6 +17,16 @@ module Rails end protected + def module_namespacing(&block) + inside_namespace do + content = capture(&block) + if namespaced? + content = indent(content) + content = wrap_with_namespace(content) + end + concat(content) + end + end def indent(content, multiplier = 2) spaces = " " * multiplier @@ -27,19 +37,6 @@ module Rails "module #{namespace.name}\n#{content}\nend\n" end - def namespaced_template(source, *args, &block) - inside_namespace do - template(source, *args) do |content| - content = block.call(content) if block_given? - if namespace - content = indent(content) - content = wrap_with_namespace(content) - end - content - end - end - end - def inside_namespace @inside_namespace = true if namespaced? result = yield diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 981ce88474..9788c0d0bc 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -5,7 +5,7 @@ module Rails check_class_collision :suffix => "Controller" def create_controller_files - namespaced_template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb") + template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb") end def add_routes diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb index cda2659e69..c61ea4b510 100644 --- a/railties/lib/rails/generators/rails/controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb @@ -1,3 +1,4 @@ +<% module_namespacing do -%> class <%= class_name %>Controller < ApplicationController <% for action in actions -%> def <%= action %> @@ -5,3 +6,4 @@ class <%= class_name %>Controller < ApplicationController <% end -%> end +<% end -%> diff --git a/railties/lib/rails/generators/rails/helper/helper_generator.rb b/railties/lib/rails/generators/rails/helper/helper_generator.rb index 50d3b46b56..ad66388591 100644 --- a/railties/lib/rails/generators/rails/helper/helper_generator.rb +++ b/railties/lib/rails/generators/rails/helper/helper_generator.rb @@ -4,7 +4,7 @@ module Rails check_class_collision :suffix => "Helper" def create_helper_files - namespaced_template 'helper.rb', File.join('app/helpers', class_path, "#{file_name}_helper.rb") + template 'helper.rb', File.join('app/helpers', class_path, "#{file_name}_helper.rb") end hook_for :test_framework diff --git a/railties/lib/rails/generators/rails/helper/templates/helper.rb b/railties/lib/rails/generators/rails/helper/templates/helper.rb index 3fe2ecdc74..b4173151b4 100644 --- a/railties/lib/rails/generators/rails/helper/templates/helper.rb +++ b/railties/lib/rails/generators/rails/helper/templates/helper.rb @@ -1,2 +1,4 @@ +<% module_namespacing do -%> module <%= class_name %>Helper end +<% end -%> |