Class: ContentGenerator
- Inherits:
-
Rails::Generator::NamedBase
- Object
- Rails::Generator::NamedBase
- ContentGenerator
- Defined in:
- lib/generators/content/content_generator.rb
Instance Attribute Summary collapse
-
#controller_class_name ⇒ Object
readonly
Returns the value of attribute controller_class_name.
-
#controller_class_nesting ⇒ Object
readonly
Returns the value of attribute controller_class_nesting.
-
#controller_class_nesting_depth ⇒ Object
readonly
Returns the value of attribute controller_class_nesting_depth.
-
#controller_class_path ⇒ Object
readonly
Returns the value of attribute controller_class_path.
-
#controller_file_path ⇒ Object
readonly
Returns the value of attribute controller_file_path.
-
#controller_name ⇒ Object
readonly
Returns the value of attribute controller_name.
-
#controller_plural_name ⇒ Object
(also: #controller_table_name)
readonly
Returns the value of attribute controller_plural_name.
-
#controller_singular_name ⇒ Object
(also: #controller_file_name)
readonly
Returns the value of attribute controller_singular_name.
Instance Method Summary collapse
-
#initialize(runtime_args, runtime_options = {}) ⇒ ContentGenerator
constructor
A new instance of ContentGenerator.
- #manifest ⇒ Object
Constructor Details
#initialize(runtime_args, runtime_options = {}) ⇒ ContentGenerator
Returns a new instance of ContentGenerator.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/content/content_generator.rb', line 44 def initialize(runtime_args, = {}) super @controller_name = @name.pluralize base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) if @controller_class_nesting.empty? @controller_class_name = @controller_class_name_without_nesting else @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}" end end |
Instance Attribute Details
#controller_class_name ⇒ Object (readonly)
Returns the value of attribute controller_class_name.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_class_name @controller_class_name end |
#controller_class_nesting ⇒ Object (readonly)
Returns the value of attribute controller_class_nesting.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_class_nesting @controller_class_nesting end |
#controller_class_nesting_depth ⇒ Object (readonly)
Returns the value of attribute controller_class_nesting_depth.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_class_nesting_depth @controller_class_nesting_depth end |
#controller_class_path ⇒ Object (readonly)
Returns the value of attribute controller_class_path.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_class_path @controller_class_path end |
#controller_file_path ⇒ Object (readonly)
Returns the value of attribute controller_file_path.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_file_path @controller_file_path end |
#controller_name ⇒ Object (readonly)
Returns the value of attribute controller_name.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_name @controller_name end |
#controller_plural_name ⇒ Object (readonly) Also known as: controller_table_name
Returns the value of attribute controller_plural_name.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_plural_name @controller_plural_name end |
#controller_singular_name ⇒ Object (readonly) Also known as: controller_file_name
Returns the value of attribute controller_singular_name.
33 34 35 |
# File 'lib/generators/content/content_generator.rb', line 33 def controller_singular_name @controller_singular_name end |
Instance Method Details
#manifest ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/generators/content/content_generator.rb', line 59 def manifest record do |m| #add position to attributes if not there already attributes << Rails::Generator::GeneratedAttribute.new('position', 'integer') unless attributes.map{|att| att.name == 'position'} # Check for class naming collisions. m.class_collisions(class_name, "#{class_name}Test", "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper") #namespace route under :cms :admin m.route_namespaced_resources(controller_file_name) # Controller, helper, views, and test directories. m.directory(File.join('app/models', class_path)) m.directory(File.join('app/controllers/cms/admin', controller_class_path)) m.directory(File.join('test/functional/cms/admin', controller_class_path)) m.directory(File.join('test/unit', class_path)) m.directory(File.join('app/views/cms/admin', controller_class_path, controller_file_name)) m.template('controller.rb', File.join('app/controllers/cms/admin', controller_class_path, "#{controller_file_name}_controller.rb")) m.template('functional_test.rb', File.join('test/functional/cms/admin', controller_class_path, "#{controller_file_name}_controller_test.rb")) m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") #make view code for model form and containers m.template 'form.rb', File.join('app/views/cms/admin', class_path, table_name, '_form.html.haml') m.template 'container.rb', File.join('app/views/cms/content', class_path, "_#{table_name}_container.html.haml") m.template 'item.rb', File.join('app/views/cms/content', class_path, "_#{file_name}.html.haml") m.create_factory #make migration unless [:skip_migration] m.migration_template 'migration.rb', 'db/migrate', :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" end end end |