Sha256: 998e8493b757deef6be74032991dee6e7fdcf129e9bec0325bd441680a99405a

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

require_relative 'base_generator'
module Fae
  class NestedScaffoldGenerator < Fae::BaseGenerator
    source_root File.expand_path('../templates', __FILE__)
    class_option :parent_model, type: :string, desc: 'Sets the parent model this scaffold belongs_to.'

    def go
      generate_nested_model_file
      inject_display_field_to_model
      generate_nested_controller_file
      generate_view_files
      add_route
    end

    private

      def generate_nested_model_file
        generate "model #{file_name} #{@@attributes_flat}"
        inject_concern
        inject_position_scope
        inject_touch_option_into_model
      end

      def generate_nested_controller_file
        template "controllers/nested_scaffold_controller.rb", "app/controllers/#{options.namespace}/#{file_name.pluralize}_controller.rb"
      end

      def generate_view_files
        @form_attrs = set_form_attrs
        template "views/table_nested.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/table.html.#{options.template}"
        template "views/_form_nested.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/_form.html.#{options.template}"
        template "views/new_nested.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/new.html.#{options.template}"
        template "views/edit_nested.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/edit.html.#{options.template}"
      end

      def inject_touch_option_into_model
        if options.parent_model.present?
          inject_into_file "app/models/#{file_name}.rb", after: "belongs_to :#{options.parent_model.underscore}" do <<-RUBY
, touch: true
RUBY
          end
        end
      end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fae-rails-1.3.0 lib/generators/fae/nested_scaffold_generator.rb
fae-rails-1.2.5 lib/generators/fae/nested_scaffold_generator.rb
fae-rails-1.2.4 lib/generators/fae/nested_scaffold_generator.rb
fae-rails-1.2.3 lib/generators/fae/nested_scaffold_generator.rb
fae-rails-1.2.2 lib/generators/fae/nested_scaffold_generator.rb