Module: Babl::Operators::Partial::DSL
- Included in:
- Template
- Defined in:
- lib/babl/operators/partial.rb
Instance Method Summary collapse
- #lookup_context ⇒ Object
-
#partial(partial_name) ⇒ Object
Load a partial template given its name A ‘lookup_context’ must be defined.
- #with_lookup_context(lookup_context) ⇒ Object
Instance Method Details
#lookup_context ⇒ Object
25 26 27 |
# File 'lib/babl/operators/partial.rb', line 25 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
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/babl/operators/partial.rb', line 10 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
21 22 23 |
# File 'lib/babl/operators/partial.rb', line 21 def with_lookup_context(lookup_context) self.class.new(builder.dup.tap { |inst| inst.instance_variable_set(:@lookup_context, lookup_context) }) end |