Module: Vendor::Template

Defined in:
lib/vendor/template.rb

Defined Under Namespace

Classes: Locals

Class Method Summary collapse

Class Method Details

.copy(name, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vendor/template.rb', line 28

def copy(name, options = {})
  # Where should we write this file?
  file_name = options[:name] || name
  target = File.join(File.expand_path(Dir.pwd), file_name)

  # The template to load
  template = File.join(Vendor.root, "vendor", "templates", name)

  if File.exist?(target)
    Vendor.ui.error "#{name} already exists at #{target}"
  else
    Vendor.ui.info "Writing new #{name} to #{target}"

    contents = parse(File.read(template), options[:locals] || {})

    File.open(target, 'w') { |f| f.write(contents) }
  end
end

.parse(contents, locals) ⇒ Object



47
48
49
# File 'lib/vendor/template.rb', line 47

def parse(contents, locals)
  ERB.new(contents).result(Locals.new(locals).get_binding)
end