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
data/man/mustache.5.html
CHANGED
@@ -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='
|
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>&</code> to unescape a variable: <code>{{& 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
|
-
{{=<%
|
265
|
-
* <% erb_style_tags
|
266
|
-
<%={{ }}
|
268
|
+
{{=<% %>=}}
|
269
|
+
* <% erb_style_tags %>
|
270
|
+
<%={{ }}=%>
|
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>
|
data/man/mustache.5.ron
CHANGED
@@ -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
|
|
data/test/autoloading_test.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<h1>{{title}}{{! just something interesting... #or not... }}</h1>
|
@@ -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,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,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 @@
|
|
1
|
+
<h1>{{title}}</h1>
|
@@ -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,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,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
|