Class: Subtrac::Template

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

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Template

Returns a new instance of Template.



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

def initialize(template)
  @template = template
end

Instance Method Details

#renderObject



7
8
9
10
11
# File 'lib/subtrac/template.rb', line 7

def render
  puts "Rendering template: #{File.basename(@template)}"
  b = Config.get_binding
  ERB.new(IO.read(@template)).result(b)
end

#write(outfile) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/subtrac/template.rb', line 12

def write(outfile)
  file = File.open(outfile, 'w+')
  if file
    file_output = render()
    file.syswrite(file_output)
    puts("Template written: #{File.basename(outfile)}")
  else
    raise "Unable to open file for writing. file #{outfile}"
  end
end