class Mumukit::Core::Template
Attributes
path[RW]
Public Class Methods
new(path, variables)
click to toggle source
# File lib/template.rb, line 4 def initialize(path, variables) @path = path variables.each do |key, value| instance_variable_set "@#{key}", value self.singleton_class.class_eval { attr_reader key } end end
Public Instance Methods
render()
click to toggle source
# File lib/template.rb, line 12 def render template_file.result binding end
with_tempfile!(prefix) { |file| ... }
click to toggle source
# File lib/template.rb, line 20 def with_tempfile!(prefix) file = Tempfile.new(prefix) write! file yield file ensure file.unlink file.close end
write!(file)
click to toggle source
# File lib/template.rb, line 16 def write!(file) File.write file, render end
Private Instance Methods
template_file()
click to toggle source
# File lib/template.rb, line 31 def template_file ERB.new File.read(path) end