mustache 0.6.0 → 0.7.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.
Files changed (49) hide show
  1. data/README.md +2 -0
  2. data/Rakefile +9 -8
  3. data/bin/mustache +36 -10
  4. data/lib/mustache.rb +26 -0
  5. data/lib/mustache/context.rb +23 -0
  6. data/lib/mustache/template.rb +6 -5
  7. data/lib/mustache/version.rb +1 -1
  8. data/man/mustache.1 +18 -27
  9. data/man/mustache.1.html +3 -1
  10. data/man/mustache.5 +38 -52
  11. data/man/mustache.5.html +9 -4
  12. data/man/mustache.5.ron +3 -0
  13. data/test/autoloading_test.rb +1 -1
  14. data/test/fixtures/comments.mustache +1 -0
  15. data/test/fixtures/comments.rb +14 -0
  16. data/test/fixtures/complex_view.mustache +16 -0
  17. data/test/fixtures/complex_view.rb +34 -0
  18. data/test/fixtures/crazy_recursive.mustache +9 -0
  19. data/test/fixtures/crazy_recursive.rb +31 -0
  20. data/test/fixtures/delimiters.mustache +6 -0
  21. data/test/fixtures/delimiters.rb +22 -0
  22. data/test/fixtures/double_section.mustache +7 -0
  23. data/test/fixtures/double_section.rb +14 -0
  24. data/test/fixtures/escaped.mustache +1 -0
  25. data/test/fixtures/escaped.rb +14 -0
  26. data/test/fixtures/inner_partial.mustache +1 -0
  27. data/test/fixtures/inner_partial.txt +1 -0
  28. data/test/fixtures/namespaced.mustache +1 -0
  29. data/test/fixtures/namespaced.rb +25 -0
  30. data/test/fixtures/nested_objects.mustache +16 -0
  31. data/test/fixtures/nested_objects.rb +35 -0
  32. data/test/fixtures/node.mustache +8 -0
  33. data/test/fixtures/partial_with_module.mustache +3 -0
  34. data/test/fixtures/partial_with_module.rb +37 -0
  35. data/test/fixtures/passenger.conf +5 -0
  36. data/test/fixtures/passenger.rb +27 -0
  37. data/test/fixtures/recursive.mustache +4 -0
  38. data/test/fixtures/recursive.rb +14 -0
  39. data/test/fixtures/simple.mustache +5 -0
  40. data/test/fixtures/simple.rb +26 -0
  41. data/test/fixtures/template_partial.mustache +2 -0
  42. data/test/fixtures/template_partial.rb +18 -0
  43. data/test/fixtures/template_partial.txt +4 -0
  44. data/test/fixtures/unescaped.mustache +1 -0
  45. data/test/fixtures/unescaped.rb +14 -0
  46. data/test/helper.rb +5 -12
  47. data/test/mustache_test.rb +14 -2
  48. data/test/partial_test.rb +50 -3
  49. metadata +33 -1
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
- <meta name='generator' value='Ron/v0.3'>
5
+ <meta name='generator' value='Ronn/v0.4.1'>
6
6
  <title>mustache(5) -- Logic-less templates.</title>
7
7
  <style type='text/css'>
8
8
  body {margin:0}
@@ -64,6 +64,7 @@
64
64
 
65
65
  <h2 id='NAME'>NAME</h2>
66
66
  <p><code>mustache</code> -- Logic-less templates.</p>
67
+
67
68
  <h2>SYNOPSIS</h2>
68
69
 
69
70
  <p>A typical Mustache template:</p>
@@ -117,6 +118,9 @@ no <code>name</code> method, an exception will be raised.</p>
117
118
  <p>All variables are HTML escaped by default. If you want to return
118
119
  unescaped HTML, use the triple mustache: <code>{{{name}}}</code>.</p>
119
120
 
121
+ <p>You can also use <code>&amp;</code> to unescape a variable: <code>{{&amp; name}}</code>. This may be
122
+ useful when changing delimiters (see "Set Delimter" below).</p>
123
+
120
124
  <p>By default a variable "miss" returns an empty string. This can usually
121
125
  be configured in your Mustache library.</p>
122
126
 
@@ -261,9 +265,9 @@ delimiters from {{ and }} to custom strings.</p>
261
265
  <p>Consider the following contrived example:</p>
262
266
 
263
267
  <pre><code>* {{ default_tags }}
264
- {{=&lt;% %&gt;=}}
265
- * &lt;% erb_style_tags %&gt;
266
- &lt;%={{ }}=%&gt;
268
+ {{=&lt;% %>=}}
269
+ * &lt;% erb_style_tags %>
270
+ &lt;%={{ }}=%>
267
271
  * {{ default_tags_again }}
268
272
  </code></pre>
