class Ella::Template
Class to handle naming, copying, and processing the various templates that the Ella
generators use.
Constants
- TEMPLATE_DIRECTORY
Public Class Methods
new(filename, generic_template: nil, template_vars: nil)
click to toggle source
If generic_template is nil, this class will look for a specific template based on the filename.
# 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
Public Instance Methods
write()
click to toggle source
# 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
Private Instance Methods
data()
click to toggle source
# File lib/ella/template.rb, line 42 def data @generic_template == :blank ? '' : render_erb(File.open(template_path, 'r').read) end
file_exists?()
click to toggle source
# File lib/ella/template.rb, line 30 def file_exists? File.exist?(@destination) end
render_erb(template)
click to toggle source
# File lib/ella/template.rb, line 34 def render_erb(template) @template_vars ? ERB.new(template, nil, '-').result_with_hash(@template_vars) : template end
template_path()
click to toggle source
# File lib/ella/template.rb, line 38 def template_path File.join(TEMPLATE_DIRECTORY, @generic_template || @filename) end