markbates-yamler 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -9,6 +9,16 @@ several YAML files into one file, because other wise it would be too big
9
9
  and unwieldy to manage. Enter Yamler:
10
10
 
11
11
  === Examples:
12
- # This will read the file in, parse it through ERB, and then run it
13
- # through YAML#load
12
+ # Renders said file through ERB, and then through YAML.load:
14
13
  Yamler.load('/path/to/file.yml')
14
+
15
+ # Does the same as above but makes a method called say_hi
16
+ # available to the binding of the Yamler::Template instance.
17
+ Yamler.load('/path/to/file.yml') do
18
+ def say_hi
19
+ 'hi'
20
+ end
21
+ end
22
+
23
+ # Renders said file through ERB, and then through YAML.load:
24
+ Yamler.load('/path/to/file.yml', {:locals => {:username => 'markbates'}, :foo => :bar})
@@ -2,10 +2,24 @@ module Yamler
2
2
 
3
3
  class Template
4
4
 
5
- attr_accessor :path # :nodoc:
5
+ # The path of the YAML file to be rendered
6
+ attr_accessor :path
7
+ # Options that are available to the YAML file.
6
8
  attr_accessor :options
7
9
 
8
10
  # Takes the path to the YAML file you wish to render.
11
+ # An optional <tt>Hash</tt> of options can be passed in.
12
+ # These options are available via the <tt>options</tt> accessor.
13
+ # If there is a <tt>Hash</tt> in the <tt>options</tt> called
14
+ # <tt>:locals</tt> then the keys of that <tt>Hash are available</tt>
15
+ # as local methods.
16
+ #
17
+ # Examples:
18
+ # Yamler::Template.new('/path/to/file.yml', {:locals => {:username => 'markbates'}, :foo => :bar})
19
+ #
20
+ # # in file.yml:
21
+ # username: <%= username %> # => 'markbates'
22
+ # foo: <%= options[:foo] %> # => :bar
9
23
  def initialize(path, options = {})
10
24
  self.path = File.expand_path(path)
11
25
  self.options = options
@@ -19,7 +33,7 @@ module Yamler
19
33
  res
20
34
  end
21
35
 
22
- def method_missing(sym, *args)
36
+ def method_missing(sym, *args) # :nodoc:
23
37
  raise NoMethodError.new(sym.to_s) if self.options[:locals].nil? || self.options[:locals][sym].nil?
24
38
  return self.options[:locals][sym]
25
39
  end
@@ -43,6 +57,7 @@ module Yamler
43
57
  Yamler::Template.new(path).render(binding)
44
58
  end
45
59
 
60
+ # Returns the path of the current YAML file.
46
61
  def __FILE__
47
62
  self.path
48
63
  end
@@ -5,6 +5,9 @@ module Yamler
5
5
  # Mimics <tt>YAML#load</tt>, except that it creates a new <tt>Yamler::Template</tt>
6
6
  # class and calls the <tt>render</tt> method on <tt>Yamler::Template</tt>.
7
7
  #
8
+ # An optional <tt>Hash</tt> of options can be passed in. See <tt>Yamler::Template</tt>
9
+ # for more information.
10
+ #
8
11
  # If a block is passed in the contents of that block will be made available to
9
12
  # ERB when the rendering occurs.
10
13
  #
@@ -12,8 +15,8 @@ module Yamler
12
15
  # # Renders said file through ERB, and then through YAML.load:
13
16
  # Yamler.load('/path/to/file.yml')
14
17
  #
15
- # Does the same as above but makes a method called say_hi
16
- # available to the binding of the Yamler::Template instance.
18
+ # # Does the same as above but makes a method called say_hi
19
+ # # available to the binding of the Yamler::Template instance.
17
20
  # Yamler.load('/path/to/file.yml') do
18
21
  # def say_hi
19
22
  # 'hi'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markbates-yamler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates