| Module | Yamler |
| In: |
lib/yamler/template.rb
lib/yamler/yamler.rb |
Mimics YAML#load, except that it creates a new Yamler::Template class and calls the render method on Yamler::Template.
An optional Hash of options can be passed in. See Yamler::Template for more information.
If a block is passed in the contents of that block will be made available to ERB when the rendering occurs.
Examples:
# Renders said file through ERB, and then through YAML.load:
Yamler.load('/path/to/file.yml')
# Does the same as above but makes a method called say_hi
# available to the binding of the Yamler::Template instance.
Yamler.load('/path/to/file.yml') do
def say_hi
'hi'
end
end
# File lib/yamler/yamler.rb, line 25
25: def load(path, options = {}, &block)
26: template = Yamler::Template.new(path, options)
27: if block_given?
28: template.instance_eval(&block)
29: end
30: YAML.load(template.render)
31: end