diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-26 09:53:53 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-26 11:59:13 +0200 |
commit | e0843136405e26a13405567d65fe7e5cc40dfcff (patch) | |
tree | 9453e6afcde311258800734da87892f3fd5f8678 /railties/lib/generators | |
parent | da1baeab4a681b63b29f4a3c7222d660306551d9 (diff) | |
download | rails-e0843136405e26a13405567d65fe7e5cc40dfcff.tar.gz rails-e0843136405e26a13405567d65fe7e5cc40dfcff.tar.bz2 rails-e0843136405e26a13405567d65fe7e5cc40dfcff.zip |
Added HelperGenerator.
Diffstat (limited to 'railties/lib/generators')
6 files changed, 62 insertions, 4 deletions
diff --git a/railties/lib/generators/named_base.rb b/railties/lib/generators/named_base.rb index 223b34ce57..4f173bffce 100644 --- a/railties/lib/generators/named_base.rb +++ b/railties/lib/generators/named_base.rb @@ -13,15 +13,15 @@ module Rails def initialize(*args) super - assign_names! + assign_names!(self.name) parse_attributes! if respond_to?(:attributes) end protected - def assign_names! - base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(name) - @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) + def assign_names!(given_name) + self.name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(given_name) + @class_name_without_nesting, @singular_name, @plural_name = inflect_names(self.name) @table_name = if !defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names plural_name diff --git a/railties/lib/generators/rails/helper/USAGE b/railties/lib/generators/rails/helper/USAGE new file mode 100644 index 0000000000..e74d4b6425 --- /dev/null +++ b/railties/lib/generators/rails/helper/USAGE @@ -0,0 +1,24 @@ +Description: + Stubs out a new helper. Pass the helper name, either + CamelCased or under_scored. + + To create a helper within a module, specify the helper name as a + path like 'parent_module/helper_name'. + + This generates a helper class in app/helpers and invokes your test + framework. + +Example: + `./script/generate helper CreditCard` + + Credit card helper. + Helper: app/helpers/credit_card_helper.rb + Test: test/unit/helpers/credit_card_helper_test.rb + +Modules Example: + `./script/generate helper 'admin/credit_card'` + + Credit card admin helper. + Helper: app/helpers/admin/credit_card_helper.rb + Test: test/unit/helpers/admin/credit_card_helper_test.rb + diff --git a/railties/lib/generators/rails/helper/helper_generator.rb b/railties/lib/generators/rails/helper/helper_generator.rb new file mode 100644 index 0000000000..6f741b0978 --- /dev/null +++ b/railties/lib/generators/rails/helper/helper_generator.rb @@ -0,0 +1,15 @@ +module Rails + module Generators + class HelperGenerator < NamedBase + def check_class_collisions + class_collisions "#{class_name}Helper" + end + + def create_helper_files + template 'helper.rb', File.join('app/helpers', class_path, "#{file_name}_helper.rb") + end + + invoke_for :test_framework + end + end +end diff --git a/railties/lib/generators/rails/helper/templates/helper.rb b/railties/lib/generators/rails/helper/templates/helper.rb new file mode 100644 index 0000000000..3fe2ecdc74 --- /dev/null +++ b/railties/lib/generators/rails/helper/templates/helper.rb @@ -0,0 +1,2 @@ +module <%= class_name %>Helper +end diff --git a/railties/lib/generators/test_unit/helper/helper_generator.rb b/railties/lib/generators/test_unit/helper/helper_generator.rb new file mode 100644 index 0000000000..e7fc4e0dbd --- /dev/null +++ b/railties/lib/generators/test_unit/helper/helper_generator.rb @@ -0,0 +1,13 @@ +module TestUnit + module Generators + class HelperGenerator < Base + def check_class_collisions + class_collisions "#{class_name}Helper" + end + + def create_helper_files + template 'helper_test.rb', File.join('test/unit/helpers', class_path, "#{file_name}_helper_test.rb") + end + end + end +end diff --git a/railties/lib/generators/test_unit/helper/templates/helper_test.rb b/railties/lib/generators/test_unit/helper/templates/helper_test.rb new file mode 100644 index 0000000000..591e40900e --- /dev/null +++ b/railties/lib/generators/test_unit/helper/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end |