Class: Nesta::Commands::Template
- Inherits:
-
Object
- Object
- Nesta::Commands::Template
- Defined in:
- lib/nesta/commands/template.rb
Instance Method Summary collapse
- #copy_to(dest, context) ⇒ Object
-
#initialize(filename) ⇒ Template
constructor
A new instance of Template.
- #template_path ⇒ Object
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_path ⇒ Object
8 9 10 11 |
# File 'lib/nesta/commands/template.rb', line 8 def template_path dir = File.('../../../templates', File.dirname(__FILE__)) File.join(dir, @filename) end |