Sha256: 84c97a1093cea7eb7e8b2bbde0c8dbe660ca5882ff1890909a0d3dc3d48d7b31

Contents?: true

Size: 855 Bytes

Versions: 4

Compression:

Stored size: 855 Bytes

Contents

class HelperGenerator < Rails::Generators::NamedBase
  include Rails::Generators::BasicHelper
  
  desc "Adds method 'help_me' to a Helper" 
    
  def self.source_root
    @source_root ||= File.expand_path("../templates", __FILE__)
  end

  def add_helper_method
    info "add_helper_method: #{helper_file_name}" 
    if File.exist?(helper_file_name)
      inject_into_file(helper_file_name, helper_method_code, :after => after_txt) if after_txt
    else
      say "#{helper_file_name} does not exist. Please create it first before you can add a helper method to it!", :red
    end
  end

  protected

  def after_txt
    "#{class_name}Helper"
  end
                     
  def helper_file_name
    File.join(Rails.root, "app/helpers/#{file_name}_helper.rb")
  end

  def helper_method_code
    %Q{
  def help_me
    "Help me please!"
  end
}
  end
end 

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
generator-spec-0.5.0 lib/generators/helper/helper_generator.rb
generator-spec-0.4.8 lib/generators/helper/helper_generator.rb
generator-spec-0.4.7 lib/generators/helper/helper_generator.rb
generator-spec-0.4.5 lib/generators/helper/helper_generator.rb