Sha256: ebbd3ec303ece6b25324ab6c0d04a8e58d6e5231927894221ac3e97edb4fb1d0

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module ActionWidget
  module Extensions
    module Rails
      module Generators
        
        class Base < ::Rails::Generators::Base
          
          def self.namespace(name=nil)
            super.sub(/extensions:rails:/, '')
          end
          
        end
        
        class Create < Base
          source_root File.expand_path('../../../../../support/templates', __FILE__)
          argument :widget_name, :type => :string
          class_option :rspec, :type => :boolean, :default => true, :description => "Generates rspec file"

          def generate_widget_implementation_file
            empty_directory 'app/widgets'
            template('widget.rb.erb', "app/widgets/#{widget_implementation_filename}")
          end

          def generate_widget_spec_file
            if defined?(::RSpec) && options.rspec?
              empty_directory 'spec/widgets'
              template('widget_spec.rb.erb', "spec/widgets/#{widget_spec_filename}")
            end
          end

          private

            def widget_spec_filename
              "#{widget_helper_name}_spec.rb"
            end

            def widget_implementation_filename
              "#{widget_helper_name}.rb"
            end

            def widget_class_name
              /[Ww]idget$/.match(widget_name) ? widget_name.classify : "#{widget_name.classify}Widget"
            end

            def widget_helper_name
              widget_class_name.underscore
            end

        end
      
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_widget-0.3.0 lib/action_widget/extensions/rails/generators.rb