Sha256: 03c4fd4ad00159ae858b2a5778115bb60bbcf259514550ffb5dcaf6c5585dace

Contents?: true

Size: 973 Bytes

Versions: 27

Compression:

Stored size: 973 Bytes

Contents

class DynamicScaffoldGenerator < Rails::Generators::Base
  source_root File.expand_path('templates', __dir__)

  argument :path, type: 'string', required: true
  argument :model, type: 'string', required: false
  class_option :content_for, type: :string
  class_option :controller_base, type: :string, default: 'ApplicationController'

  def init
    @namespases = path.split('/')
    @plural_model_name = @namespases.pop.camelize
    @class_scope = @namespases.map(&:camelize).join('::')
    @model_name = model || @plural_model_name.singularize
    @model_name = @model_name.camelize
    @model = @model_name.constantize
    @content_for = options['content_for']
    @controller_base = options['controller_base']
  end

  def create_controllers
    template 'controller.erb', "app/controllers/#{path}_controller.rb"
  end

  def create_views
    %i[edit index new].each do |file|
      template "views/#{file}.erb", "app/views/#{path}/#{file}.html.erb"
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
dynamic_scaffold-1.12.2 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.12.1 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.12.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.11.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.10.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.9.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.8.1 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.8.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.7.1 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.7.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.6.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.5.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.4.3 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.4.2 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.4.1 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.4.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.3.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.2.2 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.2.1 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb
dynamic_scaffold-1.2.0 lib/generators/dynamic_scaffold/dynamic_scaffold_generator.rb