class RoboPigeon::Extensions::Template

Constants

TEMPLATE_PATH

Attributes

name[RW]
template[RW]

Public Class Methods

render(name, path, template='default') click to toggle source
# File lib/robopigeon/extend/template.rb, line 9
def self.render(name, path, template='default')
  to_render = new
  to_render.name = name
  to_render.template = template
  raise "No template with name #{template}" unless File.directory?("#{TEMPLATE_PATH}/#{template}")

  to_render.render_to(path)
end

Public Instance Methods

extension_name_lower() click to toggle source
# File lib/robopigeon/extend/template.rb, line 37
def extension_name_lower
  name.downcase
end
extension_name_upper() click to toggle source
# File lib/robopigeon/extend/template.rb, line 41
def extension_name_upper
  name.capitalize
end
render_to(path) click to toggle source
# File lib/robopigeon/extend/template.rb, line 18
def render_to(path)
  cwd = FileUtils.pwd
  base = File.expand_path("#{path}/robopigeon_#{name}")
  FileUtils.cd "#{TEMPLATE_PATH}/#{template}"
  FileUtils.mkdir_p base.to_s
  Dir.glob('{**{,/*/**},.*}') do |file|
    new_filename = file.gsub('extension', name).gsub('.erb', '')
    if File.directory?(file)
      FileUtils.mkdir("#{base}/#{new_filename}") unless File.exist? "#{base}/#{new_filename}"
      puts "Created directory #{base}/#{new_filename}"
    else
      content = ERB.new(File.read(file)).result(binding)
      File.write("#{base}/#{new_filename}", content)
      puts "Created #{base}/#{new_filename}"
    end
  end
  FileUtils.cd cwd
end
user_email() click to toggle source
# File lib/robopigeon/extend/template.rb, line 45
def user_email
  `git config user.email`.strip
end
user_name() click to toggle source
# File lib/robopigeon/extend/template.rb, line 49
def user_name
  `git config user.name`.strip
end