Class: Asteroid::Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = :erb, text = nil) ⇒ Template

Returns a new instance of Template.



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

def initialize(type = :erb, text = nil)
  @type = type
  @text = text
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/asteroid/template.rb', line 6

def text
  @text
end

Instance Method Details

#render(locals = {}) ⇒ Object



13
14
15
# File 'lib/asteroid/template.rb', line 13

def render(locals = {})
  render_text(@text, locals)
end

#render_text(text = nil, locals = {}) ⇒ Object



17
18
19
20
21
22
23
24
# 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