Module: WalrusLang

Defined in:
lib/opswalrus/walrus_lang.rb

Defined Under Namespace

Modules: Mustache, Template, Templates

Constant Summary collapse

Grammar =
"  grammar WalrusLang::Parser\n    rule templates\n      (template*) <WalrusLang::Templates>\n    end\n\n    rule template\n      ((pre:(non_mustache?) mustache post:(non_mustache?)) | fallthrough:non_mustache) <WalrusLang::Template>\n    end\n\n    rule before_mustache\n      ~'{{'\n    end\n\n    rule non_mustache\n      ~('{{' | '}}')\n    end\n\n    rule mustache\n      ('{{' expr:templates '}}') <WalrusLang::Mustache>\n    end\n  end\n"

Class Method Summary collapse

Class Method Details

.eval(template_string, bindings_from_stack_frame_offset = 1) ⇒ Object



66
67
68
69
# File 'lib/opswalrus/walrus_lang.rb', line 66

def self.eval(template_string, bindings_from_stack_frame_offset = 1)
  binding_from_earlier_stack_frame = binding.of_caller(bindings_from_stack_frame_offset)
  template_string =~ /{{.*}}/ ? WalrusLang.render(template_string, binding_from_earlier_stack_frame) : template_string
end

.render(template, binding_obj) ⇒ Object

binding_obj : Binding | Hash



60
61
62
63
64
# File 'lib/opswalrus/walrus_lang.rb', line 60

def self.render(template, binding_obj)
  binding_obj = binding_obj.to_binding if binding_obj.respond_to?(:to_binding)
  ast = WalrusLang::Parser.parse(template)
  ast.render(binding_obj)
end