Class: Twitter_bootstrap_scaffold::Integratedscaffold
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Twitter_bootstrap_scaffold::Integratedscaffold
- Defined in:
- lib/integratedscaffold.rb
Overview
If you use the NamedBase inheritance, a ‘name’ parameter has to follow the ‘rails g integratedscaffold’. Won’t work otherwise. If you don’t want this, use ::Base
Class Method Summary collapse
-
.source_root ⇒ Object
this sets the path where the code looks for templates within the gem.
Instance Method Summary collapse
- #create_controller ⇒ Object
- #create_helper ⇒ Object
- #create_migration ⇒ Object
- #create_model ⇒ Object
- #create_routes ⇒ Object
- #create_views ⇒ Object
-
#initialize(*args, &block) ⇒ Integratedscaffold
constructor
A new instance of Integratedscaffold.
Constructor Details
#initialize(*args, &block) ⇒ Integratedscaffold
Returns a new instance of Integratedscaffold.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/integratedscaffold.rb', line 19 def initialize(*args, &block) # This is a standard initializer super # Call parent class @model_attributes = [] # Initialize empty array for 'thor' attributes # This method splits the name:type arguments in the parameters list g_parameters.each do |arg| @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':')) end # Creates a list of all the standard actions in the controller @controller_actions=all_actions end |
Class Method Details
.source_root ⇒ Object
this sets the path where the code looks for templates within the gem
15 16 17 |
# File 'lib/integratedscaffold.rb', line 15 def self.source_root File.("../templates", __FILE__) end |
Instance Method Details
#create_controller ⇒ Object
44 45 46 47 48 |
# File 'lib/integratedscaffold.rb', line 44 def create_controller # creates the controller using the 'controller.rb' template and puts it into the rails app template 'controller.rb', "app/controllers/#{plural_name}_controller.rb" end |
#create_helper ⇒ Object
57 58 59 60 61 |
# File 'lib/integratedscaffold.rb', line 57 def create_helper # creates the helper using the 'helper.rb' template and puts it into the rails app template 'helper.rb', "app/helpers/#{plural_name}_helper.rb" end |
#create_migration ⇒ Object
50 51 52 53 54 55 |
# File 'lib/integratedscaffold.rb', line 50 def create_migration # creates the migration file using the 'migration.rb' template and puts it into the rails app with a time stamp template 'migration.rb', "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_#{model_path.pluralize.gsub('/', '_')}.rb" end |
#create_model ⇒ Object
37 38 39 40 41 42 |
# File 'lib/integratedscaffold.rb', line 37 def create_model # creates the model using the 'model.rb' template and puts it into the rails app template 'model.rb', "app/models/#{model_path}.rb" end |
#create_routes ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/integratedscaffold.rb', line 63 def create_routes # adds the routes for the gem into the routes file namespaces = plural_name.split('/') resource = namespaces.pop route namespaces.reverse.inject("resources :#{resource}") { |acc, namespace| "namespace(:#{namespace}){ #{acc} }" } end |
#create_views ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/integratedscaffold.rb', line 74 def create_views # creates the standard views using the '[action].html.erb' templates and puts it into the rails app controller_actions.each do |action| if action!="show" and action!="create" and action!="update" and action!="destroy" and action!="parse_save_from_excel" template "views/erb/#{action}.html.erb", "app/views/#{plural_name}/#{action}.html.erb" end end if form_partial? template "views/erb/_form.html.erb", "app/views/#{plural_name}/_form.html.erb" end end |