mustache 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/Rakefile +9 -8
- data/bin/mustache +36 -10
- data/lib/mustache.rb +26 -0
- data/lib/mustache/context.rb +23 -0
- data/lib/mustache/template.rb +6 -5
- data/lib/mustache/version.rb +1 -1
- data/man/mustache.1 +18 -27
- data/man/mustache.1.html +3 -1
- data/man/mustache.5 +38 -52
- data/man/mustache.5.html +9 -4
- data/man/mustache.5.ron +3 -0
- data/test/autoloading_test.rb +1 -1
- data/test/fixtures/comments.mustache +1 -0
- data/test/fixtures/comments.rb +14 -0
- data/test/fixtures/complex_view.mustache +16 -0
- data/test/fixtures/complex_view.rb +34 -0
- data/test/fixtures/crazy_recursive.mustache +9 -0
- data/test/fixtures/crazy_recursive.rb +31 -0
- data/test/fixtures/delimiters.mustache +6 -0
- data/test/fixtures/delimiters.rb +22 -0
- data/test/fixtures/double_section.mustache +7 -0
- data/test/fixtures/double_section.rb +14 -0
- data/test/fixtures/escaped.mustache +1 -0
- data/test/fixtures/escaped.rb +14 -0
- data/test/fixtures/inner_partial.mustache +1 -0
- data/test/fixtures/inner_partial.txt +1 -0
- data/test/fixtures/namespaced.mustache +1 -0
- data/test/fixtures/namespaced.rb +25 -0
- data/test/fixtures/nested_objects.mustache +16 -0
- data/test/fixtures/nested_objects.rb +35 -0
- data/test/fixtures/node.mustache +8 -0
- data/test/fixtures/partial_with_module.mustache +3 -0
- data/test/fixtures/partial_with_module.rb +37 -0
- data/test/fixtures/passenger.conf +5 -0
- data/test/fixtures/passenger.rb +27 -0
- data/test/fixtures/recursive.mustache +4 -0
- data/test/fixtures/recursive.rb +14 -0
- data/test/fixtures/simple.mustache +5 -0
- data/test/fixtures/simple.rb +26 -0
- data/test/fixtures/template_partial.mustache +2 -0
- data/test/fixtures/template_partial.rb +18 -0
- data/test/fixtures/template_partial.txt +4 -0
- data/test/fixtures/unescaped.mustache +1 -0
- data/test/fixtures/unescaped.rb +14 -0
- data/test/helper.rb +5 -12
- data/test/mustache_test.rb +14 -2
- data/test/partial_test.rb +50 -3
- metadata +33 -1
@@ -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,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 @@
|
|
1
|
+
<h1>{{{title}}}</h1>
|
data/test/helper.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '
|
4
|
-
|
5
|
-
|
6
|
-
require
|
7
|
-
|
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
|
data/test/mustache_test.rb
CHANGED
@@ -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("
|
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__) + '
|
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
|
data/test/partial_test.rb
CHANGED
@@ -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__) + '
|
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__) + '
|
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__) + '
|
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.
|
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
|