269
273
 
@@ -289,6 +293,7 @@ markup."</p>
289
293
  <p>mustache(1), mustache(7), gem(1),
290
294
  <a href="http://defunkt.github.com/mustache/">http://defunkt.github.com/mustache/</a></p>
291
295
 
296
+
292
297
  <ol class='foot man'>
293
298
  <li class='tl'>DEFUNKT</li>
294
299
  <li class='tc'>March 2010</li>
@@ -54,6 +54,9 @@ no `name` method, an exception will be raised.
54
54
  All variables are HTML escaped by default. If you want to return
55
55
  unescaped HTML, use the triple mustache: `{{{name}}}`.
56
56
 
57
+ You can also use `&` to unescape a variable: `{{& name}}`. This may be
58
+ useful when changing delimiters (see "Set Delimter" below).
59
+
57
60
  By default a variable "miss" returns an empty string. This can usually
58
61
  be configured in your Mustache library.
59
62
 
@@ -5,7 +5,7 @@ module TestViews; end
5
5
 
6
6
  class AutoloadingTest < Test::Unit::TestCase
7
7
  def setup
8
- Mustache.view_path = File.dirname(__FILE__) + '/../examples'
8
+ Mustache.view_path = File.dirname(__FILE__) + '/fixtures'
9
9
  end
10
10
 
11
11
  def test_autoload
