Class: Humpyard::Generators::ElementGenerator
- Includes:
- ModelTemplate, Rails::Generators::Migration
- Defined in:
- lib/generators/humpyard/element/element_generator.rb
Overview
Element Generator
rails humpyard:element ElementName [field:type field:type] [options]
Description
The humpyard element generator creates a custom element that can be used inside your humpyard pages.
Options
[--skip-model]-
Don’t generate a model or migration file.
[--skip-migration]-
Dont generate migration file for model.
[--skip-timestamps]-
Don’t add timestamps to migration file.
[--skip-views]-
Don’t generate view files.
Runtime options
-q, [--quiet]-
Supress status output
-p, [--pretend]-
Run but do not make any changes
-s, [--skip]-
Skip files that already exist
-f, [--force]-
Overwrite files that already exist
Test framework options
[--testunit]-
Use test/unit for test files.
[--shoulda]-
Use shoulda for test files.
[--rspec]-
Use RSpec for test files.
[--skip-tests]-
Don’t generate test files.
Examples
rails generate humpyard:element SimpleText text:string
rails generate humpyard:element another_thing content:text --skip-tests
Instance Method Summary collapse
-
#create_element ⇒ Object
:nodoc:.
Methods included from ModelTemplate
Methods inherited from Base
Instance Method Details
#create_element ⇒ Object
:nodoc:
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/humpyard/element/element_generator.rb', line 48 def create_element # :nodoc: template 'model.rb', "app/models/#{singular_name}.rb" unless .skip_tests? case test_framework when :rspec template "tests/rspec/model.rb", "spec/models/#{singular_name}_spec.rb" template 'fixtures.yml', "spec/fixtures/#{plural_name}.yml" else template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb" template 'fixtures.yml', "test/fixtures/#{plural_name}.yml" end end unless .skip_migration? migration_template 'migration.rb', "db/migrate/create_#{plural_name.gsub('/','_')}.rb" end unless .skip_views? template '_inline_edit.html.haml', "app/views/humpyard/elements/#{plural_name}/_inline_edit.html.haml" template '_edit.html.haml', "app/views/humpyard/elements/#{plural_name}/_edit.html.haml" template '_show.html.haml', "app/views/humpyard/elements/#{plural_name}/_show.html.haml" end unless .skip_model? create_model end end |