Class: Railsstrap::Generators::ScaffoldGenerator
- Inherits:
-
Base
- Object
- Rails::Generators::NamedBase
- Base
- Railsstrap::Generators::ScaffoldGenerator
- Includes:
- Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/railsstrap/scaffold/scaffold_generator.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
Instance Method Summary collapse
- #copy_views ⇒ Object
- #excluded_columns ⇒ Object
- #excluded_columns_pattern ⇒ Object
- #ext ⇒ Object
- #extract_modules ⇒ Object
- #form_builder ⇒ Object
- #generate_erb ⇒ Object
- #generate_views ⇒ Object
-
#initialize(args, *options) ⇒ ScaffoldGenerator
constructor
A new instance of ScaffoldGenerator.
- #initialize_views_variables ⇒ Object
- #rescue_block(exception = Exception) ⇒ Object
- #selected_views ⇒ Object
Constructor Details
#initialize(args, *options) ⇒ ScaffoldGenerator
Returns a new instance of ScaffoldGenerator
28 29 30 31 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 28 def initialize(args, *) super(args, *) initialize_views_variables end |
Instance Attribute Details
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name
41 42 43 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 41 def resource_name @resource_name end |
Instance Method Details
#copy_views ⇒ Object
70 71 72 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 70 def copy_views generate_views end |
#excluded_columns ⇒ Object
50 51 52 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 50 def excluded_columns ['excluded_columns'] || [] end |
#excluded_columns_pattern ⇒ Object
43 44 45 46 47 48 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 43 def excluded_columns_pattern [ /.*_checksum/, /.*_count/, ] end |
#ext ⇒ Object
94 95 96 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 94 def ext ::Rails.application.config.generators.[:rails][:template_extension] || :erb end |
#extract_modules ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 61 def extract_modules modules = controller_name.include?('/') ? controller_name.split('/') : controller_name.split('::') name = modules.pop path = modules.map(&:underscore) file_path = (path + [name.underscore]).join('/') nesting = modules.map(&:camelize).join('::') [name, path, file_path, nesting, modules.size] end |
#form_builder ⇒ Object
98 99 100 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 98 def form_builder defined?(::SimpleForm) ? 'simple_form/' : '' end |
#generate_erb ⇒ Object
88 89 90 91 92 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 88 def generate_erb selected_views.each do |template_name, output_path| template template_name, output_path end end |
#generate_views ⇒ Object
74 75 76 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 74 def generate_views .engine == generate_erb end |
#initialize_views_variables ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 33 def initialize_views_variables @base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules @controller_routing_path = @controller_file_path.gsub(/\//, '_') @resource_name ||= @controller_class_nesting + "::#{@base_name.singularize.camelize}" @resource_name = @resource_name.camelize @model_name = @resource_name.downcase.gsub('::', '') end |
#rescue_block(exception = Exception) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 54 def rescue_block(exception = Exception) yield if block_given? rescue exception => e say e., :red exit end |
#selected_views ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/generators/railsstrap/scaffold/scaffold_generator.rb', line 78 def selected_views { "index.html.#{ext}" => File.join('app/views', @controller_file_path, "index.html.#{ext}"), "new.html.#{ext}" => File.join('app/views', @controller_file_path, "new.html.#{ext}"), "edit.html.#{ext}" => File.join('app/views', @controller_file_path, "edit.html.#{ext}"), "#{form_builder}_form.html.#{ext}" => File.join('app/views', @controller_file_path, "_form.html.#{ext}"), "show.html.#{ext}" => File.join('app/views', @controller_file_path, "show.html.#{ext}") } end |