Module: Yamler

Defined in:
lib/yamler/yamler.rb,
lib/yamler/template.rb

Defined Under Namespace

Classes: Template

Class Method Summary collapse

Class Method Details

.load(path, options = {}, &block) ⇒ Object

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


25
26
27
28
29
30
31
# File 'lib/yamler/yamler.rb', line 25

def load(path, options = {}, &block)
  template = Yamler::Template.new(path, options) 
  if block_given?
    template.instance_eval(&block)
  end
  YAML.load(template.render)
end