class Asteroid::Template
Attributes
text[RW]
Public Class Methods
new(type = :erb, text = nil)
click to toggle source
# File lib/asteroid/template.rb, line 8 def initialize(type = :erb, text = nil) @type = type @text = text end
Public Instance Methods
render(locals = {})
click to toggle source
# File lib/asteroid/template.rb, line 13 def render(locals = {}) render_text(@text, locals) end
render_text(text = nil, locals = {})
click to toggle source
# File lib/asteroid/template.rb, line 17 def render_text(text = nil, locals = {}) m = "render_#{@type}" if Asteroid::Config.template_engines[@type] self.send m, text, locals else raise "No template engine for type #{@type}" end end
Private Instance Methods
render_erb(text, locals = {})
click to toggle source
# File lib/asteroid/template.rb, line 28 def render_erb(text, locals = {}) ERB.new(text).result( data = OpenStruct.new(locals).instance_eval{ binding } ) end