Class: Template

Inherits:
Object show all
Defined in:
opal/stdlib/template.rb

Defined Under Namespace

Classes: OutputBuffer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &body) ⇒ Template

Returns a new instance of Template.



17
18
19
20
# File 'opal/stdlib/template.rb', line 17

def initialize(name, &body)
  @name, @body = name, body
  Template[name] = self
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



15
16
17
# File 'opal/stdlib/template.rb', line 15

def body
  @body
end

Class Method Details

.[](name) ⇒ Object



3
4
5
# File 'opal/stdlib/template.rb', line 3

def self.[](name)
  @_cache[name] || @_cache["templates/#{name}"]
end

.[]=(name, instance) ⇒ Object



7
8
9
# File 'opal/stdlib/template.rb', line 7

def self.[]=(name, instance)
  @_cache[name] = instance
end

.pathsObject



11
12
13
# File 'opal/stdlib/template.rb', line 11

def self.paths
  @_cache.keys
end

Instance Method Details

#inspectObject



22
23
24
# File 'opal/stdlib/template.rb', line 22

def inspect
  "#<Template: '#{@name}'>"
end

#render(ctx = self) ⇒ Object



26
27
28
# File 'opal/stdlib/template.rb', line 26

def render(ctx = self)
  ctx.instance_exec(OutputBuffer.new, &@body)
end