Module: Brine::MustacheExpanding

Included in:
Brine
Defined in:
lib/brine/mustache_expanding.rb

Overview

Provides a binding environment and template expansion that uses that environment.

Instance Method Summary collapse

Instance Method Details

#bind(key, value) ⇒ Object

Assign ‘value’ to ‘key’ within binding,

Parameters:

  • key (String)

    The key in the binding to which ‘value` will be assigned.

  • value (Object)

    The value to assign to “key` within the binding.



29
30
31
32
# File 'lib/brine/mustache_expanding.rb', line 29

def bind(key, value)
  STDERR.puts "Assigning #{value} to #{key}" if ENV['BRINE_LOG_BINDING']
  binding[key] = value
end

#bindingHash<String, Object>

Mutable hash which serves as binding environment.

Returns:

  • (Hash<String, Object>)

    The active binding environment.



19
20
21
# File 'lib/brine/mustache_expanding.rb', line 19

def binding
  @binding ||= {}
end

#shave_value(template) ⇒ String

Expanded Mustache template using binding environment. Mustache in…no Mustache out.

Parameters:

  • template (String)

    Template content to expand with binding.

Returns:

  • (String)

    The contents of ‘template` with any expansions done using `binding`.



41
42
43
# File 'lib/brine/mustache_expanding.rb', line 41

def shave_value(template)
  Mustache.render(template, binding)
end