mustache 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,5 @@
1
+ Hello {{name}}
2
+ You have just won ${{value}}!
3
+ {{#in_ca}}
4
+ Well, ${{ taxed_value }}, after taxes.
5
+ {{/in_ca}}
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class Simple < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def name
8
+ "Chris"
9
+ end
10
+
11
+ def value
12
+ 10_000
13
+ end
14
+
15
+ def taxed_value
16
+ value - (value * 0.4)
17
+ end
18
+
19
+ def in_ca
20
+ true
21
+ end
22
+ end
23
+
24
+ if $0 == __FILE__
25
+ puts Simple.to_html
26
+ end
@@ -0,0 +1,2 @@
1
+ <h1>{{title}}</h1>
2
+ {{>inner_partial}}
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mustache'
3
+
4
+ class TemplatePartial < Mustache
5
+ self.path = File.dirname(__FILE__)
6
+
7
+ def title
8
+ "Welcome"
9
+ end
10
+
11
+ def title_bars
12
+ '-' * title.size
13
+ end
14
+ end
15
+
16
+ if $0 == __FILE__
17
+ puts TemplatePartial.to_html
18
+ end
@@ -0,0 +1,4 @@
1
+ {{title}}
2
+ {{title_bars}}
3
+
4
+ {{>inner_partial}}
@@ -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 Unescaped < 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 Unescaped.to_html
14
+ end
@@ -1,14 +1,7 @@
1
1
  require 'test/unit'
2
2
 
3
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../examples'
4
- require 'simple'
5
- require 'complex_view'
6
- require 'partial_with_module'
7
- require 'template_partial'
8
- require 'escaped'
9
- require 'unescaped'
10
- require 'comments'
11
- require 'passenger'
12
- require 'delimiters'
13
- require 'double_section'
14
- require 'nested_objects'
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/fixtures'
4
+
5
+ Dir[File.dirname(__FILE__) + '/fixtures/*.rb'].each do |f|
6
+ require f
7
+ end
@@ -139,6 +139,13 @@ end_section
139
139
  assert_equal '<h1>Bear > Shark</h1>', Unescaped.render
140
140
  end
141
141
 
142
+ def test_unescaped_ampersand
143
+ view = Mustache.new
144
+ view.template = "<h1>{{& title}}</h1>"
145
+ view[:title] = "Bear > Shark"
146
+ assert_equal '<h1>Bear > Shark</h1>', view.render
147
+ end
148
+
142
149
  def test_classify
143
150
  assert_equal 'TemplatePartial', Mustache.classify('template_partial')
144
151
  end
@@ -172,7 +179,7 @@ end_section
172
179
  RailsEnv production
173
180
  </VirtualHost>
174
181
  data
175
- template = File.read("examples/passenger.conf")
182
+ template = File.read(File.dirname(__FILE__) + "/fixtures/passenger.conf")
176
183
  assert_equal expected, Mustache.render(template, :stage => 'production',
177
184
  :server => 'example.com',
178
185
  :deploy_to => '/var/www/example.com' )
@@ -265,7 +272,7 @@ data
265
272
 
266
273
  def test_knows_when_its_been_compiled_when_using_a_file_template
267
274
  klass = Class.new(Simple)
268
- klass.template_file = File.dirname(__FILE__) + '/../examples/simple.mustache'
275
+ klass.template_file = File.dirname(__FILE__) + '/fixtures/simple.mustache'
269
276
 
270
277
  assert ! klass.compiled?
271
278
  klass.render
@@ -292,4 +299,9 @@ data
292
299
  instance.template = 'Hi, {{person}}!'
293
300
  assert instance.compiled?
294
301
  end
302
+
303
+ def test_compile
304
+ assert_equal '"Hi, #{CGI.escapeHTML(ctx[:person].to_s)}!"',
305
+ Mustache.compile("Hi, {{person}}!")
306
+ end
295
307
  end
@@ -14,7 +14,7 @@ end_partial
14
14
 
15
15
  def test_view_partial_inherits_context
16
16
  klass = Class.new(TemplatePartial)
17
- klass.template_path = File.dirname(__FILE__) + '/../examples'
17
+ klass.template_path = File.dirname(__FILE__) + '/fixtures'
18
18
  view = klass.new
19
19
  view[:titles] = [{:title => :One}, {:title => :Two}]
20
20
  view.template = <<-end_template
@@ -36,7 +36,7 @@ end_partial
36
36
 
37
37
  def test_view_partial_inherits_context_of_class_methods
38
38
  klass = Class.new(TemplatePartial)
39
- klass.template_path = File.dirname(__FILE__) + '/../examples'
39
+ klass.template_path = File.dirname(__FILE__) + '/fixtures'
40
40
  klass.send(:define_method, :titles) do
41
41
  [{:title => :One}, {:title => :Two}]
42
42
  end
@@ -68,13 +68,60 @@ end_partial
68
68
  def test_template_partial_with_custom_extension
69
69
  partial = Class.new(TemplatePartial)
70
70
  partial.template_extension = 'txt'
71
- partial.template_path = File.dirname(__FILE__) + '/../examples'
71
+ partial.template_path = File.dirname(__FILE__) + '/fixtures'
72
72
 
73
73
  assert_equal <<-end_partial.strip, partial.render.strip
74
74
  Welcome
75
75
  -------
76
76
 
77
77
  ## Again, Welcome! ##
78
+ end_partial
79
+ end
80
+
81
+ def test_recursive_paritals
82
+ assert_equal <<-end_partial, Recursive.render
83
+ It works!
84
+ end_partial
85
+ end
86
+
87
+ def test_crazy_recursive_partials
88
+ assert_equal <<-end_partial.strip, CrazyRecursive.render
89
+ <html>
90
+ <body>
91
+ <ul>
92
+ <li>
93
+ 1
94
+ <ul>
95
+ <li>
96
+ 2
97
+ <ul>
98
+ <li>
99
+ 3
100
+ <ul>
101
+ </ul>
102
+ </li>
103
+ </ul>
104
+ </li>
105
+ <li>
106
+ 4
107
+ <ul>
108
+ <li>
109
+ 5
110
+ <ul>
111
+ <li>
112
+ 6
113
+ <ul>
114
+ </ul>
115
+ </li>
116
+ </ul>
117
+ </li>
118
+ </ul>
119
+ </li>
120
+ </ul>
121
+ </li>
122
+ </ul>
123
+ </body>
124
+ </html>
78
125
  end_partial
79
126
  end
80
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -53,6 +53,38 @@ files:
53
53
  - man/mustache.5.html
54
54
  - man/mustache.5.ron
55
55
  - test/autoloading_test.rb
56
+ - test/fixtures/comments.mustache
57
+ - test/fixtures/comments.rb
58
+ - test/fixtures/complex_view.mustache
59
+ - test/fixtures/complex_view.rb
60
+ - test/fixtures/crazy_recursive.mustache
61
+ - test/fixtures/crazy_recursive.rb
62
+ - test/fixtures/delimiters.mustache
63
+ - test/fixtures/delimiters.rb
64
+ - test/fixtures/double_section.mustache
65
+ - test/fixtures/double_section.rb
66
+ - test/fixtures/escaped.mustache
67
+ - test/fixtures/escaped.rb
68
+ - test/fixtures/inner_partial.mustache
69
+ - test/fixtures/inner_partial.txt
70
+ - test/fixtures/namespaced.mustache
71
+ - test/fixtures/namespaced.rb
72
+ - test/fixtures/nested_objects.mustache
73
+ - test/fixtures/nested_objects.rb
74
+ - test/fixtures/node.mustache
75
+ - test/fixtures/partial_with_module.mustache
76
+ - test/fixtures/partial_with_module.rb
77
+ - test/fixtures/passenger.conf
78
+ - test/fixtures/passenger.rb
79
+ - test/fixtures/recursive.mustache
80
+ - test/fixtures/recursive.rb
81
+ - test/fixtures/simple.mustache
82
+ - test/fixtures/simple.rb
83
+ - test/fixtures/template_partial.mustache
84
+ - test/fixtures/template_partial.rb
85
+ - test/fixtures/template_partial.txt
86
+ - test/fixtures/unescaped.mustache
87
+ - test/fixtures/unescaped.rb
56
88
  - test/helper.rb
57
89
  - test/mustache_test.rb
58
90
  - test/partial_test.rb