Class: Nake::ErbTemplate
Instance Method Summary (collapse)
-
- (ErbTemplate) initialize(path)
constructor
A new instance of ErbTemplate.
- - (Object) render(context = Hash.new)
- - (Object) set_locals(context)
- - (Object) source(context)
Constructor Details
- (ErbTemplate) initialize(path)
A new instance of ErbTemplate
31 32 33 34 |
# File 'lib/nake/template.rb', line 31 def initialize(path) require "erb" @path = path end |
Instance Method Details
- (Object) render(context = Hash.new)
46 47 48 49 |
# File 'lib/nake/template.rb', line 46 def render(context = Hash.new) template = ERB.new(self.source(context)) template.result(binding) end |
- (Object) set_locals(context)
36 37 38 39 40 |
# File 'lib/nake/template.rb', line 36 def set_locals(context) context.inject("") do |source, pair| source += "#{pair.first} = context[:#{pair.first}]\n" end end |
- (Object) source(context)
42 43 44 |
# File 'lib/nake/template.rb', line 42 def source(context) ["<% #{self.set_locals(context)} %>", File.read(@path)].join("") end |