Module: Babl::Operators::Partial::DSL

Included in:
Template
Defined in:
lib/babl/operators/partial.rb

Instance Method Summary collapse

Instance Method Details

#lookup_contextObject



24
25
26
# File 'lib/babl/operators/partial.rb', line 24

def lookup_context
    builder.instance_variable_get(:@lookup_context)
end

#partial(partial_name) ⇒ Object

Load a partial template given its name A ‘lookup_context’ must be defined



9
10
11
12
13
14
15
16
17
18
# File 'lib/babl/operators/partial.rb', line 9

def partial(partial_name)
    raise Errors::InvalidTemplate, "Cannot use partial without lookup context" unless lookup_context

    path, source, partial_lookup_context = lookup_context.find(partial_name)
    raise Errors::InvalidTemplate, "Cannot find partial '#{partial_name}'" unless path

    with_lookup_context(partial_lookup_context)
        .source(source, path, 0)
        .with_lookup_context(lookup_context)
end

#with_lookup_context(lookup_context) ⇒ Object



20
21
22
# File 'lib/babl/operators/partial.rb', line 20

def with_lookup_context(lookup_context)
    self.class.new(builder.dup.tap { |inst| inst.instance_variable_set(:@lookup_context, lookup_context) })
end