mustache-bibanon 0.99.5

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 (70) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +409 -0
  3. data/Rakefile +89 -0
  4. data/bin/mustache +94 -0
  5. data/lib/mustache.rb +304 -0
  6. data/lib/mustache/context.rb +142 -0
  7. data/lib/mustache/generator.rb +195 -0
  8. data/lib/mustache/parser.rb +263 -0
  9. data/lib/mustache/settings.rb +226 -0
  10. data/lib/mustache/sinatra.rb +205 -0
  11. data/lib/mustache/template.rb +58 -0
  12. data/lib/mustache/version.rb +3 -0
  13. data/lib/rack/bug/panels/mustache_panel.rb +81 -0
  14. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +27 -0
  15. data/lib/rack/bug/panels/mustache_panel/view.mustache +46 -0
  16. data/man/mustache.1 +165 -0
  17. data/man/mustache.1.html +213 -0
  18. data/man/mustache.1.ron +127 -0
  19. data/man/mustache.5 +539 -0
  20. data/man/mustache.5.html +422 -0
  21. data/man/mustache.5.ron +324 -0
  22. data/test/autoloading_test.rb +56 -0
  23. data/test/fixtures/comments.mustache +1 -0
  24. data/test/fixtures/comments.rb +14 -0
  25. data/test/fixtures/complex_view.mustache +17 -0
  26. data/test/fixtures/complex_view.rb +34 -0
  27. data/test/fixtures/crazy_recursive.mustache +9 -0
  28. data/test/fixtures/crazy_recursive.rb +31 -0
  29. data/test/fixtures/delimiters.mustache +8 -0
  30. data/test/fixtures/delimiters.rb +23 -0
  31. data/test/fixtures/dot_notation.mustache +10 -0
  32. data/test/fixtures/dot_notation.rb +25 -0
  33. data/test/fixtures/double_section.mustache +7 -0
  34. data/test/fixtures/double_section.rb +14 -0
  35. data/test/fixtures/escaped.mustache +1 -0
  36. data/test/fixtures/escaped.rb +14 -0
  37. data/test/fixtures/inner_partial.mustache +1 -0
  38. data/test/fixtures/inner_partial.txt +1 -0
  39. data/test/fixtures/inverted_section.mustache +7 -0
  40. data/test/fixtures/inverted_section.rb +14 -0
  41. data/test/fixtures/lambda.mustache +7 -0
  42. data/test/fixtures/lambda.rb +31 -0
  43. data/test/fixtures/method_missing.rb +19 -0
  44. data/test/fixtures/namespaced.mustache +1 -0
  45. data/test/fixtures/namespaced.rb +25 -0
  46. data/test/fixtures/nested_objects.mustache +17 -0
  47. data/test/fixtures/nested_objects.rb +35 -0
  48. data/test/fixtures/node.mustache +8 -0
  49. data/test/fixtures/partial_with_module.mustache +4 -0
  50. data/test/fixtures/partial_with_module.rb +37 -0
  51. data/test/fixtures/passenger.conf +5 -0
  52. data/test/fixtures/passenger.rb +27 -0
  53. data/test/fixtures/recursive.mustache +4 -0
  54. data/test/fixtures/recursive.rb +14 -0
  55. data/test/fixtures/simple.mustache +5 -0
  56. data/test/fixtures/simple.rb +26 -0
  57. data/test/fixtures/template_partial.mustache +2 -0
  58. data/test/fixtures/template_partial.rb +18 -0
  59. data/test/fixtures/template_partial.txt +4 -0
  60. data/test/fixtures/unescaped.mustache +1 -0
  61. data/test/fixtures/unescaped.rb +14 -0
  62. data/test/fixtures/utf8.mustache +3 -0
  63. data/test/fixtures/utf8_partial.mustache +1 -0
  64. data/test/helper.rb +7 -0
  65. data/test/mustache_test.rb +677 -0
  66. data/test/parser_test.rb +78 -0
  67. data/test/partial_test.rb +168 -0
  68. data/test/spec_test.rb +68 -0
  69. data/test/template_test.rb +20 -0
  70. metadata +147 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Chris Wanstrath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,409 @@
