Sha256: b1f61a6ad21752424ae08169d4e23ab683514736d74463638dc7eaf8588a1210

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Merb::Generators
  
  class HelperGenerator < ComponentGenerator

    def self.source_root
      File.join(super, 'helper')
    end
    
    desc <<-DESC
      Generates a new helper.
    DESC
    
    option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
    
    first_argument :name, :required => true, :desc => "helper name"
    
    template :helper do
      source('app/helpers/%file_name%_helper.rb')
      destination("app/helpers/#{file_name}_helper.rb")
    end
    
    template :helper_spec, :testing_framework => :rspec do
      source('spec/helpers/%file_name%_helper_spec.rb')
      destination("spec/helpers/#{file_name}_helper_spec.rb")
    end
    
    def helper_modules
      chunks[0..-2]
    end
    
    def helper_class_name
      chunks.last
    end
    
    def full_class_name
      chunks.join('::')
    end
    
    def file_name
      helper_class_name.snake_case
    end
    
    protected
    
    def chunks
      name.gsub('/', '::').split('::').map { |c| c.camel_case }
    end
    
  end
  
  add :helper, HelperGenerator
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thorero-gen-0.9.4 lib/merb-gen/helper.rb