Class: Nesta::Commands::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/nesta/commands/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Template

Returns a new instance of Template.



4
5
6
# File 'lib/nesta/commands/template.rb', line 4

def initialize(filename)
  @filename = filename
end

Instance Method Details

#copy_to(dest, context) ⇒ Object



13
14
15
16
17
# File 'lib/nesta/commands/template.rb', line 13

def copy_to(dest, context)
  FileUtils.mkdir_p(File.dirname(dest))
  template = ERB.new(File.read(template_path), trim_mode: "-")
  File.open(dest, 'w') { |file| file.puts template.result(context) }
end

#template_pathObject



8
9
10
11
# File 'lib/nesta/commands/template.rb', line 8

def template_path
  dir = File.expand_path('../../../templates', File.dirname(__FILE__))
  File.join(dir, @filename)
end