Class: TurboCrud::Generators::ScaffoldGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
InstallSupport
Defined in:
lib/generators/turbo_crud/scaffold_generator.rb

Constant Summary collapse

VALID_CONTAINERS =
%w[modal drawer both].freeze

Instance Method Summary collapse

Instance Method Details

#create_controllerObject



76
77
78
# File 'lib/generators/turbo_crud/scaffold_generator.rb', line 76

def create_controller
  template "controller.rb.tt", "app/controllers/#{plural_name}_controller.rb"
end

#create_viewsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/generators/turbo_crud/scaffold_generator.rb', line 80

def create_views
  return if options[:wrap_existing]

  @generated_fields = build_fields_markup
  @generated_row_fields = build_row_fields_markup

  template "views/index.html.erb.tt", "app/views/#{plural_name}/index.html.erb"
  template "views/_row.html.erb.tt",  "app/views/#{plural_name}/_row.html.erb"
  template "views/_form.html.erb.tt", "app/views/#{plural_name}/_form.html.erb"

  case normalized_container
  when "modal"
    template "views/new.html.erb.tt",  "app/views/#{plural_name}/new.html.erb"
    template "views/edit.html.erb.tt", "app/views/#{plural_name}/edit.html.erb"
  when "drawer"
    template "views/new.drawer.html.erb.tt",  "app/views/#{plural_name}/new.html.erb"
    template "views/edit.drawer.html.erb.tt", "app/views/#{plural_name}/edit.html.erb"
  when "both"
    template "views/new.html.erb.tt",  "app/views/#{plural_name}/new.html.erb"
    template "views/edit.html.erb.tt", "app/views/#{plural_name}/edit.html.erb"
    template "views/new.drawer.html.erb.tt",  "app/views/#{plural_name}/new.drawer.html.erb"
    template "views/edit.drawer.html.erb.tt", "app/views/#{plural_name}/edit.drawer.html.erb"
  end
end

#generate_model_and_routes_if_fullObject



68
69
70
71
72
73
74
# File 'lib/generators/turbo_crud/scaffold_generator.rb', line 68

def generate_model_and_routes_if_full
  return unless options[:full]

  generate_model unless options[:skip_model]
  inject_routes unless options[:skip_routes]
  run_migrations_if_full
end

#install_if_requestedObject



105
106
107
108
109
110
# File 'lib/generators/turbo_crud/scaffold_generator.rb', line 105

def install_if_requested
  return unless should_install?

  install_layout_frames
  install_sprockets_css
end

#validate_options!Object

Raises:

  • (Thor::Error)


61
62
63
64
65
66
# File 'lib/generators/turbo_crud/scaffold_generator.rb', line 61

def validate_options!
  return if VALID_CONTAINERS.include?(normalized_container)

  raise Thor::Error,
        "Invalid --container=#{options[:container].inspect}. Expected one of: #{VALID_CONTAINERS.join(', ')}."
end