Sha256: def6f35bf0bd07316d9208a66b1a03f0bd6ac497262fd3f00ee4d0b21faa7118

Contents?: true

Size: 1.16 KB

Versions: 28

Compression:

Stored size: 1.16 KB

Contents

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

      class_option :parent, type: :string, desc: 'The parent class for the generated cell'
      class_option :e, type: :string, desc: 'The template engine'

      check_class_collision suffix: 'Cell'

      argument :actions, type: :array, default: [], banner: 'action action2'

      def create_cell_file
        template 'cell.rb.erb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
      end

      def create_view_files
        states.each do |state|
          @state = state
          @path = File.join('app/cells', class_path, file_name,  "#{state}.#{template_engine}")
          template "view.#{template_engine}", @path
        end
      end

      hook_for :test_framework

      private

      def parent_class_name
        options[:parent] || 'Cell::ViewModel'
      end

      # The show state is included by default
      def states
        (['show'] + actions).uniq
      end

      def template_engine
        (options[:e] || Rails.application.config.app_generators.rails[:template_engine] || 'erb').to_s
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
cells-rails-0.1.6 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.1.5 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.1.4 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.1.3 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.1.2 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.1.1 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.1.0 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.9 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.8 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.7 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.6 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.5 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.4 lib/rails/generators/cell/cell_generator.rb
cells-rails-0.0.3 lib/rails/generators/cell/cell_generator.rb
cells-4.0.5 lib/rails/generators/cell/cell_generator.rb
cells-4.0.4 lib/rails/generators/cell/cell_generator.rb
cells-4.0.3 lib/rails/generators/cell/cell_generator.rb
cells-4.0.2 lib/rails/generators/cell/cell_generator.rb
cells-4.0.1 lib/rails/generators/cell/cell_generator.rb
cells-4.0.0 lib/rails/generators/cell/cell_generator.rb