Class: MinimumCrudGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- MinimumCrudGenerator
- Defined in:
- lib/generators/minimum_crud_generator.rb
Instance Method Summary collapse
- #copy_layout_files ⇒ Object
- #generate_controller_files ⇒ Object
- #generate_jbuilder_files ⇒ Object
- #generate_view_files ⇒ Object
Instance Method Details
#copy_layout_files ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/minimum_crud_generator.rb', line 15 def copy_layout_files return unless use_sub_layout? sub_layout = [:sub_layout] || 'application' %w(_form index show new edit).each do |action| copy_file "layouts/#{action}.html.erb", File.join('app/views/layouts/minimum_crud', sub_layout, "#{action}.html.erb") end end |
#generate_controller_files ⇒ Object
11 12 13 |
# File 'lib/generators/minimum_crud_generator.rb', line 11 def generate_controller_files template 'controller.rb.erb', File.join('app/controllers', class_path, "#{file_name}_controller.rb") end |
#generate_jbuilder_files ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/minimum_crud_generator.rb', line 43 def generate_jbuilder_files return unless enable_json? @attributes_argument = @attributes.map{|a| ":#{a}"}.join(', ') %w(index show).each do |action| template "views/#{action}.json.jbuilder.erb", File.join('app/views', class_path, file_name, "#{action}.json.jbuilder") end end |
#generate_view_files ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/minimum_crud_generator.rb', line 26 def generate_view_files @attributes = [:permit_params] || model.attribute_names - ["id", "created_at", "updated_at"] if use_sub_layout? %w(_form _index _show).each do |action| template "views/with_sub_layout/#{action}.html.erb", File.join('app/views', class_path, file_name, "#{action}.html.erb") end else %w(_form index show edit new).each do |action| template "views/without_sub_layout/#{action}.html.erb", File.join('app/views', class_path, file_name, "#{action}.html.erb") end end end |