Sha256: 2395f0307b165631fecba66a0bb8126017813cdd97b147afdeb2efbccecac411

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

module Scrivito
  module Generators
    class WidgetGenerator < ::Rails::Generators::NamedBase
      include ::Rails::Generators::Migration

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

      def self.next_migration_number(dirname)
        Scrivito::Migration.next_migration_number(current_migration_number(dirname))
      end

      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 generate_migration
        migration_template 'migration.erb',
          File.join(Scrivito::Configuration.migration_path, "create_#{file_name}_migration.rb")
      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

16 entries across 16 versions & 1 rubygems

Version Path
scrivito_sdk-0.50.1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.50.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.50.0.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.50.0.rc1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.42.1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.42.1.rc3 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.42.1.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.42.1.rc1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.42.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.41.1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.41.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.41.0.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.41.0.rc1 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.40.0 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.40.0.rc2 lib/generators/scrivito/widget/widget_generator.rb
scrivito_sdk-0.40.0.rc1 lib/generators/scrivito/widget/widget_generator.rb