Class: Twig::Template

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

Overview

Base class for compiled templates

Constant Summary collapse

ARRAY_CALL =
:array_call
METHOD_CALL =
:method_call
ANY_CALL =
:any_call

Instance Method Summary collapse

Constructor Details

#initialize(environment, call_context: nil, output_buffer: nil) ⇒ Template

Returns a new instance of Template.

Parameters:



11
12
13
14
15
16
17
# File 'lib/twig/template.rb', line 11

def initialize(environment, call_context: nil, output_buffer: nil)
  @environment = environment
  @parents = {}
  @blocks = {}
  @call_context = call_context
  @output_buffer = output_buffer || OutputBuffer.new
end

Instance Method Details

#call(context = {}, blocks = {}) ⇒ Object



19
20
21
# File 'lib/twig/template.rb', line 19

def call(context = {}, blocks = {})
  raise 'call is not implemented'
end

#render(context = {}, blocks = {}) ⇒ Object



23
24
25
# File 'lib/twig/template.rb', line 23

def render(context = {}, blocks = {})
  call(Context.new(context), blocks)
end

#yield_block(name, context = {}, blocks = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/twig/template.rb', line 27

def yield_block(name, context = {}, blocks = {})
  object = self

  if blocks.key?(name)
    object = blocks[name]
  end

  object.public_send(:"block_#{name}", context, blocks)
end