Sha256: 0bfa2b6d441845b3f9797c1074e3c9754847577c99a38f30e377de6f8766eab2

Contents?: true

Size: 928 Bytes

Versions: 25

Compression:

Stored size: 928 Bytes

Contents

module Scrivito
  module Generators
    class WidgetGenerator < ::Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)

      argument :name, type: :string
      argument :attributes, type: :array, default: [], banner: 'attribute:type attribute:type'

      def create_model
        template 'model.erb', "app/models/#{file_name}.rb"
      end

      def create_views
        template 'show.html.erb', "app/views/#{file_name}/show.html.erb"
        template 'details.html.erb', "app/views/#{file_name}/details.html.erb"
        template 'thumbnail.html.erb', "app/views/#{file_name}/thumbnail.html.erb"
      end

      def file_name
        super.ends_with?('_widget') ? super : "#{super}_widget"
      end

      def class_name
        super.ends_with?('Widget') ? super : "#{super}Widget"
      end

      def human_name
        class_name.underscore.humanize
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
scrivito_sdk-1.1.1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.1.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.1.0.rc3 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.1.0.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.1.0.rc1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.0.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.0.0.rc4 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.0.0.rc3 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.0.0.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-1.0.0.rc1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.90.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.90.0.rc3 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.90.0.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.90.0.rc1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.70.2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.71.2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.71.1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.70.1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.71.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.71.0.rc2 lib/generators/scrivito/widget/widget_generator.rb