Class: Mullet::HTML::Template

Inherits:
Object
  • Object
show all
Includes:
Container
Defined in:
lib/mullet/html/template.rb

Overview

Template containing static text and dynamically generated content.

Constant Summary collapse

RETURN_EMPTY_STRING =
Proc.new { '' }

Instance Method Summary collapse

Methods included from Container

#add_child, #children, #clear_children, #delete_child, #render_children

Constructor Details

#initializeTemplate

Returns a new instance of Template.



12
13
14
15
16
# File 'lib/mullet/html/template.rb', line 12

def initialize()
  super
  @on_missing = RETURN_EMPTY_STRING
  @on_nil = RETURN_EMPTY_STRING
end

Instance Method Details

#execute(data, output) ⇒ Object

Renders the template.

Parameters:

  • data (Object)

    provides data to render

  • output (#<<)

    where to write rendered output



38
39
40
41
# File 'lib/mullet/html/template.rb', line 38

def execute(data, output)
  render_context = RenderContext.new(data, @on_missing, @on_nil, output)
  render(render_context)
end

#on_missing(strategy) ⇒ Object



18
19
20
21
# File 'lib/mullet/html/template.rb', line 18

def on_missing(strategy)
  @on_missing = strategy
  return self
end

#on_nil(strategy) ⇒ Object



23
24
25
26
# File 'lib/mullet/html/template.rb', line 23

def on_nil(strategy)
  @on_nil = strategy
  return self
end

#render(render_context) ⇒ Object



28
29
30
# File 'lib/mullet/html/template.rb', line 28

def render(render_context)
  render_children(render_context)
end