Sha256: 016a7c8471271bd05cc8dcc46043bb6b68129a32b2e861a4cc7c3ae2452951dd

Contents?: true

Size: 985 Bytes

Versions: 49

Compression:

Stored size: 985 Bytes

Contents

module Para
  module Page
    class SectionGenerator < Rails::Generators::NamedBase
      include Para::Generators::NameHelpers

      source_root File.expand_path("../templates", __FILE__)

      argument :attributes, type: :array, required: false, default: []

      def generate_model
        template(
          "section.rb.erb",
          "app/models/page_section/#{ singular_namespaced_path }.rb"
        )
      end

      def generate_fields
        generate 'para:nested_fields', "page_section/#{ singular_namespaced_path }"
      end

      def generate_template
        template(
          "section.html.haml.erb",
          "app/views/page_section/#{ plural_namespaced_path }/_#{ singular_namespaced_path }.html.haml"
        )
      end

      private

      def attributes_separated_with_commas
        if attributes.empty?
          ':title'
        else
          attributes.map { |attribute| ":#{ attribute.name }" }.join(', ')
        end
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
para-0.12.4 lib/generators/para/page/section/section_generator.rb
para-0.12.3 lib/generators/para/page/section/section_generator.rb
para-0.12.2 lib/generators/para/page/section/section_generator.rb
para-0.12.1 lib/generators/para/page/section/section_generator.rb
para-0.12.0 lib/generators/para/page/section/section_generator.rb
para-0.11.4 lib/generators/para/page/section/section_generator.rb
para-0.11.3 lib/generators/para/page/section/section_generator.rb
para-0.11.2 lib/generators/para/page/section/section_generator.rb
para-0.11.1 lib/generators/para/page/section/section_generator.rb
para-0.11.0 lib/generators/para/page/section/section_generator.rb
para-0.10.0 lib/generators/para/page/section/section_generator.rb
para-0.9.4 lib/generators/para/page/section/section_generator.rb
para-0.9.3.3 lib/generators/para/page/section/section_generator.rb
para-0.9.3.2 lib/generators/para/page/section/section_generator.rb
para-0.9.3.1 lib/generators/para/page/section/section_generator.rb
para-0.9.2 lib/generators/para/page/section/section_generator.rb
para-0.9.0 lib/generators/para/page/section/section_generator.rb
para-0.8.15 lib/generators/para/page/section/section_generator.rb
para-0.8.14 lib/generators/para/page/section/section_generator.rb
para-0.8.13 lib/generators/para/page/section/section_generator.rb