1
+ Mustache
2
+ =========
3
+
4
+ Inspired by [ctemplate][1] and [et][2], Mustache is a
5
+ framework-agnostic way to render logic-free views.
6
+
7
+ As ctemplates says, "It emphasizes separating logic from presentation:
8
+ it is impossible to embed application logic in this template language."
9
+
10
+ For a list of implementations (other than Ruby) and tips, see
11
+ <http://mustache.github.com/>.
12
+
13
+
14
+ Overview
15
+ --------
16
+
17
+ Think of Mustache as a replacement for your views. Instead of views
18
+ consisting of ERB or HAML with random helpers and arbitrary logic,
19
+ your views are broken into two parts: a Ruby class and an HTML
20
+ template.
21
+
22
+ We call the Ruby class the "view" and the HTML template the
23
+ "template."
24
+
25
+ All your logic, decisions, and code is contained in your view. All
26
+ your markup is contained in your template. The template does nothing
27
+ but reference methods in your view.
28
+
29
+ This strict separation makes it easier to write clean templates,
30
+ easier to test your views, and more fun to work on your app's front end.
31
+
32
+
33
+ Why?
34
+ ----
35
+
36
+ I like writing Ruby. I like writing HTML. I like writing JavaScript.
37
+
38
+ I don't like writing ERB, Haml, Liquid, Django Templates, putting Ruby
39
+ in my HTML, or putting JavaScript in my HTML.
40
+
41
+
42
+ Usage
43
+ -----
44
+
45
+ Quick example:
46
+
47
+ >> require 'mustache'
48
+ => true
49
+ >> Mustache.render("Hello {{planet}}", :planet => "World!")
50
+ => "Hello World!"
51
+
52
+ We've got an `examples` folder but here's the canonical one:
53
+
54
+ class Simple < Mustache
55
+ def name
56
+ "Chris"
57
+ end
58
+
59
+ def value
60
+ 10_000
61
+ end
62
+
63
+ def taxed_value
64
+ value * 0.6
65
+ end
66
+
67
+ def in_ca
68
+ true
69
+ end
70
+ end
71
+
72
+ We simply create a normal Ruby class and define methods. Some methods
73
+ reference others, some return values, some return only booleans.
74
+
75
+ Now let's write the template:
76
+
77
+ Hello {{name}}
78
+ You have just won {{value}} dollars!
79
+ {{#in_ca}}
80
+ Well, {{taxed_value}} dollars, after taxes.
81
+ {{/in_ca}}
82
+
83
+ This template references our view methods. To bring it all together,
84
+ here's the code to render actual HTML;
85
+
86
+ Simple.render
87
+
88
+ Which returns the following:
89
+
90
+ Hello Chris
91
+ You have just won 10000 dollars!
92
+ Well, 6000.0 dollars, after taxes.
93
+
94
+ Simple.
95
+
96
+
97
+ Tag Types
98
+ ---------
99
+
100
+ For a language-agnostic overview of Mustache's template syntax, see
101
+ the `mustache(5)` manpage or
102
+ <http://mustache.github.com/mustache.5.html>.
103
+
104
+
105
+ Escaping
106
+ --------
107
+
108
+ Mustache does escape all values when using the standard double
109
+ Mustache syntax. Characters which will be escaped: `& \ " < >`. To
110
+ disable escaping, simply use triple mustaches like
111
+ `{{{unescaped_variable}}}`.
112
+
113
+ Example: Using `{{variable}}` inside a template for `5 > 2` will
114
+ result in `5 &gt; 2`, where as the usage of `{{{variable}}}` will
115
+ result in `5 > 2`.
116
+
117
+
118
+ Dict-Style Views
119
+ ----------------
120
+
121
+ ctemplate and friends want you to hand a dictionary to the template
122
+ processor. Mustache supports a similar concept. Feel free to mix the
123
+ class-based and this more procedural style at your leisure.
124
+
125
+ Given this template (winner.mustache):
126
+
127
+ Hello {{name}}
128
+ You have just won {{value}} bucks!
129
+
130
+ We can fill in the values at will:
131
+
132
+ view = Winner.new
133
+ view[:name] = 'George'
134
+ view[:value] = 100
135
+ view.render
136
+
137
+ Which returns:
138
+
139
+ Hello George
140
+ You have just won 100 bucks!
141
+
142
+ We can re-use the same object, too:
143
+
144
+ view[:name] = 'Tony'
145
+ view.render
146
+ Hello Tony
147
+ You have just won 100 bucks!
148
+
149
+
150
+ Templates
151
+ ---------
152
+
153
+ A word on templates. By default, a view will try to find its template
154
+ on disk by searching for an HTML file in the current directory that
155
+ follows the classic Ruby naming convention.
156
+
157
+ TemplatePartial => ./template_partial.mustache
158
+
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
166
+
167
+ Now `Simple` will look for `simple.mustache` in the directory it resides
168
+ in, no matter the cwd.
169
+
170
+ If you want to just change what template is used you can set
171
+ `Mustache.template_file` directly:
172
+
173
+ Simple.template_file = './blah.mustache'
174
+
175
+ Mustache also allows you to define the extension it'll use.
176
+
177
+ Simple.template_extension = 'xml'
178
+
179
+ Given all other defaults, the above line will cause Mustache to look
180
+ for './blah.xml'
181
+
182
+ Feel free to set the template directly:
183
+
184
+ Simple.template = 'Hi {{person}}!'
185
+
186
+ Or set a different template for a single instance:
187
+
188
+ Simple.new.template = 'Hi {{person}}!'
189
+
190
+ Whatever works.
191
+
192
+
193
+ Views
194
+ -----
195
+
196
+ Mustache supports a bit of magic when it comes to views. If you're
197
+ authoring a plugin or extension for a web framework (Sinatra, Rails,
198
+ etc), check out the `view_namespace` and `view_path` settings on the
199
+ `Mustache` class. They will surely provide needed assistance.
200
+
201
+
202
+ Helpers
203
+ -------
204
+
205
+ What about global helpers? Maybe you have a nifty `gravatar` function
206
+ you want to use in all your views? No problem.
207
+
208
+ This is just Ruby, after all.
209
+
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
215
+
216
+ def gravatar_for_id(gid, size = 30)
217
+ "#{gravatar_host}/avatar/#{gid}?s=#{size}"
218
+ end
219
+
220
+ def gravatar_host
221
+ @ssl ? 'https://secure.gravatar.com' : 'http://www.gravatar.com'
222
+ end
223
+ end
224
+
225
+ Then just include it:
226
+
227
+ class Simple < Mustache
228
+ include ViewHelpers
229
+
230
+ def name
231
+ "Chris"
232
+ end
233
+
234
+ def value
235
+ 10_000
236
+ end
237
+
238
+ def taxed_value
239
+ value * 0.6
240
+ end
241
+
242
+ def in_ca
243
+ true
244
+ end
245
+
246
+ def users
247
+ User.all
248
+ end
249
+ end
250
+
251
+ Great, but what about that `@ssl` ivar in `gravatar_host`? There are
252
+ many ways we can go about setting it.
253
+
254
+ Here's on example which illustrates a key feature of Mustache: you
255
+ are free to use the `initialize` method just as you would in any
256
+ normal class.
257
+
258
+ class Simple < Mustache
259
+ include ViewHelpers
260
+
261
+ def initialize(ssl = false)
262
+ @ssl = ssl
263
+ end
264
+
265
+ ... etc ...
266
+ end
267
+
268
+ Now:
269
+
270
+ Simple.new(request.ssl?).render
271
+
272
+ Finally, our template might look like this:
273
+
274
+ <ul>
275
+ {{# users}}
276
+ <li><img src="{{ gravatar }}"> {{ login }}</li>
277
+ {{/ users}}
278
+ </ul>
279
+
280
+
281
+ Sinatra
282
+ -------
283
+
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.
288
+
289
+ An example Sinatra application is also provided:
290
+ <http://github.com/defunkt/mustache-sinatra-example>
291
+
292
+ If you are upgrading to Sinatra 1.0 and Mustache 0.9.0+ from Mustache
293
+ 0.7.0 or lower, the settings have changed. But not that much.
294
+
295
+ See [this diff](http://gist.github.com/345490) for what you need to
296
+ do. Basically, things are named properly now and all should be
297
+ contained in a hash set using `set :mustache, hash`.
298
+
299
+
300
+ [Rack::Bug][4]
301
+ --------------
302
+
303
+ Mustache also ships with a `Rack::Bug` panel. In your `config.ru` add
304
+ the following code:
305
+
306
+ require 'rack/bug/panels/mustache_panel'
307
+ use Rack::Bug::MustachePanel
308
+
309
+ Using Rails? Add this to your initializer or environment file:
310
+
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]
315
+
316
+
317
+ Vim
318
+ ---
319
+
320
+ Thanks to [Juvenn Woo](http://github.com/juvenn) for mustache.vim. It
321
+ is included under the contrib/ directory.
322
+
323
+ See <http://gist.github.com/323622> for installation instructions.
324
+
325
+
326
+ Emacs
327
+ -----
328
+
329
+ mustache-mode.el is available at https://github.com/mustache/emacs
330
+
331
+
332
+ TextMate
333
+ --------
334
+
335
+ [Mustache.tmbundle](http://github.com/defunkt/Mustache.tmbundle)
336
+
337
+ See <http://gist.github.com/323624> for installation instructions.
338
+
339
+
340
+ Command Line
341
+ ------------
342
+
343
+ See `mustache(1)` man page or
344
+ <http://mustache.github.com/mustache.1.html>
345
+ for command line docs.
346
+
347
+
348
+ Installation
349
+ ------------
350
+
351
+ ### [RubyGems](http://rubygems.org/)
352
+
353
+ $ gem install mustache
354
+
355
+
356
+ Acknowledgements
357
+ ----------------
358
+
359
+ Thanks to [Tom Preston-Werner](http://github.com/mojombo) for showing
360
+ me ctemplate and [Leah Culver](http://github.com/leah) for the name "Mustache."
361
+
362
+ Special thanks to [Magnus Holm](http://judofyr.net/) for all his
363
+ awesome work on Mustache's parser.
364
+
365
+
366
+ Contributing
367
+ ------------
368
+
369
+ Once you've made your great commits:
370
+
371
+ 1. [Fork][fk] Mustache
372
+ 2. Create a topic branch - `git checkout -b my_branch`
373
+ 3. Push to your branch - `git push origin my_branch`
374
+ 4. Create an [Issue][is] with a link to your branch
375
+ 5. That's it!
376
+
377
+ You might want to checkout Resque's [Contributing][cb] wiki page for information
378
+ on coding standards, new features, etc.
379
+
380
+
381
+ Mailing List
382
+ ------------
383
+
384
+ To join the list simply send an email to <mustache@librelist.com>. This
385
+ will subscribe you and send you information about your subscription,
386
+ including unsubscribe information.
387
+
388
+ The archive can be found at <http://librelist.com/browser/>.
389
+
390
+
391
+ Meta
392
+ ----
393
+
394
+ * Code: `git clone git://github.com/defunkt/mustache.git`
395
+ * Home: <http://mustache.github.com>
396
+ * Bugs: <http://github.com/defunkt/mustache/issues>
397
+ * List: <mustache@librelist.com>
398
+ * Gems: <http://rubygems.org/gems/mustache>
399
+
400
+ You can also find us in `#{` on irc.freenode.net.
401
+
402
+ [1]: http://code.google.com/p/google-ctemplate/
403
+ [2]: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
404
+ [3]: http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html
405
+ [4]: http://github.com/brynary/rack-bug/
406
+ [5]: http://img.skitch.com/20091027-n8pxwwx8r61tc318a15q1n6m14.png
407
+ [cb]: http://wiki.github.com/defunkt/resque/contributing
408
+ [fk]: http://help.github.com/forking/
409
+ [is]: http://github.com/defunkt/mustache/issues
@@ -0,0 +1,89 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+
4
+ #
5
+ # Helpers
6
+ #
7
+
8
+ def command?(command)
9
+ system("type #{command} &> /dev/null")
10
+ end
11
+
12
+
13
+ #
14
+ # Tests
15
+ #
16
+
17
+ task :default => :test
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
31
+ end
32
+
33
+
34
+ #
35
+ # Ron
36
+ #
37
+
38
+ if command? :ronn
39
+ desc "Show the manual"
40
+ task :man => "man:build" do
41
+ exec "man man/mustache.1"
42
+ end
43
+
44
+ desc "Build the manual"
45
+ task "man:build" do
46
+ sh "ronn -br5 --organization=DEFUNKT --manual='Mustache Manual' man/*.ron"
47
+ end
48
+ end
49
+
50
+
51
+ #
52
+ # Gems
53
+ #
54
+
55
+ desc "Push a new version to Gemcutter and publish docs."
56
+ task :publish do
57
+ require File.dirname(__FILE__) + '/lib/mustache/version'
58
+
59
+ system "git tag v#{Mustache::Version}"
60
+ sh "gem build mustache.gemspec"
61
+ sh "gem push mustache-#{Mustache::Version}.gem"
62
+ sh "git push origin master --tags"
63
+ sh "git clean -fd"
64
+ exec "rake pages"
65
+ end
66
+
67
+ #
68
+ # Documentation
69
+ #
70
+
71
+ desc "Publish to GitHub Pages"
72
+ task :pages => [ "man:build" ] do
73
+ Dir['man/*.html'].each do |f|
74
+ cp f, File.basename(f).sub('.html', '.newhtml')
75
+ end
76
+
77
+ `git commit -am 'generated manual'`
78
+ `git checkout site`
79
+
80
+ Dir['*.newhtml'].each do |f|
81
+ mv f, f.sub('.newhtml', '.html')
82
+ end
83
+
84
+ `git add .`
85
+ `git commit -m updated`
86
+ `git push site site:master`
87
+ `git checkout master`
88
+ puts :done
89
+ end