Module: WalrusLang
- Defined in:
- lib/opswalrus/walrus_lang.rb
Defined Under Namespace
Modules: Mustache, Template, Templates
Constant Summary collapse
- Grammar =
<<-GRAMMAR grammar WalrusLang::Parser rule templates (template*) <WalrusLang::Templates> end rule template ((pre:(non_mustache?) mustache post:(non_mustache?)) | fallthrough:non_mustache) <WalrusLang::Template> end rule before_mustache ~'{{' end rule non_mustache ~('{{' | '}}') end rule mustache ('{{' expr:templates '}}') <WalrusLang::Mustache> end end GRAMMAR
Class Method Summary collapse
- .eval(template_string, bindings_from_stack_frame_offset = 1) ⇒ Object
-
.render(template, binding_obj) ⇒ Object
binding_obj : Binding | Hash.
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 |