mustache 0.99.4 → 1.1.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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +183 -183
  3. data/Rakefile +6 -14
  4. data/bin/mustache +28 -14
  5. data/lib/mustache/context.rb +98 -46
  6. data/lib/mustache/context_miss.rb +55 -0
  7. data/lib/mustache/enumerable.rb +3 -0
  8. data/lib/mustache/generator.rb +63 -42
  9. data/lib/mustache/parser.rb +173 -65
  10. data/lib/mustache/settings.rb +84 -24
  11. data/lib/mustache/template.rb +74 -4
  12. data/lib/mustache/utils.rb +31 -0
  13. data/lib/mustache/version.rb +1 -1
  14. data/lib/mustache.rb +116 -96
  15. data/man/mustache.1 +25 -40
  16. data/man/mustache.1.html +90 -81
  17. data/man/mustache.1.ron +6 -6
  18. data/man/mustache.5 +338 -298
  19. data/man/mustache.5.html +400 -115
  20. data/man/mustache.5.ron +292 -32
  21. data/test/autoloading_test.rb +7 -3
  22. data/test/fixtures/comments.rb +0 -1
  23. data/test/fixtures/complex_view.rb +0 -1
  24. data/test/fixtures/crazy_recursive.rb +0 -1
  25. data/test/fixtures/delimiters.rb +0 -1
  26. data/test/fixtures/dot_notation.rb +0 -1
  27. data/test/fixtures/double_section.rb +0 -1
  28. data/test/fixtures/inverted_section.rb +0 -1
  29. data/test/fixtures/lambda.rb +0 -1
  30. data/test/fixtures/liberal.mustache +1 -0
  31. data/test/fixtures/liberal.rb +25 -0
  32. data/test/fixtures/method_missing.rb +0 -1
  33. data/test/fixtures/namespaced.rb +0 -1
  34. data/test/fixtures/nested_objects.rb +0 -1
  35. data/test/fixtures/override/passenger.conf +6 -0
  36. data/test/fixtures/partial_with_module.rb +0 -1
  37. data/test/fixtures/passenger.rb +0 -1
  38. data/test/fixtures/recursive.rb +0 -1
  39. data/test/fixtures/simple.rb +0 -1
  40. data/test/fixtures/simply_complicated.mustache +25 -0
  41. data/test/fixtures/template_partial.rb +0 -1
  42. data/test/fixtures/unescaped.rb +0 -1
  43. data/test/helper.rb +5 -2
  44. data/test/mustache_test.rb +210 -25
  45. data/test/parser_test.rb +90 -7
  46. data/test/partial_test.rb +16 -4
  47. data/test/path_test.rb +49 -0
  48. data/test/spec_test.rb +5 -5
  49. data/test/template_test.rb +35 -3
  50. metadata +37 -59
  51. data/lib/mustache/sinatra.rb +0 -186
  52. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +0 -27
  53. data/lib/rack/bug/panels/mustache_panel/view.mustache +0 -46
  54. data/lib/rack/bug/panels/mustache_panel.rb +0 -81
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bf066480926aaca95b8ebbb4e45de15a11cae753e407be03a8059bee4deb9837
4
+ data.tar.gz: a334278f764909eb095bed8bf31132af6c61d6dffadbf5688cd745e85517a7a6
5
+ SHA512:
6
+ metadata.gz: 571c5ff585457d1073fa4de0d506073b55a7c3409967d39a488b71fe38b03e7074312ad5e9e379d0f654043dc8be7ffdba4e1cb3b6df4ba6e884920885064ecd
7
+ data.tar.gz: cb3b39d80301b99e13e4cf412e5da3065ecf5215d7b7bece535c032e6cec5c452a0d44f43363d4d35a06a2267e67945325c177ae8631f8b19bac8f344fad2768
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- Mustache
2
- =========
1
+ # Mustache
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/mustache.svg)](http://badge.fury.io/rb/mustache)
4
+ [![Test](https://github.com/mustache/mustache/actions/workflows/test.yml/badge.svg)](https://github.com/mustache/mustache/actions/workflows/test.yml)
3
5
 
4
6
  Inspired by [ctemplate][1] and [et][2], Mustache is a
5
7
  framework-agnostic way to render logic-free views.
@@ -8,11 +10,10 @@ As ctemplates says, "It emphasizes separating logic from presentation:
8
10
  it is impossible to embed application logic in this template language."
9
11
 
10
12
  For a list of implementations (other than Ruby) and tips, see
11
- <http://mustache.github.com/>.
13
+ <http://mustache.github.io/>.
12
14
 
13
15
 
14
- Overview
15
- --------
16
+ ## Overview
16
17
 
17
18
  Think of Mustache as a replacement for your views. Instead of views
18
19
  consisting of ERB or HAML with random helpers and arbitrary logic,
@@ -30,8 +31,7 @@ This strict separation makes it easier to write clean templates,
30
31
  easier to test your views, and more fun to work on your app's front end.
31
32
 
32
33
 
33
- Why?
34
- ----
34
+ ## Why?
35
35
 
36
36
  I like writing Ruby. I like writing HTML. I like writing JavaScript.
37
37
 
@@ -39,35 +39,49 @@ I don't like writing ERB, Haml, Liquid, Django Templates, putting Ruby
39
39
  in my HTML, or putting JavaScript in my HTML.
40
40
 
41
41
 
42
- Usage
43
- -----
42
+ ## Installation
43
+
44
+ Install the gem locally with:
45
+
46
+ $ gem install mustache
47
+
48
+ Or add it to your `Gemfile`:
49
+
50
+ ```ruby
51
+ gem "mustache", "~> 1.0"
52
+ ```
53
+
54
+
55
+ ## Usage
44
56
 
45
57
  Quick example:
46
58
 
47
59
  >> require 'mustache'
48
60
  => true
49
- >> Mustache.render("Hello {{planet}}", :planet => "World!")
61
+ >> Mustache.render("Hello {{planet}}", planet: "World!")
50
62
  => "Hello World!"
51
63
 
52
64
  We've got an `examples` folder but here's the canonical one:
53
65
 
54
- class Simple < Mustache
55
- def name
56
- "Chris"
57
- end
66
+ ```ruby
67
+ class Simple < Mustache
68
+ def name
69
+ "Chris"
70
+ end
58
71
 
59
- def value
60
- 10_000
61
- end
72
+ def value
73
+ 10_000
74
+ end
62
75
 
63
- def taxed_value
64
- value * 0.6
65
- end
76
+ def taxed_value
77
+ value * 0.6
78
+ end
66
79
 
67
- def in_ca
68
- true
69
- end
70
- end
80
+ def in_ca
81
+ true
82
+ end
83
+ end
84
+ ```
71
85
 
72
86
  We simply create a normal Ruby class and define methods. Some methods
73
87
  reference others, some return values, some return only booleans.
@@ -82,9 +96,9 @@ Now let's write the template:
82
96
 
83
97
  This template references our view methods. To bring it all together,
84
98
  here's the code to render actual HTML;
85
-
86
- Simple.render
87
-
99
+ ```ruby
100
+ Simple.render
101
+ ```
88
102
  Which returns the following:
89
103
 
90
104
  Hello Chris
@@ -94,29 +108,26 @@ Which returns the following:
94
108
  Simple.
95
109
 
96
110
 
97
- Tag Types
98
- ---------
111
+ ## Tag Types
99
112
 
100
113
  For a language-agnostic overview of Mustache's template syntax, see
101
114
  the `mustache(5)` manpage or
102
- <http://mustache.github.com/mustache.5.html>.
115
+ <http://mustache.github.io/mustache.5.html>.
103
116
 
104
117
 
105
- Escaping
106
- --------
118
+ ## Escaping
107
119
 
108
120
  Mustache does escape all values when using the standard double
109
- Mustache syntax. Characters which will be escaped: `& \ " < >`. To
110
- disable escaping, simply use tripple mustaches like
111
- `{{{unescaped_variable}}}`.
121
+ Mustache syntax. Characters which will be escaped: `& \ " < >` (as
122
+ well as `'` in Ruby `>= 2.0`). To disable escaping, simply use triple
123
+ mustaches like `{{{unescaped_variable}}}`.
112
124
 
113
125
  Example: Using `{{variable}}` inside a template for `5 > 2` will
114
126
  result in `5 &gt; 2`, where as the usage of `{{{variable}}}` will
115
127
  result in `5 > 2`.
116
128
 
117
129
 
118
- Dict-Style Views
119
- ----------------
130
+ ## Dict-Style Views
120
131
 
121
132
  ctemplate and friends want you to hand a dictionary to the template
122
133
  processor. Mustache supports a similar concept. Feel free to mix the
@@ -129,11 +140,12 @@ Given this template (winner.mustache):
129
140
 
130
141
  We can fill in the values at will:
131
142
 
132
- view = Winner.new
133
- view[:name] = 'George'
134
- view[:value] = 100
135
- view.render
136
-
143
+ ```ruby
144
+ view = Winner.new
145
+ view[:name] = 'George'
146
+ view[:value] = 100
147
+ view.render
148
+ ```
137
149
  Which returns:
138
150
 
139
151
  Hello George
@@ -141,14 +153,12 @@ Which returns:
141
153
 
142
154
  We can re-use the same object, too:
143
155
 
144
- view[:name] = 'Tony'
145
- view.render
146
- Hello Tony
147
- You have just won 100 bucks!
148
-
156
+ ```ruby
157
+ view[:name] = 'Tony'
158
+ view.render # => Hello Tony\nYou have just won 100 bucks!
159
+ ```
149
160
 
150
- Templates
151
- ---------
161
+ ## Templates
152
162
 
153
163
  A word on templates. By default, a view will try to find its template
154
164
  on disk by searching for an HTML file in the current directory that
@@ -156,42 +166,47 @@ follows the classic Ruby naming convention.
156
166
 
157
167
  TemplatePartial => ./template_partial.mustache
158
168
 
159
- You can set the search path using `Mustache.template_path`. It can be set on a
160
- class by class basis:
161
-
162
- class Simple < Mustache
163
- self.template_path = File.dirname(__FILE__)
164
- ... etc ...
165
- end
169
+ You can set the search path using `Mustache.template_path`. Search multiple
170
+ paths by delimiting them with your platform's 'path separator' (colon on Unix).
171
+ It can be set on a class by class basis:
166
172
 
173
+ ```ruby
174
+ class Simple < Mustache
175
+ self.template_path = __dir__
176
+ end
177
+ ```
167
178
  Now `Simple` will look for `simple.mustache` in the directory it resides
168
179
  in, no matter the cwd.
169
180
 
170
181
  If you want to just change what template is used you can set
171
182
  `Mustache.template_file` directly:
172
183
 
173
- Simple.template_file = './blah.mustache'
174
-
184
+ ```ruby
185
+ Simple.template_file = './blah.mustache'
186
+ ```
175
187
  Mustache also allows you to define the extension it'll use.
176
188
 
177
- Simple.template_extension = 'xml'
178
-
189
+ ```ruby
190
+ Simple.template_extension = 'xml'
191
+ ```
179
192
  Given all other defaults, the above line will cause Mustache to look
180
193
  for './blah.xml'
181
194
 
182
195
  Feel free to set the template directly:
183
196
 
184
- Simple.template = 'Hi {{person}}!'
197
+ ```ruby
198
+ Simple.template = 'Hi {{person}}!'
199
+ ```
185
200
 
186
201
  Or set a different template for a single instance:
187
-
188
- Simple.new.template = 'Hi {{person}}!'
202
+ ```ruby
203
+ Simple.new.template = 'Hi {{person}}!'
204
+ ```
189
205
 
190
206
  Whatever works.
191
207
 
192
208
 
193
- Views
194
- -----
209
+ ## Views
195
210
 
196
211
  Mustache supports a bit of magic when it comes to views. If you're
197
212
  authoring a plugin or extension for a web framework (Sinatra, Rails,
@@ -199,75 +214,80 @@ etc), check out the `view_namespace` and `view_path` settings on the
199
214
  `Mustache` class. They will surely provide needed assistance.
200
215
 
201
216
 
202
- Helpers
203
- -------
217
+ ## Helpers
204
218
 
205
219
  What about global helpers? Maybe you have a nifty `gravatar` function
206
220
  you want to use in all your views? No problem.
207
221
 
208
222
  This is just Ruby, after all.
209
223
 
210
- module ViewHelpers
211
- def gravatar
212
- gravatar_id = Digest::MD5.hexdigest(self[:email].to_s.strip.downcase)
213
- gravatar_for_id(gravatar_id)
214
- end
224
+ ```ruby
225
+ module ViewHelpers
226
+ def gravatar
227
+ gravatar_id = Digest::MD5.hexdigest(self[:email].to_s.strip.downcase)
228
+ gravatar_for_id(gravatar_id)
229
+ end
215
230
 
216
- def gravatar_for_id(gid, size = 30)
217
- "#{gravatar_host}/avatar/#{gid}?s=#{size}"
218
- end
231
+ def gravatar_for_id(gid, size = 30)
232
+ "#{gravatar_host}/avatar/#{gid}?s=#{size}"
233
+ end
219
234
 
220
- def gravatar_host
221
- @ssl ? 'https://secure.gravatar.com' : 'http://www.gravatar.com'
222
- end
223
- end
235
+ def gravatar_host
236
+ @ssl ? 'https://secure.gravatar.com' : 'http://www.gravatar.com'
237
+ end
238
+ end
239
+ ```
224
240
 
225
241
  Then just include it:
226
242
 
227
- class Simple < Mustache
228
- include ViewHelpers
243
+ ```ruby
244
+ class Simple < Mustache
245
+ include ViewHelpers
229
246
 
230
- def name
231
- "Chris"
232
- end
247
+ def name
248
+ "Chris"
249
+ end
233
250
 
234
- def value
235
- 10_000
236
- end
251
+ def value
252
+ 10_000
253
+ end
237
254
 
238
- def taxed_value
239
- value * 0.6
240
- end
255
+ def taxed_value
256
+ value * 0.6
257
+ end
241
258
 
242
- def in_ca
243
- true
244
- end
259
+ def in_ca
260
+ true
261
+ end
245
262
 
246
- def users
247
- User.all
248
- end
249
- end
263
+ def users
264
+ User.all
265
+ end
266
+ end
267
+ ```
250
268
 
251
269
  Great, but what about that `@ssl` ivar in `gravatar_host`? There are
252
270
  many ways we can go about setting it.
253
271
 
254
- Here's on example which illustrates a key feature of Mustache: you
272
+ Here's an example which illustrates a key feature of Mustache: you
255
273
  are free to use the `initialize` method just as you would in any
256
274
  normal class.
257
275
 
258
- class Simple < Mustache
259
- include ViewHelpers
260
-
261
- def initialize(ssl = false)
262
- @ssl = ssl
263
- end
276
+ ```ruby
277
+ class Simple < Mustache
278
+ include ViewHelpers
264
279
 
265
- ... etc ...
266
- end
280
+ def initialize(ssl = false)
281
+ @ssl = ssl
282
+ end
283
+ end
284
+ ```
267
285
 
268
286
  Now:
269
287
 
270
- Simple.new(request.ssl?).render
288
+ ```ruby
289
+ Simple.new(request.ssl?).render
290
+ ```
271
291
 
272
292
  Finally, our template might look like this:
273
293
 
@@ -278,98 +298,76 @@ Finally, our template might look like this:
278
298
  </ul>
279
299
 
280
300
 
281
- Sinatra
282
- -------
301
+ ## Integrations
283
302
 
284
- Mustache ships with Sinatra integration. Please see
285
- `lib/mustache/sinatra.rb` or
286
- <http://github.com/defunkt/mustache/blob/master/lib/mustache/sinatra.rb>
287
- for complete documentation.
303
+ ### Sinatra
304
+
305
+ Sinatra integration is available with the
306
+ [mustache-sinatra gem](https://github.com/mustache/mustache-sinatra).
288
307
 
289
308
  An example Sinatra application is also provided:
290
- <http://github.com/defunkt/mustache-sinatra-example>
309
+ <https://github.com/defunkt/mustache-sinatra-example>
291
310
 
292
311
  If you are upgrading to Sinatra 1.0 and Mustache 0.9.0+ from Mustache
293
312
  0.7.0 or lower, the settings have changed. But not that much.
294
313
 
295
- See [this diff](http://gist.github.com/345490) for what you need to
314
+ See [this diff][diff] for what you need to
296
315
  do. Basically, things are named properly now and all should be
297
316
  contained in a hash set using `set :mustache, hash`.
298
317
 
299
318
 
300
- [Rack::Bug][4]
301
- --------------
319
+ ### [Rack::Bug][4]
302
320
 
303
- Mustache also ships with a `Rack::Bug` panel. In your `config.ru` add
304
- the following code:
321
+ Mustache also provides a `Rack::Bug` panel.
322
+ First you have to install the `rack-bug-mustache_panel` gem, then in your `config.ru` add the following code:
305
323
 
306
- require 'rack/bug/panels/mustache_panel'
307
- use Rack::Bug::MustachePanel
324
+ ```ruby
325
+ require 'rack/bug/panels/mustache_panel'
326
+ use Rack::Bug::MustachePanel
327
+ ```
308
328
 
309
329
  Using Rails? Add this to your initializer or environment file:
310
330
 
311
- require 'rack/bug/panels/mustache_panel'
312
- config.middleware.use "Rack::Bug::MustachePanel"
313
-
314
- [![Rack::Bug](http://img.skitch.com/20091027-xyf4h1yxnefpp7usyddrcmc7dn.png)][5]
331
+ ```ruby
332
+ require 'rack/bug/panels/mustache_panel'
333
+ config.middleware.use "Rack::Bug::MustachePanel"
334
+ ```
315
335
 
336
+ ![Rack::Bug][5]
316
337
 
317
- Vim
318
- ---
319
338
 
320
- Thanks to [Juvenn Woo](http://github.com/juvenn) for mustache.vim. It
321
- is included under the contrib/ directory.
339
+ ### Vim
322
340
 
323
- See <http://gist.github.com/323622> for installation instructions.
341
+ vim-mustache-handlebars is available at [mustache/vim-mustache-handlebars][vim]
324
342
 
343
+ ### Emacs
325
344
 
326
- Emacs
327
- -----
345
+ mustache-mode.el is available at [mustache/emacs][emacs]
328
346
 
329
- mustache-mode.el is included under the contrib/ directory for any
330
- Emacs users. Based on Google's tpl-mode for ctemplates, it adds
331
- support for Mustache's more lenient tag values and includes a few
332
- commands for your editing pleasure.
333
347
 
334
- See <http://gist.github.com/323619> for installation instructions.
348
+ ### TextMate
335
349
 
350
+ [Mustache.tmbundle][tmbundle]
336
351
 
337
- TextMate
338
- --------
352
+ See <https://gist.github.com/defunkt/323624> for installation instructions.
339
353
 
340
- [Mustache.tmbundle](http://github.com/defunkt/Mustache.tmbundle)
341
354
 
342
- See <http://gist.github.com/323624> for installation instructions.
355
+ ### Command Line
343
356
 
344
-
345
- Command Line
346
- ------------
347
-
348
- See `mustache(1)` man page or
349
- <http://mustache.github.com/mustache.1.html>
357
+ See `mustache(1)` man page or <http://mustache.github.io/mustache.1.html>
350
358
  for command line docs.
351
359
 
352
360
 
353
- Installation
354
- ------------
361
+ ## Acknowledgements
355
362
 
356
- ### [RubyGems](http://rubygems.org/)
357
-
358
- $ gem install mustache
359
-
360
-
361
- Acknowledgements
362
- ----------------
363
-
364
- Thanks to [Tom Preston-Werner](http://github.com/mojombo) for showing
365
- me ctemplate and [Leah Culver](http://github.com/leah) for the name "Mustache."
363
+ Thanks to [Tom Preston-Werner](https://github.com/mojombo) for showing
364
+ me ctemplate and [Leah Culver](https://github.com/leah) for the name "Mustache."
366
365
 
367
366
  Special thanks to [Magnus Holm](http://judofyr.net/) for all his
368
367
  awesome work on Mustache's parser.
369
368
 
370
369
 
371
- Contributing
372
- ------------
370
+ ## Contributing
373
371
 
374
372
  Once you've made your great commits:
375
373
 
@@ -379,37 +377,39 @@ Once you've made your great commits:
379
377
  4. Create an [Issue][is] with a link to your branch
380
378
  5. That's it!
381
379
 
382
- You might want to checkout Resque's [Contributing][cb] wiki page for information
383
- on coding standards, new features, etc.
384
-
385
380
 
386
- Mailing List
387
- ------------
381
+ ## Mailing List
388
382
 
389
- To join the list simply send an email to <mustache@librelist.com>. This
383
+ ~~To join the list simply send an email to <mustache@librelist.com>. This
390
384
  will subscribe you and send you information about your subscription,
391
- including unsubscribe information.
385
+ including unsubscribe information.~~
392
386
 
393
- The archive can be found at <http://librelist.com/browser/>.
387
+ ~~The archive can be found at <http://librelist.com/browser/mustache/>.~~
394
388
 
389
+ The mailing list hasn't been updated in quite a while, please join us on Gitter
390
+ or IRC:
395
391
 
396
- Meta
397
- ----
392
+ [![Join the chat at https://gitter.im/mustache/mustache](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mustache/mustache?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
398
393
 
399
- * Code: `git clone git://github.com/defunkt/mustache.git`
400
- * Home: <http://mustache.github.com>
401
- * Bugs: <http://github.com/defunkt/mustache/issues>
402
- * List: <mustache@librelist.com>
403
- * Test: <http://runcoderun.com/defunkt/mustache>
404
- * Gems: <http://rubygems.org/gems/mustache>
394
+ [#{ on Freenode][irc]
395
+
396
+ ## Meta
405
397
 
406
- You can also find us in `#{` on irc.freenode.net.
398
+ * Code: `git clone https://github.com/mustache/mustache.git`
399
+ * Home: <http://mustache.github.io>
400
+ * Bugs: <https://github.com/mustache/mustache/issues>
401
+ * List: <mustache@librelist.com>
402
+ * Gems: <https://rubygems.org/gems/mustache>
407
403
 
408
- [1]: http://code.google.com/p/google-ctemplate/
404
+ [1]: https://github.com/olafvdspek/ctemplate
409
405
  [2]: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
410
406
  [3]: http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html
411
- [4]: http://github.com/brynary/rack-bug/
407
+ [4]: https://github.com/brynary/rack-bug/
412
408
  [5]: http://img.skitch.com/20091027-n8pxwwx8r61tc318a15q1n6m14.png
413
- [cb]: http://wiki.github.com/defunkt/resque/contributing
414
- [fk]: http://help.github.com/forking/
415
- [is]: http://github.com/defunkt/mustache/issues
409
+ [fk]: https://help.github.com/forking/
410
+ [is]: https://github.com/mustache/mustache/issues
411
+ [irc]: irc://irc.freenode.net/#{
412
+ [vim]: https://github.com/mustache/vim-mustache-handlebars
413
+ [emacs]: https://github.com/mustache/emacs
414
+ [tmbundle]: https://github.com/defunkt/Mustache.tmbundle
415
+ [diff]: https://gist.github.com/defunkt/345490
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rake/testtask'
2
- require 'rake/rdoctask'
2
+ require 'rdoc/task'
3
3
 
4
4
  #
5
5
  # Helpers
@@ -16,18 +16,10 @@ end
16
16
 
17
17
  task :default => :test
18
18
 
19
- if command? :turn
20
- desc "Run tests"
21
- task :test do
22
- suffix = "-n #{ENV['TEST']}" if ENV['TEST']
23
- sh "turn test/*.rb #{suffix}"
24
- end
25
- else
26
- Rake::TestTask.new do |t|
27
- t.libs << 'lib'
28
- t.pattern = 'test/**/*_test.rb'
29
- t.verbose = false
30
- end
19
+ Rake::TestTask.new do |t|
20
+ t.libs << 'lib'
21
+ t.pattern = 'test/**/*_test.rb'
22
+ t.verbose = false
31
23
  end
32
24
 
33
25
 
@@ -43,7 +35,7 @@ if command? :ronn
43
35
 
44
36
  desc "Build the manual"
45
37
  task "man:build" do
46
- sh "ronn -br5 --organization=DEFUNKT --manual='Mustache Manual' man/*.ron"
38
+ sh "ronn-ng -br5 --organization=DEFUNKT --manual='Mustache Manual' man/*.ron"
47
39
  end
48
40
  end
49
41
 
data/bin/mustache CHANGED
@@ -11,7 +11,7 @@ class Mustache
11
11
  # Return a structure describing the options.
12
12
  def self.parse_options(args)
13
13
  opts = OptionParser.new do |opts|
14
- opts.banner = "Usage: mustache [-c] [-t] [-r library] FILE ..."
14
+ opts.banner = "Usage: mustache [-c] [-t] [-l level] [-e] [-r library] FILE ..."
15
15
 
16
16
  opts.separator " "
17
17
 
@@ -42,6 +42,16 @@ class Mustache
42
42
  exit
43
43
  end
44
44
 
45
+ opts.on("-l", "--level",
46
+ "Provide a context access security level.") do |level|
47
+ Mustache.context_access_security_level = level.to_i
48
+ end
49
+
50
+ opts.on("-e", "--error",
51
+ "Raise an error on context misses.") do |e|
52
+ Mustache.raise_on_context_miss = true
53
+ end
54
+
45
55
  opts.on('-r', '--require LIB', 'Require a Ruby library before running.') do |lib|
46
56
  require lib
47
57
  end
@@ -49,7 +59,7 @@ class Mustache
49
59
  opts.separator "Common Options:"
50
60
 
51
61
  opts.on("-v", "--version", "Print the version") do |v|
52
- puts "Mustache v#{Mustache::Version}"
62
+ puts "Mustache v#{Mustache::VERSION}"
53
63
  exit
54
64
  end
55
65
 
@@ -64,20 +74,24 @@ class Mustache
64
74
  opts.parse!(args)
65
75
  end
66
76
 
67
- # Does the dirty work of reading files from STDIN and the command
68
- # line then processing them. The meat of this script, if you will.
69
- def self.process_files(input_stream)
70
- doc = input_stream.read
77
+ # Does the dirty work of reading files from the command line then
78
+ # processing them. The meat of this script, if you will.
79
+ def self.process_files(input_files)
80
+ doc = input_files.file.read
71
81
 
72
- if doc =~ /^(\s*---(.+)---\s*)/m
73
- yaml = $2.strip
74
- template = doc.sub($1, '')
82
+ yaml = nil
83
+ begin
84
+ yaml = YAML.load_stream(doc)
85
+ rescue
86
+ abort "Unable to parse yaml!"
87
+ end
75
88
 
76
- YAML.each_document(yaml) do |data|
77
- puts Mustache.render(template, data)
78
- end
79
- else
89
+ if yaml.nil?
80
90
  puts Mustache.render(doc)
91
+ else
92
+ template = input_files.skip.file.read
93
+
94
+ puts Mustache.render template, yaml.compact.reduce(&:merge)
81
95
  end
82
96
  end
83
97
  end
@@ -89,6 +103,6 @@ ARGV << '-h' if ARGV.empty? && $stdin.tty?
89
103
  # Process options
90
104
  Mustache::CLI.parse_options(ARGV) if $stdin.tty?
91
105
 
92
- # Still here - process ARGF
106
+ # Still here - process rest of ARGF
93
107
  Mustache::CLI.process_files(ARGF)
94
108