@@ -0,0 +1 @@
1
+ <h1>{{title}}{{! just something interesting... #or not... }}</h1>
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Comments < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def title
8
+ "A Comedy of Errors"
9
+ end
10
+ end
11
+
12
+ if $0 == __FILE__
13
+ puts Comments.to_html
14
+ end
@@ -0,0 +1,16 @@
1
+ <h1>{{header}}</h1>
2
+ {{#list}}
3
+ <ul>
4
+ {{#item}}
5
+ {{#current}}
6
+ <li><strong>{{name}}</strong></li>
7
+ {{/current}}
8
+ {{#link}}
9
+ <li><a href="{{url}}">{{name}}</a></li>
10
+ {{/link}}
11
+ {{/item}}
12
+ </ul>
13
+ {{/list}}
14
+ {{#empty}}
15
+ <p>The list is empty.</p>
16
+ {{/empty}}
@@ -0,0 +1,34 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class ComplexView < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def header
8
+ "Colors"
9
+ end
10
+
11
+ def item
12
+ items = []
13
+ items << { :name => 'red', :current => true, :url => '#Red' }
14
+ items << { :name => 'green', :current => false, :url => '#Green' }
15
+ items << { :name => 'blue', :current => false, :url => '#Blue' }
16
+ items
17
+ end
18
+
19
+ def link
20
+ not self[:current]
21
+ end
22
+
23
+ def list
24
+ not item.empty?
25
+ end
26
+
27
+ def empty
28
+ item.empty?
29
+ end
30
+ end
31
+
32
+ if $0 == __FILE__
33
+ puts ComplexView.to_html
34
+ end
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <body>
3
+ <ul>
4
+ {{#top_nodes}}
5
+ {{> node}}
6
+ {{/top_nodes}}
7
+ </ul>
8
+ </body>
9
+ </html>
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class CrazyRecursive < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def top_nodes
8
+ [{ :contents => "1",
9
+ :children =>
10
+ [{ :contents => "2",
11
+ :children =>
12
+ [{ :contents => "3",
13
+ :children => []
14
+ }]
15
+ },
16
+ { :contents => "4",
17
+ :children =>
18
+ [{ :contents => "5",
19
+ :children =>
20
+ [{ :contents => "6",
21
+ :children => []
22
+ }]
23
+ }]
24
+ }]
25
+ }]
26
+ end
27
+ end
28
+
29
+ if $0 == __FILE__
30
+ puts CrazyRecursive.to_html
31
+ end
@@ -0,0 +1,6 @@
1
+ {{=<% %>=}}
2
+ * <% first %>
3
+ <%=| |=%>
4
+ * | second |
5
+ |={{ }}=|
6
+ * {{ third }}
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Delimiters < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def first
8
+ "It worked the first time."
9
+ end
10
+
11
+ def second
12
+ "And it worked the second time."
13
+ end
14
+
15
+ def third
16
+ "Then, surprisingly, it worked the third time."
17
+ end
18
+ end
19
+
20
+ if $0 == __FILE__
21
+ puts Delimiters.to_html
22
+ end
@@ -0,0 +1,7 @@
1
+ {{#t}}
2
+ * first
3
+ {{/t}}
4
+ * {{two}}
5
+ {{#t}}
6
+ * third
7
+ {{/t}}
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class DoubleSection < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def t
8
+ true
9
+ end
10
+
11
+ def two
12
+ "second"
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ <h1>{{title}}</h1>
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Escaped < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def title
8
+ "Bear > Shark"
9
+ end
10
+ end
11
+
12
+ if $0 == __FILE__
13
+ puts Escaped.to_html
14
+ end
@@ -0,0 +1 @@
1
+ Again, {{title}}!
@@ -0,0 +1 @@
1
+ ## Again, {{title}}! ##
@@ -0,0 +1 @@
1
+ <h1>{{title}}</h1>
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ module TestViews
5
+ class Namespaced < Mustache
6
+ self.path = File.dirname(__FILE__)
7
+
8
+ def title
9
+ "Dragon < Tiger"
10
+ end
11
+ end
12
+
13
+ class NamespacedWithPartial < Mustache
14
+ self.path = File.dirname(__FILE__)
15
+ self.template = "My opinion: {{>inner_partial}}"
16
+
17
+ def title
18
+ "Victory"
19
+ end
20
+ end
21
+ end
22
+
23
+ if $0 == __FILE__
24
+ puts TestViews::Namespaced.to_html
25
+ end
@@ -0,0 +1,16 @@
1
+ <h1>{{header}}</h1>
2
+ {{#list}}
3
+ <ul>
4
+ {{#item}}
5
+ {{#current}}
6
+ <li><strong>{{name}}</strong></li>
7
+ {{/current}}
8
+ {{#link}}
9
+ <li><a href="{{url}}">{{name}}</a></li>
10
+ {{/link}}
11
+ {{/item}}
12
+ </ul>
13
+ {{/list}}
14
+ {{#empty}}
15
+ <p>The list is empty.</p>
16
+ {{/empty}}
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+ require 'ostruct'
4
+
5
+ class NestedObjects < Mustache
6
+ self.path = File.dirname(__FILE__)
7
+
8
+ def header
9
+ "Colors"
10
+ end
11
+
12
+ def item
13
+ items = []
14
+ items << OpenStruct.new(:name => 'red', :current => true, :url => '#Red')
15
+ items << OpenStruct.new(:name => 'green', :current => false, :url => '#Green')
16
+ items << OpenStruct.new(:name => 'blue', :current => false, :url => '#Blue')
17
+ items
18
+ end
19
+
20
+ def link
21
+ not self[:current]
22
+ end
23
+
24
+ def list
25
+ not item.empty?
26
+ end
27
+
28
+ def empty
29
+ item.empty?
30
+ end
31
+ end
32
+
33
+ if $0 == __FILE__
34
+ puts NestedObjects.to_html
35
+ end
@@ -0,0 +1,8 @@
1
+ <li>
2
+ {{contents}}
3
+ <ul>
4
+ {{#children}}
5
+ {{> node}}
6
+ {{/children}}
7
+ </ul>
8
+ </li>
@@ -0,0 +1,3 @@
1
+ <h1>{{greeting}}</h1>
2
+ {{>simple}}
3
+ <h3>{{farewell}}</h3>
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ module SimpleView
5
+ def name
6
+ "Bob"
7
+ end
8
+
9
+ def value
10
+ 100_000
11
+ end
12
+
13
+ def taxed_value
14
+ value - (value * 0.4)
15
+ end
16
+
17
+ def in_ca
18
+ false
19
+ end
20
+ end
21
+
22
+ class PartialWithModule < Mustache
23
+ include SimpleView
24
+ self.path = File.dirname(__FILE__)
25
+
26
+ def greeting
27
+ "Welcome"
28
+ end
29
+
30
+ def farewell
31
+ "Fair enough, right?"
32
+ end
33
+ end
34
+
35
+ if $0 == __FILE__
36
+ puts PartialWithModule.to_html
37
+ end
@@ -0,0 +1,5 @@
1
+ <VirtualHost *>
2
+ ServerName {{server}}
3
+ DocumentRoot {{deploy_to}}
4
+ RailsEnv {{stage}}
5
+ </VirtualHost>
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Passenger < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+ self.template_extension = 'conf'
7
+
8
+ def server
9
+ "example.com"
10
+ end
11
+
12
+ def deploy_to
13
+ "/var/www/example.com"
14
+ end
15
+
16
+ def stage
17
+ "production"
18
+ end
19
+
20
+ def timestamp
21
+ Time.now.strftime('%Y%m%d%H%M%S')
22
+ end
23
+ end
24
+
25
+ if $0 == __FILE__
26
+ puts Passenger.to_text
27
+ end
@@ -0,0 +1,4 @@
1
+ It works!
2
+ {{#show}}
3
+ {{>recursive}}
4
+ {{/show}}
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Recursive < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def show
8
+ false
9
+ end
10
+ end
11
+
12
+ if $0 == __FILE__
13
+ puts Recursive.to_html
14
+ end