yamler 0.1.0

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 ADDED
@@ -0,0 +1,24 @@
1
+ Yamler - Making YAML easy and fun to use with Ruby
2
+ =========================================================================
3
+
4
+ Using YAML in Ruby is pretty easy, but I find myself doing several things
5
+ every time I use YAML. First is I always seem to pass it through ERB. The
6
+ other is that I want to pass it a binding, because I want to give it
7
+ access to some variables or methods. Finally I sometimes end up merging
8
+ several YAML files into one file, because other wise it would be too big
9
+ and unwieldy to manage. Enter Yamler:
10
+
11
+ === Examples:
12
+ # Renders said file through ERB, and then through YAML.load:
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})
@@ -0,0 +1,183 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Yamler</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Yamler</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/yamler/template_rb.html">
59
+ lib/yamler/template.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/yamler/yamler_rb.html">
63
+ lib/yamler/yamler.rb
64
+ </a>
65
+ <br />
66
+ </td>
67
+ </tr>
68
+
69
+ </table>
70
+ </div>
71
+ <!-- banner header -->
72
+
73
+ <div id="bodyContent">
74
+
75
+
76
+
77
+ <div id="contextContent">
78
+
79
+
80
+
81
+ </div>
82
+
83
+ <div id="method-list">
84
+ <h3 class="section-bar">Methods</h3>
85
+
86
+ <div class="name-list">
87
+ <a href="#M000001">load</a>&nbsp;&nbsp;
88
+ </div>
89
+ </div>
90
+
91
+ </div>
92
+
93
+
94
+ <!-- if includes -->
95
+
96
+ <div id="section">
97
+
98
+ <div id="class-list">
99
+ <h3 class="section-bar">Classes and Modules</h3>
100
+
101
+ Class <a href="Yamler/Template.html" class="link">Yamler::Template</a><br />
102
+
103
+ </div>
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+ <!-- if method_list -->
112
+ <div id="methods">
113
+ <h3 class="section-bar">Public Class methods</h3>
114
+
115
+ <div id="method-M000001" class="method-detail">
116
+ <a name="M000001"></a>
117
+
118
+ <div class="method-heading">
119
+ <a href="#M000001" class="method-signature">
120
+ <span class="method-name">load</span><span class="method-args">(path, options = {}, &amp;block)</span>
121
+ </a>
122
+ </div>
123
+
124
+ <div class="method-description">
125
+ <p>
126
+ Mimics <tt>YAML#load</tt>, except that it creates a new <tt><a
127
+ href="Yamler/Template.html">Yamler::Template</a></tt> class and calls the
128
+ <tt>render</tt> method on <tt><a
129
+ href="Yamler/Template.html">Yamler::Template</a></tt>.
130
+ </p>
131
+ <p>
132
+ An optional <tt>Hash</tt> of options can be passed in. See <tt><a
133
+ href="Yamler/Template.html">Yamler::Template</a></tt> for more information.
134
+ </p>
135
+ <p>
136
+ If a block is passed in the contents of that block will be made available
137
+ to ERB when the rendering occurs.
138
+ </p>
139
+ <p>
140
+ Examples:
141
+ </p>
142
+ <pre>
143
+ # Renders said file through ERB, and then through YAML.load:
144
+ Yamler.load('/path/to/file.yml')
145
+
146
+ # Does the same as above but makes a method called say_hi
147
+ # available to the binding of the Yamler::Template instance.
148
+ Yamler.load('/path/to/file.yml') do
149
+ def say_hi
150
+ 'hi'
151
+ end
152
+ end
153
+ </pre>
154
+ <p><a class="source-toggle" href="#"
155
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
156
+ <div class="method-source-code" id="M000001-source">
157
+ <pre>
158
+ <span class="ruby-comment cmt"># File lib/yamler/yamler.rb, line 25</span>
159
+ 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
160
+ 26: <span class="ruby-identifier">template</span> = <span class="ruby-constant">Yamler</span><span class="ruby-operator">::</span><span class="ruby-constant">Template</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">options</span>)
161
+ 27: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
162
+ 28: <span class="ruby-identifier">template</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
163
+ 29: <span class="ruby-keyword kw">end</span>
164
+ 30: <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">template</span>.<span class="ruby-identifier">render</span>)
165
+ 31: <span class="ruby-keyword kw">end</span>
166
+ </pre>
167
+ </div>
168
+ </div>
169
+ </div>
170
+
171
+
172
+ </div>
173
+
174
+
175
+ </div>
176
+
177
+
178
+ <div id="validator-badges">
179
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
180
+ </div>
181
+
182
+ </body>
183
+ </html>
@@ -0,0 +1,293 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Yamler::Template</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Yamler::Template</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/yamler/template_rb.html">
59
+ lib/yamler/template.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000005">__FILE__</a>&nbsp;&nbsp;
90
+ <a href="#M000002">new</a>&nbsp;&nbsp;
91
+ <a href="#M000003">render</a>&nbsp;&nbsp;
92
+ <a href="#M000004">require_yaml</a>&nbsp;&nbsp;
93
+ </div>
94
+ </div>
95
+
96
+ </div>
97
+
98
+
99
+ <!-- if includes -->
100
+
101
+ <div id="section">
102
+
103
+
104
+
105
+
106
+
107
+ <div id="attribute-list">
108
+ <h3 class="section-bar">Attributes</h3>
109
+
110
+ <div class="name-list">
111
+ <table>
112
+ <tr class="top-aligned-row context-row">
113
+ <td class="context-item-name">options</td>
114
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
115
+ <td class="context-item-desc">
116
+ Options that are available to the YAML file.
117
+
118
+ </td>
119
+ </tr>
120
+ <tr class="top-aligned-row context-row">
121
+ <td class="context-item-name">path</td>
122
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
123
+ <td class="context-item-desc">
124
+ The path of the YAML file to be rendered
125
+
126
+ </td>
127
+ </tr>
128
+ </table>
129
+ </div>
130
+ </div>
131
+
132
+
133
+
134
+ <!-- if method_list -->
135
+ <div id="methods">
136
+ <h3 class="section-bar">Public Class methods</h3>
137
+
138
+ <div id="method-M000002" class="method-detail">
139
+ <a name="M000002"></a>
140
+
141
+ <div class="method-heading">
142
+ <a href="#M000002" class="method-signature">
143
+ <span class="method-name">new</span><span class="method-args">(path, options = {})</span>
144
+ </a>
145
+ </div>
146
+
147
+ <div class="method-description">
148
+ <p>
149
+ Takes the path to the YAML file you wish to <a
150
+ href="Template.html#M000003">render</a>. An optional <tt>Hash</tt> of
151
+ options can be passed in. These options are available via the
152
+ <tt>options</tt> accessor. If there is a <tt>Hash</tt> in the
153
+ <tt>options</tt> called <tt>:locals</tt> then the keys of that <tt>Hash are
154
+ available</tt> as local methods.
155
+ </p>
156
+ <p>
157
+ Examples:
158
+ </p>
159
+ <pre>
160
+ Yamler::Template.new('/path/to/file.yml', {:locals =&gt; {:username =&gt; 'markbates'}, :foo =&gt; :bar})
161
+
162
+ # in file.yml:
163
+ username: &lt;%= username %&gt; # =&gt; 'markbates'
164
+ foo: &lt;%= options[:foo] %&gt; # =&gt; :bar
165
+ </pre>
166
+ <p><a class="source-toggle" href="#"
167
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
168
+ <div class="method-source-code" id="M000002-source">
169
+ <pre>
170
+ <span class="ruby-comment cmt"># File lib/yamler/template.rb, line 23</span>
171
+ 23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">options</span> = {})
172
+ 24: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>)
173
+ 25: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
174
+ 26: <span class="ruby-keyword kw">end</span>
175
+ </pre>
176
+ </div>
177
+ </div>
178
+ </div>
179
+
180
+ <h3 class="section-bar">Public Instance methods</h3>
181
+
182
+ <div id="method-M000005" class="method-detail">
183
+ <a name="M000005"></a>
184
+
185
+ <div class="method-heading">
186
+ <a href="#M000005" class="method-signature">
187
+ <span class="method-name">__FILE__</span><span class="method-args">()</span>
188
+ </a>
189
+ </div>
190
+
191
+ <div class="method-description">
192
+ <p>
193
+ Returns the path of the current YAML file.
194
+ </p>
195
+ <p><a class="source-toggle" href="#"
196
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
197
+ <div class="method-source-code" id="M000005-source">
198
+ <pre>
199
+ <span class="ruby-comment cmt"># File lib/yamler/template.rb, line 61</span>
200
+ 61: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">__FILE__</span>
201
+ 62: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>
202
+ 63: <span class="ruby-keyword kw">end</span>
203
+ </pre>
204
+ </div>
205
+ </div>
206
+ </div>
207
+
208
+ <div id="method-M000003" class="method-detail">
209
+ <a name="M000003"></a>
210
+
211
+ <div class="method-heading">
212
+ <a href="#M000003" class="method-signature">
213
+ <span class="method-name">render</span><span class="method-args">(b = binding)</span>
214
+ </a>
215
+ </div>
216
+
217
+ <div class="method-description">
218
+ <p>
219
+ Runs the YAML file through ERB using either the current templates
220
+ <tt>binding</tt> or the specified one. This method returns a string and
221
+ <em>NOT</em> a YAML object.
222
+ </p>
223
+ <p><a class="source-toggle" href="#"
224
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
225
+ <div class="method-source-code" id="M000003-source">
226
+ <pre>
227
+ <span class="ruby-comment cmt"># File lib/yamler/template.rb, line 31</span>
228
+ 31: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>(<span class="ruby-identifier">b</span> = <span class="ruby-identifier">binding</span>)
229
+ 32: <span class="ruby-identifier">res</span> = <span class="ruby-constant">ERB</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>)).<span class="ruby-identifier">result</span>(<span class="ruby-identifier">b</span>)
230
+ 33: <span class="ruby-identifier">res</span>
231
+ 34: <span class="ruby-keyword kw">end</span>
232
+ </pre>
233
+ </div>
234
+ </div>
235
+ </div>
236
+
237
+ <div id="method-M000004" class="method-detail">
238
+ <a name="M000004"></a>
239
+
240
+ <div class="method-heading">
241
+ <a href="#M000004" class="method-signature">
242
+ <span class="method-name">require_yaml</span><span class="method-args">(path)</span>
243
+ </a>
244
+ </div>
245
+
246
+ <div class="method-description">
247
+ <p>
248
+ Requires another YAML file from inside the current YAML file. The contents
249
+ of the required YAML file will be run through ERB with the binding of the
250
+ requiring YAML file and it&#8216;s output will be appended to the calling
251
+ YAML file. The &#8217;.yml&#8217; extension is optional. It will be added
252
+ on if the extension is blank. If the file does not exist, it will look for
253
+ it in the current directory. If it does not exist there it will raise an
254
+ error.
255
+ </p>
256
+ <p>
257
+ Examples:
258
+ </p>
259
+ <pre>
260
+ &lt;%= require_yaml('foo') %&gt; # =&gt; &lt;current_yml_files_directory&gt;/foo.yml
261
+ &lt;%= require_yaml('foo.yml') %&gt; # =&gt; &lt;current_yml_files_directory&gt;/foo.yml
262
+ &lt;%= require_yaml('/usr/foo.yml') %&gt; # =&gt; /usr/foo.yml
263
+ </pre>
264
+ <p><a class="source-toggle" href="#"
265
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
266
+ <div class="method-source-code" id="M000004-source">
267
+ <pre>
268
+ <span class="ruby-comment cmt"># File lib/yamler/template.rb, line 52</span>
269
+ 52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">require_yaml</span>(<span class="ruby-identifier">path</span>)
270
+ 53: <span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-identifier">path</span>) <span class="ruby-operator">==</span> <span class="ruby-value str">''</span> <span class="ruby-operator">?</span> <span class="ruby-node">&quot;#{path}.yml&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">path</span>
271
+ 54: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">path</span>)
272
+ 55: <span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>), <span class="ruby-identifier">path</span>))
273
+ 56: <span class="ruby-keyword kw">end</span>
274
+ 57: <span class="ruby-constant">Yamler</span><span class="ruby-operator">::</span><span class="ruby-constant">Template</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>).<span class="ruby-identifier">render</span>(<span class="ruby-identifier">binding</span>)
275
+ 58: <span class="ruby-keyword kw">end</span>
276
+ </pre>
277
+ </div>
278
+ </div>
279
+ </div>
280
+
281
+
282
+ </div>
283
+
284
+
285
+ </div>
286
+
287
+
288
+ <div id="validator-badges">
289
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
290
+ </div>
291
+
292
+ </body>
293
+ </html>