Sha256: 6f9103cb52e8f6451c96d0c3774bc05e3358b77a585849e8f50041f4b055f1e2

Contents?: true

Size: 1.66 KB

Versions: 23

Compression:

Stored size: 1.66 KB

Contents

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

      check_class_collision :suffix => 'Enquiry'

      argument :action_name,
               :type => :string,
               :default => 'index',
               :banner => 'action_name'

      argument :filter_attributes,
               :type => :array,
               :default => [],
               :banner => "[attribute[:type[:required]] attribute[:type[:required]]]"

      def initialize(args, *options)
        super
        parse_filter_attributes!
      end

      def create_template_file
        template 'index.html.haml', File.join('app/views', class_path, "#{file_name}_enquiry", "#{action_name}.html.haml")
      end

    protected

      def parse_filter_attributes!
        self.filter_attributes = (filter_attributes || []).map do |attribute|
          # expected in the form "name", "name:type" or "name:type:required"
          parts = attribute.split(':')
          name = parts.first.underscore
          type = ((parts.length > 1) ? parts[1] : 'string')

          additional_options = case type.to_sym
            when :integer, :decimal, :boolean, :date, :time, :datetime
              ", :as => :#{type}"
            when :enum
              ", :collection => #{name.titleize}Enum.collection"
            when :model
              ", :collection => #{name.titleize}.all"
            else
              ''
            end

          OpenStruct.new(
            :name => name,
            :type => type,
            :inject_options => additional_options
          )
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
riveter-0.8.3 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.8.2 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.8.1 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.8.0 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.7.0 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.6.0 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.3.0 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.2.1 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.2.0 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.1.1 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.15 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.14 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.13 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.12 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.11 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.10 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.9 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.8 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.7 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb
riveter-0.0.6 lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb