Class: Brine::MustacheExpanding::BrineTemplate

Inherits:
Mustache
  • Object
show all
Defined in:
lib/brine/mustache_expanding.rb

Overview

Provide an expandable Mustache template using binding environment.

This exists to support latent expansion and template retrieval.

Instance Method Summary collapse

Constructor Details

#initialize(tmpl) ⇒ BrineTemplate

Instantiate a BrineTemplate.

Parameters:

  • tmpl (String)

    Define the string content of the template.



45
46
47
# File 'lib/brine/mustache_expanding.rb', line 45

def initialize(tmpl)
  @template = tmpl
end

Instance Method Details

#expand(binding) ⇒ String

Expand the template using the provided bindings.

Parameters:

  • binding (Hash)

    Provide bound values to use within the template.

Returns:

  • (String)

    Return the contents of this template applied against ‘binding`.



55
56
57
58
59
60
61
62
# File 'lib/brine/mustache_expanding.rb', line 55

def expand(binding)
  begin
    context.push(binding)
    render
  ensure
    context.pop
  end
end

#to_sObject

Stringify as template contents.

This supports cases such as dynamic steps where a string is expected but the template should not yet be expanded.



70
71
72
# File 'lib/brine/mustache_expanding.rb', line 70

def to_s
  @template
end