Class: Comfy::Generators::ScaffoldGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Comfy::Generators::ScaffoldGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/comfy/scaffold/scaffold_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate_controller ⇒ Object
- #generate_model ⇒ Object
- #generate_navigation_link ⇒ Object
- #generate_route ⇒ Object
- #generate_views ⇒ Object
-
#initialize(*args, &block) ⇒ ScaffoldGenerator
constructor
A new instance of ScaffoldGenerator.
Constructor Details
#initialize(*args, &block) ⇒ ScaffoldGenerator
Returns a new instance of ScaffoldGenerator.
20 21 22 23 24 25 26 27 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 20 def initialize(*args, &block) super @model_attrs = [] model_args.each do |arg| next unless arg.include?(":") @model_attrs << Rails::Generators::GeneratedAttribute.new(*arg.split(":")) end end |
Class Method Details
.next_migration_number(dirname) ⇒ Object
29 30 31 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 29 def self.next_migration_number(dirname) ActiveRecord::Generators::Base.next_migration_number(dirname) end |
Instance Method Details
#generate_controller ⇒ Object
40 41 42 43 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 40 def generate_controller template "controller.rb", "app/controllers/admin/#{file_name.pluralize}_controller.rb" template "tests/controller.rb", "test/controllers/admin/#{file_name.pluralize}_controller_test.rb" end |
#generate_model ⇒ Object
33 34 35 36 37 38 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 33 def generate_model migration_template "migration.rb", "db/migrate/create_#{file_name.pluralize}.rb" template "model.rb", "app/models/#{file_name}.rb" template "tests/model.rb", "test/models/#{file_name}_test.rb" template "tests/fixture.yml", "test/fixtures/#{file_name.pluralize}.yml" end |
#generate_navigation_link ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 63 def partial_path = "app/views/comfy/admin/cms/partials/_navigation_inner.html.haml" unless File.exist?(File.join(destination_root, partial_path)) create_file partial_path end append_file partial_path do <<~HAML %li.nav-item = active_link_to '#{class_name.pluralize}', admin_#{file_name.pluralize}_path, class: 'nav-link' HAML end end |
#generate_route ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 53 def generate_route route_string = <<~TEXT namespace :admin do resources :#{file_name.pluralize} end TEXT route route_string end |
#generate_views ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/generators/comfy/scaffold/scaffold_generator.rb', line 45 def generate_views template "views/index.haml", "app/views/admin/#{file_name.pluralize}/index.html.haml" template "views/show.haml", "app/views/admin/#{file_name.pluralize}/show.html.haml" template "views/new.haml", "app/views/admin/#{file_name.pluralize}/new.html.haml" template "views/edit.haml", "app/views/admin/#{file_name.pluralize}/edit.html.haml" template "views/_form.haml", "app/views/admin/#{file_name.pluralize}/_form.html.haml" end |