Class: Inprovise::Template
- Inherits:
-
Object
- Object
- Inprovise::Template
- Defined in:
- lib/inprovise/template.rb
Instance Method Summary collapse
-
#initialize(path, context = nil) ⇒ Template
constructor
A new instance of Template.
- #render(locals = {}) ⇒ Object
- #render_to_tempfile(locals = {}) ⇒ Object
Constructor Details
#initialize(path, context = nil) ⇒ Template
Returns a new instance of Template.
11 12 13 14 15 |
# File 'lib/inprovise/template.rb', line 11 def initialize(path, context = nil) @context = context || Object.new @path = resolve(path) @template = @path.respond_to?(:call) ? Tilt['erb'].new(&@path) : Tilt.new(@path) end |
Instance Method Details
#render(locals = {}) ⇒ Object
17 18 19 |
# File 'lib/inprovise/template.rb', line 17 def render(locals={}) @template.render(@context, locals) end |
#render_to_tempfile(locals = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/inprovise/template.rb', line 21 def render_to_tempfile(locals={}) basename = @path.respond_to?(:call) ? 'inprovise-inline-tpl' : File.basename(@path).gsub('.', '-') file = Tempfile.new(basename) file.write render(locals) file.close file.path end |