markbates-yamler 0.0.2 → 0.0.3
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/lib/yamler/template.rb +19 -1
- data/lib/yamler/yamler.rb +2 -2
- metadata +2 -2
data/lib/yamler/template.rb
CHANGED
|
@@ -3,10 +3,12 @@ module Yamler
|
|
|
3
3
|
class Template
|
|
4
4
|
|
|
5
5
|
attr_accessor :path # :nodoc:
|
|
6
|
+
attr_accessor :options
|
|
6
7
|
|
|
7
8
|
# Takes the path to the YAML file you wish to render.
|
|
8
|
-
def initialize(path)
|
|
9
|
+
def initialize(path, options = {})
|
|
9
10
|
self.path = File.expand_path(path)
|
|
11
|
+
self.options = options
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
# Runs the YAML file through ERB using either the current
|
|
@@ -17,6 +19,22 @@ module Yamler
|
|
|
17
19
|
res
|
|
18
20
|
end
|
|
19
21
|
|
|
22
|
+
def method_missing(sym, *args)
|
|
23
|
+
raise NoMethodError.new(sym.to_s) if self.options[:locals].nil? || self.options[:locals][sym].nil?
|
|
24
|
+
return self.options[:locals][sym]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Requires another YAML file from inside the current YAML file. The contents
|
|
28
|
+
# of the required YAML file will be run through ERB with the binding of the
|
|
29
|
+
# requiring YAML file and it's output will be appended to the calling YAML file.
|
|
30
|
+
# The '.yml' extension is optional. It will be added on if the extension
|
|
31
|
+
# is blank. If the file does not exist, it will look for it in the current
|
|
32
|
+
# directory. If it does not exist there it will raise an error.
|
|
33
|
+
#
|
|
34
|
+
# Examples:
|
|
35
|
+
# <%= require_yaml('foo') %> # => <current_yml_files_directory>/foo.yml
|
|
36
|
+
# <%= require_yaml('foo.yml') %> # => <current_yml_files_directory>/foo.yml
|
|
37
|
+
# <%= require_yaml('/usr/foo.yml') %> # => /usr/foo.yml
|
|
20
38
|
def require_yaml(path)
|
|
21
39
|
path = File.extname(path) == '' ? "#{path}.yml" : path
|
|
22
40
|
unless File.exists?(path)
|
data/lib/yamler/yamler.rb
CHANGED
|
@@ -19,8 +19,8 @@ module Yamler
|
|
|
19
19
|
# 'hi'
|
|
20
20
|
# end
|
|
21
21
|
# end
|
|
22
|
-
def load(path, &block)
|
|
23
|
-
template = Yamler::Template.new(path)
|
|
22
|
+
def load(path, options = {}, &block)
|
|
23
|
+
template = Yamler::Template.new(path, options)
|
|
24
24
|
if block_given?
|
|
25
25
|
template.instance_eval(&block)
|
|
26
26
|
end
|
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.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- markbates
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-01-
|
|
12
|
+
date: 2009-01-21 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|