Class: Twig::TemplateWrapper

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

Instance Method Summary collapse

Constructor Details

#initialize(environment, template) ⇒ TemplateWrapper

Returns a new instance of TemplateWrapper.



5
6
7
8
# File 'lib/twig/template_wrapper.rb', line 5

def initialize(environment, template)
  @environment = environment
  @template = template
end

Instance Method Details

#block?(name, context = {}) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/twig/template_wrapper.rb', line 23

def block?(name, context = {})
  context = Runtime::Context.from(context)

  template.block?(name, context)
end

#render(context = {}, call_context: nil, output_buffer: nil) ⇒ Object



10
11
12
13
14
# File 'lib/twig/template_wrapper.rb', line 10

def render(context = {}, call_context: nil, output_buffer: nil)
  context = Runtime::Context.from(context, call_context:, output_buffer:)

  template.render(context).to_s
end

#render_block(name, context = {}, call_context: nil, output_buffer: nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/twig/template_wrapper.rb', line 16

def render_block(name, context = {}, call_context: nil, output_buffer: nil)
  context = Runtime::Context.from(context, call_context:, output_buffer:)
  context.merge!(environment.globals)

  template.render_block(name, context).to_s
end

#unwrapTemplate

Returns:



30
31
32
# File 'lib/twig/template_wrapper.rb', line 30

def unwrap
  template
end