Class: Ella::Template

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

Overview

Class to handle naming, copying, and processing the various templates that the Ella generators use.

Constant Summary collapse

TEMPLATE_DIRECTORY =
File.expand_path('../../templates', __dir__)

Instance Method Summary collapse

Constructor Details

#initialize(filename, generic_template: nil, template_vars: nil) ⇒ Template

If generic_template is nil, this class will look for a specific template based on the filename.



12
13
14
15
16
17
# File 'lib/ella/template.rb', line 12

def initialize(filename, generic_template: nil, template_vars: nil)
  @filename = filename
  @destination = File.join(Dir.pwd, @filename)
  @generic_template = generic_template
  @template_vars = template_vars
end

Instance Method Details

#writeObject



19
20
21
22
23
24
25
26
# File 'lib/ella/template.rb', line 19

def write
  Log.create(@filename)
  if file_exists?
    Log.error('File already exists. Skipping.')
  else
    File.open(@destination, 'w') { |f| f.write(data) }
  end
end