mustache 0.5.1 → 0.6.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.
- data/README.md +30 -197
- data/Rakefile +87 -46
- data/bin/mustache +5 -29
- data/lib/mustache/context.rb +54 -11
- data/lib/mustache/template.rb +2 -14
- data/lib/mustache/version.rb +1 -1
- data/man/mustache.1 +138 -0
- data/man/mustache.1.html +168 -0
- data/man/mustache.1.ron +94 -0
- data/man/mustache.5 +364 -0
- data/man/mustache.5.html +300 -0
- data/man/mustache.5.ron +220 -0
- data/test/helper.rb +1 -0
- data/test/mustache_test.rb +19 -16
- metadata +32 -65
- data/.gitignore +0 -1
- data/.kick +0 -26
- data/CONTRIBUTORS +0 -7
- data/HISTORY.md +0 -76
- data/benchmarks/complex.erb +0 -15
- data/benchmarks/complex.haml +0 -10
- data/benchmarks/helper.rb +0 -20
- data/benchmarks/simple.erb +0 -5
- data/benchmarks/speed.rb +0 -76
- data/contrib/mustache.vim +0 -69
- data/contrib/tpl-mode.el +0 -274
- data/examples/comments.mustache +0 -1
- data/examples/comments.rb +0 -14
- data/examples/complex_view.mustache +0 -16
- data/examples/complex_view.rb +0 -34
- data/examples/delimiters.mustache +0 -6
- data/examples/delimiters.rb +0 -22
- data/examples/double_section.mustache +0 -7
- data/examples/double_section.rb +0 -14
- data/examples/escaped.mustache +0 -1
- data/examples/escaped.rb +0 -14
- data/examples/inner_partial.mustache +0 -1
- data/examples/inner_partial.txt +0 -1
- data/examples/namespaced.mustache +0 -1
- data/examples/namespaced.rb +0 -25
- data/examples/partial_with_module.mustache +0 -3
- data/examples/partial_with_module.rb +0 -37
- data/examples/passenger.conf +0 -5
- data/examples/passenger.rb +0 -27
- data/examples/simple.mustache +0 -5
- data/examples/simple.rb +0 -26
- data/examples/template_partial.mustache +0 -2
- data/examples/template_partial.rb +0 -18
- data/examples/template_partial.txt +0 -4
- data/examples/unescaped.mustache +0 -1
- data/examples/unescaped.rb +0 -14
data/man/mustache.5
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
.\" generated with Ron/v0.3
|
2
|
+
.\" http://github.com/rtomayko/ron/
|
3
|
+
.
|
4
|
+
.TH "MUSTACHE" "5" "March 2010" "DEFUNKT" "Mustache Manual"
|
5
|
+
.
|
6
|
+
.SH "NAME"
|
7
|
+
\fBmustache\fR \-\- Logic\-less templates.
|
8
|
+
.
|
9
|
+
.SH "SYNOPSIS"
|
10
|
+
A typical Mustache template:
|
11
|
+
.
|
12
|
+
.IP "" 4
|
13
|
+
.
|
14
|
+
.nf
|
15
|
+
|
16
|
+
\fBHello {{name}}
|
17
|
+
You have just won ${{value}}!
|
18
|
+
{{#in_ca}}
|
19
|
+
Well, ${{taxed_value}}, after taxes.
|
20
|
+
{{/in_ca}} \fR
|
21
|
+
.
|
22
|
+
.fi
|
23
|
+
.
|
24
|
+
.IP "" 0
|
25
|
+
.
|
26
|
+
.P
|
27
|
+
Given the following hash:
|
28
|
+
.
|
29
|
+
.IP "" 4
|
30
|
+
.
|
31
|
+
.nf
|
32
|
+
|
33
|
+
\fB{
|
34
|
+
"name": "Chris",
|
35
|
+
"value": 10000,
|
36
|
+
"taxed_value": 10000 - (10000 * 0.4),
|
37
|
+
"in_ca": true
|
38
|
+
} \fR
|
39
|
+
.
|
40
|
+
.fi
|
41
|
+
.
|
42
|
+
.IP "" 0
|
43
|
+
.
|
44
|
+
.P
|
45
|
+
Will produce the following:
|
46
|
+
.
|
47
|
+
.IP "" 4
|
48
|
+
.
|
49
|
+
.nf
|
50
|
+
|
51
|
+
\fBHello Chris
|
52
|
+
You have just won $10000!
|
53
|
+
Well, $6000.0, after taxes. \fR
|
54
|
+
.
|
55
|
+
.fi
|
56
|
+
.
|
57
|
+
.IP "" 0
|
58
|
+
.
|
59
|
+
.SH "DESCRIPTION"
|
60
|
+
Mustache can be used for HTML, config files, source code \-
|
61
|
+
anything. It works by expanding tags in a template using values
|
62
|
+
provided in a hash or object.
|
63
|
+
.
|
64
|
+
.P
|
65
|
+
We call it "logic\-less" because there are no if statements, else
|
66
|
+
clauses, or for loops. Instead there are only tags. Some tags are
|
67
|
+
replaced with a value, some nothing, and others a series of
|
68
|
+
values. This document explains the different types of Mustache tags.
|
69
|
+
.
|
70
|
+
.SH "TAG TYPES"
|
71
|
+
Tags are indicated by the double mustaches. \fB{{name}}\fR is a tag. Let's
|
72
|
+
talk about the different types of tags.
|
73
|
+
.
|
74
|
+
.SS "Variables"
|
75
|
+
The most basic tag is the variable. A \fB{{name}}\fR tag in a basic
|
76
|
+
template will try to call the \fBname\fR method on your view. If there is
|
77
|
+
no \fBname\fR method, an exception will be raised.
|
78
|
+
.
|
79
|
+
.P
|
80
|
+
All variables are HTML escaped by default. If you want to return
|
81
|
+
unescaped HTML, use the triple mustache: \fB{{{name}}}\fR.
|
82
|
+
.
|
83
|
+
.P
|
84
|
+
By default a variable "miss" returns an empty string. This can usually
|
85
|
+
be configured in your Mustache library.
|
86
|
+
.
|
87
|
+
.P
|
88
|
+
Template:
|
89
|
+
.
|
90
|
+
.IP "" 4
|
91
|
+
.
|
92
|
+
.nf
|
93
|
+
|
94
|
+
\fB* {{name}}
|
95
|
+
* {{age}}
|
96
|
+
* {{company}}
|
97
|
+
* {{{company}}} \fR
|
98
|
+
.
|
99
|
+
.fi
|
100
|
+
.
|
101
|
+
.IP "" 0
|
102
|
+
.
|
103
|
+
.P
|
104
|
+
Hash:
|
105
|
+
.
|
106
|
+
.IP "" 4
|
107
|
+
.
|
108
|
+
.nf
|
109
|
+
|
110
|
+
\fB{
|
111
|
+
"name": "Chris",
|
112
|
+
"company": "<b>GitHub</b>"
|
113
|
+
} \fR
|
114
|
+
.
|
115
|
+
.fi
|
116
|
+
.
|
117
|
+
.IP "" 0
|
118
|
+
.
|
119
|
+
.P
|
120
|
+
Output:
|
121
|
+
.
|
122
|
+
.IP "" 4
|
123
|
+
.
|
124
|
+
.nf
|
125
|
+
|
126
|
+
\fB* Chris
|
127
|
+
*
|
128
|
+
* <b>GitHub</b>
|
129
|
+
* <b>GitHub</b> \fR
|
130
|
+
.
|
131
|
+
.fi
|
132
|
+
.
|
133
|
+
.IP "" 0
|
134
|
+
.
|
135
|
+
.SS "Boolean Sections"
|
136
|
+
A section begins with a pound and ends with a slash. That is,\fB{{#person}}\fR begins a "person" section while \fB{{/person}}\fR ends it.
|
137
|
+
.
|
138
|
+
.P
|
139
|
+
If the \fBperson\fR key exists and calling it returns false, the HTML
|
140
|
+
between the pound and slash will not be displayed.
|
141
|
+
.
|
142
|
+
.P
|
143
|
+
If the \fBperson\fR method exists and calling it returns true, the HTML
|
144
|
+
between the pound and slash will be rendered and displayed.
|
145
|
+
.
|
146
|
+
.P
|
147
|
+
Template:
|
148
|
+
.
|
149
|
+
.IP "" 4
|
150
|
+
.
|
151
|
+
.nf
|
152
|
+
|
153
|
+
\fB{{#person}}
|
154
|
+
Shown!
|
155
|
+
{{/person}}
|
156
|
+
{{#anything_else}}
|
157
|
+
Never shown!
|
158
|
+
{{/anything_else}} \fR
|
159
|
+
.
|
160
|
+
.fi
|
161
|
+
.
|
162
|
+
.IP "" 0
|
163
|
+
.
|
164
|
+
.P
|
165
|
+
Hash:
|
166
|
+
.
|
167
|
+
.IP "" 4
|
168
|
+
.
|
169
|
+
.nf
|
170
|
+
|
171
|
+
\fB{
|
172
|
+
"person": true
|
173
|
+
} \fR
|
174
|
+
.
|
175
|
+
.fi
|
176
|
+
.
|
177
|
+
.IP "" 0
|
178
|
+
.
|
179
|
+
.P
|
180
|
+
Output:
|
181
|
+
.
|
182
|
+
.IP "" 4
|
183
|
+
.
|
184
|
+
.nf
|
185
|
+
|
186
|
+
\fBShown! \fR
|
187
|
+
.
|
188
|
+
.fi
|
189
|
+
.
|
190
|
+
.IP "" 0
|
191
|
+
.
|
192
|
+
.SS "Enumerable Sections"
|
193
|
+
Enumerable sections are syntactically identical to boolean sections in
|
194
|
+
that they begin with a pound and end with a slash. The difference,
|
195
|
+
however, is in the view: if the method called returns an enumerable,
|
196
|
+
the section is repeated as the enumerable is iterated over.
|
197
|
+
.
|
198
|
+
.P
|
199
|
+
Each item in the enumerable is expected to be a hash which will then
|
200
|
+
become the context of the corresponding iteration. In this way we can
|
201
|
+
construct loops.
|
202
|
+
.
|
203
|
+
.P
|
204
|
+
Template:
|
205
|
+
.
|
206
|
+
.IP "" 4
|
207
|
+
.
|
208
|
+
.nf
|
209
|
+
|
210
|
+
\fB{{#repo}}
|
211
|
+
<b>{{name}}</b>
|
212
|
+
{{/repo}} \fR
|
213
|
+
.
|
214
|
+
.fi
|
215
|
+
.
|
216
|
+
.IP "" 0
|
217
|
+
.
|
218
|
+
.P
|
219
|
+
Hash:
|
220
|
+
.
|
221
|
+
.IP "" 4
|
222
|
+
.
|
223
|
+
.nf
|
224
|
+
|
225
|
+
\fB{
|
226
|
+
"repo": [
|
227
|
+
{ "name": "resque" },
|
228
|
+
{ "name": "hub" },
|
229
|
+
{ "name": "rip" },
|
230
|
+
]
|
231
|
+
} \fR
|
232
|
+
.
|
233
|
+
.fi
|
234
|
+
.
|
235
|
+
.IP "" 0
|
236
|
+
.
|
237
|
+
.P
|
238
|
+
Output:
|
239
|
+
.
|
240
|
+
.IP "" 4
|
241
|
+
.
|
242
|
+
.nf
|
243
|
+
|
244
|
+
\fB<b>resque</b>
|
245
|
+
<b>hub</b>
|
246
|
+
<b>rip</b> \fR
|
247
|
+
.
|
248
|
+
.fi
|
249
|
+
.
|
250
|
+
.IP "" 0
|
251
|
+
.
|
252
|
+
.SS "Comments"
|
253
|
+
Comments begin with a bang and are ignored. The following template:
|
254
|
+
.
|
255
|
+
.IP "" 4
|
256
|
+
.
|
257
|
+
.nf
|
258
|
+
|
259
|
+
\fB<h1>Today{{! ignore me }}.</h1> \fR
|
260
|
+
.
|
261
|
+
.fi
|
262
|
+
.
|
263
|
+
.IP "" 0
|
264
|
+
.
|
265
|
+
.P
|
266
|
+
Will render as follows:
|
267
|
+
.
|
268
|
+
.IP "" 4
|
269
|
+
.
|
270
|
+
.nf
|
271
|
+
|
272
|
+
\fB<h1>Today.</h1> \fR
|
273
|
+
.
|
274
|
+
.fi
|
275
|
+
.
|
276
|
+
.IP "" 0
|
277
|
+
.
|
278
|
+
.SS "Partials"
|
279
|
+
Partials begin with a greater than sign, like \fB{{> box}}\fR.
|
280
|
+
.
|
281
|
+
.P
|
282
|
+
It is useful to think of partials as a "template expansion" \- that is,
|
283
|
+
the actual partial tag will be replaced with the content of the
|
284
|
+
partial. Therefor partials share the current context.
|
285
|
+
.
|
286
|
+
.P
|
287
|
+
For example, this template and partial:
|
288
|
+
.
|
289
|
+
.IP "" 4
|
290
|
+
.
|
291
|
+
.nf
|
292
|
+
|
293
|
+
\fBbase.mustache:
|
294
|
+
<h2>Names</h2>
|
295
|
+
{{# names }}
|
296
|
+
{{> user }}
|
297
|
+
{{/ names }}
|
298
|
+
user.mustache:
|
299
|
+
<strong>{{ name }}</strong>
|
300
|
+
\fR
|
301
|
+
.
|
302
|
+
.fi
|
303
|
+
.
|
304
|
+
.IP "" 0
|
305
|
+
.
|
306
|
+
.P
|
307
|
+
Can be thought of as a single, expanded template:
|
308
|
+
.
|
309
|
+
.IP "" 4
|
310
|
+
.
|
311
|
+
.nf
|
312
|
+
|
313
|
+
\fB<h2>Names</h2>
|
314
|
+
{{# names }}
|
315
|
+
<strong>{{ name }}</strong>
|
316
|
+
{{/ names }} \fR
|
317
|
+
.
|
318
|
+
.fi
|
319
|
+
.
|
320
|
+
.IP "" 0
|
321
|
+
.
|
322
|
+
.SS "Set Delimiter"
|
323
|
+
Set Delimiter tags start with an equal sign and change the tag
|
324
|
+
delimiters from {{ and }} to custom strings.
|
325
|
+
.
|
326
|
+
.P
|
327
|
+
Consider the following contrived example:
|
328
|
+
.
|
329
|
+
.IP "" 4
|
330
|
+
.
|
331
|
+
.nf
|
332
|
+
|
333
|
+
\fB* {{ default_tags }}
|
334
|
+
{{=<% %>=}}
|
335
|
+
* <% erb_style_tags %>
|
336
|
+
<%={{ }}=%>
|
337
|
+
* {{ default_tags_again }} \fR
|
338
|
+
.
|
339
|
+
.fi
|
340
|
+
.
|
341
|
+
.IP "" 0
|
342
|
+
.
|
343
|
+
.P
|
344
|
+
Here we have a list with three items. The first item uses the default
|
345
|
+
tag style, the second uses erb style as defined by the Set Delimiter
|
346
|
+
tag, and the third returns to the default style after yet another Set
|
347
|
+
Delimiter declaration.
|
348
|
+
.
|
349
|
+
.P
|
350
|
+
According to \fIctemplates\fR, this "is useful for languages like TeX, where
|
351
|
+
double\-braces may occur in the text and are awkward to use for
|
352
|
+
markup."
|
353
|
+
.
|
354
|
+
.P
|
355
|
+
Custom delimiters may not contain whitespace or the equals sign.
|
356
|
+
.
|
357
|
+
.SH "COPYRIGHT"
|
358
|
+
Mustache is Copyright (C) 2009 Chris Wanstrath
|
359
|
+
.
|
360
|
+
.P
|
361
|
+
Original CTemplate by Google
|
362
|
+
.
|
363
|
+
.SH "SEE ALSO"
|
364
|
+
mustache(1), mustache(7), gem(1),\fIhttp://defunkt.github.com/mustache/\fR
|
data/man/mustache.5.html
ADDED
@@ -0,0 +1,300 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
5
|
+
<meta name='generator' value='Ron/v0.3'>
|
6
|
+
<title>mustache(5) -- Logic-less templates.</title>
|
7
|
+
<style type='text/css'>
|
8
|
+
body {margin:0}
|
9
|
+
#man, #man code, #man pre, #man tt, #man kbd, #man samp {
|
10
|
+
font-family:consolas,monospace;
|
11
|
+
font-size:16px;
|
12
|
+
line-height:1.3;
|
13
|
+
color:#343331;
|
14
|
+
background:#fff; }
|
15
|
+
#man { max-width:89ex; text-align:justify; margin:0 25px 25px 25px }
|
16
|
+
#man h1, #man h2, #man h3 { color:#232221;clear:left }
|
17
|
+
#man h1 { font-size:28px; margin:15px 0 30px 0; text-align:center }
|
18
|
+
#man h2 { font-size:18px; margin-bottom:0; margin-top:10px; line-height:1.3; }
|
19
|
+
#man h3 { font-size:16px; margin:0 0 0 4ex; }
|
20
|
+
#man p, #man ul, #man ol, #man dl, #man pre { margin:0 0 18px 0; }
|
21
|
+
#man pre {
|
22
|
+
color:#333231;
|
23
|
+
background:#edeceb;
|
24
|
+
padding:5px 7px;
|
25
|
+
margin:0px 0 20px 0;
|
26
|
+
border-left:2ex solid #ddd}
|
27
|
+
#man pre + h2, #man pre + h3 {
|
28
|
+
margin-top:22px;
|
29
|
+
}
|
30
|
+
#man h2 + pre, #man h3 + pre {
|
31
|
+
margin-top:5px;
|
32
|
+
}
|
33
|
+
#man > p, #man > ul, #man > ol, #man > dl, #man > pre { margin-left:8ex; }
|
34
|
+
#man dt { margin:0; clear:left }
|
35
|
+
#man dt.flush { float:left; width:8ex }
|
36
|
+
#man dd { margin:0 0 0 9ex }
|
37
|
+
#man code, #man strong, #man b { font-weight:bold; color:#131211; }
|
38
|
+
#man pre code { font-weight:normal; color:#232221; background:inherit }
|
39
|
+
#man em, var, u {
|
40
|
+
font-style:normal; color:#333231; border-bottom:1px solid #999; }
|
41
|
+
#man h1.man-title { display:none; }
|
42
|
+
#man ol.man, #man ol.man li { margin:2px 0 10px 0; padding:0;
|
43
|
+
float:left; width:33%; list-style-type:none;
|
44
|
+
text-transform:uppercase; font-size:18px; color:#999;
|
45
|
+
letter-spacing:1px;}
|
46
|
+
#man ol.man { width:100%; }
|
47
|
+
#man ol.man li.tl { text-align:left }
|
48
|
+
#man ol.man li.tc { text-align:center;letter-spacing:4px }
|
49
|
+
#man ol.man li.tr { text-align:right }
|
50
|
+
#man ol.man a { color:#999 }
|
51
|
+
#man ol.man a:hover { color:#333231 }
|
52
|
+
</style>
|
53
|
+
</head>
|
54
|
+
<body>
|
55
|
+
<div id='man'>
|
56
|
+
|
57
|
+
<h1 class='man-title'>mustache(5)</h1>
|
58
|
+
|
59
|
+
<ol class='head man'>
|
60
|
+
<li class='tl'>mustache(5)</li>
|
61
|
+
<li class='tc'>Mustache Manual</li>
|
62
|
+
<li class='tr'>mustache(5)</li>
|
63
|
+
</ol>
|
64
|
+
|
65
|
+
<h2 id='NAME'>NAME</h2>
|
66
|
+
<p><code>mustache</code> -- Logic-less templates.</p>
|
67
|
+
<h2>SYNOPSIS</h2>
|
68
|
+
|
69
|
+
<p>A typical Mustache template:</p>
|
70
|
+
|
71
|
+
<pre><code>Hello {{name}}
|
72
|
+
You have just won ${{value}}!
|
73
|
+
{{#in_ca}}
|
74
|
+
Well, ${{taxed_value}}, after taxes.
|
75
|
+
{{/in_ca}}
|
76
|
+
</code></pre>
|
77
|
+
|
78
|
+
<p>Given the following hash:</p>
|
79
|
+
|
80
|
+
<pre><code>{
|
81
|
+
"name": "Chris",
|
82
|
+
"value": 10000,
|
83
|
+
"taxed_value": 10000 - (10000 * 0.4),
|
84
|
+
"in_ca": true
|
85
|
+
}
|
86
|
+
</code></pre>
|
87
|
+
|
88
|
+
<p>Will produce the following:</p>
|
89
|
+
|
90
|
+
<pre><code>Hello Chris
|
91
|
+
You have just won $10000!
|
92
|
+
Well, $6000.0, after taxes.
|
93
|
+
</code></pre>
|
94
|
+
|
95
|
+
<h2>DESCRIPTION</h2>
|
96
|
+
|
97
|
+
<p>Mustache can be used for HTML, config files, source code -
|
98
|
+
anything. It works by expanding tags in a template using values
|
99
|
+
provided in a hash or object.</p>
|
100
|
+
|
101
|
+
<p>We call it "logic-less" because there are no if statements, else
|
102
|
+
clauses, or for loops. Instead there are only tags. Some tags are
|
103
|
+
replaced with a value, some nothing, and others a series of
|
104
|
+
values. This document explains the different types of Mustache tags.</p>
|
105
|
+
|
106
|
+
<h2>TAG TYPES</h2>
|
107
|
+
|
108
|
+
<p>Tags are indicated by the double mustaches. <code>{{name}}</code> is a tag. Let's
|
109
|
+
talk about the different types of tags.</p>
|
110
|
+
|
111
|
+
<h3>Variables</h3>
|
112
|
+
|
113
|
+
<p>The most basic tag is the variable. A <code>{{name}}</code> tag in a basic
|
114
|
+
template will try to call the <code>name</code> method on your view. If there is
|
115
|
+
no <code>name</code> method, an exception will be raised.</p>
|
116
|
+
|
117
|
+
<p>All variables are HTML escaped by default. If you want to return
|
118
|
+
unescaped HTML, use the triple mustache: <code>{{{name}}}</code>.</p>
|
119
|
+
|
120
|
+
<p>By default a variable "miss" returns an empty string. This can usually
|
121
|
+
be configured in your Mustache library.</p>
|
122
|
+
|
123
|
+
<p>Template:</p>
|
124
|
+
|
125
|
+
<pre><code>* {{name}}
|
126
|
+
* {{age}}
|
127
|
+
* {{company}}
|
128
|
+
* {{{company}}}
|
129
|
+
</code></pre>
|
130
|
+
|
131
|
+
<p>Hash:</p>
|
132
|
+
|
133
|
+
<pre><code>{
|
134
|
+
"name": "Chris",
|
135
|
+
"company": "<b>GitHub</b>"
|
136
|
+
}
|
137
|
+
</code></pre>
|
138
|
+
|
139
|
+
<p>Output:</p>
|
140
|
+
|
141
|
+
<pre><code>* Chris
|
142
|
+
*
|
143
|
+
* &lt;b&gt;GitHub&lt;/b&gt;
|
144
|
+
* <b>GitHub</b>
|
145
|
+
</code></pre>
|
146
|
+
|
147
|
+
<h3>Boolean Sections</h3>
|
148
|
+
|
149
|
+
<p>A section begins with a pound and ends with a slash. That is,
|
150
|
+
<code>{{#person}}</code> begins a "person" section while <code>{{/person}}</code> ends it.</p>
|
151
|
+
|
152
|
+
<p>If the <code>person</code> key exists and calling it returns false, the HTML
|
153
|
+
between the pound and slash will not be displayed.</p>
|
154
|
+
|
155
|
+
<p>If the <code>person</code> method exists and calling it returns true, the HTML
|
156
|
+
between the pound and slash will be rendered and displayed.</p>
|
157
|
+
|
158
|
+
<p>Template:</p>
|
159
|
+
|
160
|
+
<pre><code>{{#person}}
|
161
|
+
Shown!
|
162
|
+
{{/person}}
|
163
|
+
{{#anything_else}}
|
164
|
+
Never shown!
|
165
|
+
{{/anything_else}}
|
166
|
+
</code></pre>
|
167
|
+
|
168
|
+
<p>Hash:</p>
|
169
|
+
|
170
|
+
<pre><code>{
|
171
|
+
"person": true
|
172
|
+
}
|
173
|
+
</code></pre>
|
174
|
+
|
175
|
+
<p>Output:</p>
|
176
|
+
|
177
|
+
<pre><code>Shown!
|
178
|
+
</code></pre>
|
179
|
+
|
180
|
+
<h3>Enumerable Sections</h3>
|
181
|
+
|
182
|
+
<p>Enumerable sections are syntactically identical to boolean sections in
|
183
|
+
that they begin with a pound and end with a slash. The difference,
|
184
|
+
however, is in the view: if the method called returns an enumerable,
|
185
|
+
the section is repeated as the enumerable is iterated over.</p>
|
186
|
+
|
187
|
+
<p>Each item in the enumerable is expected to be a hash which will then
|
188
|
+
become the context of the corresponding iteration. In this way we can
|
189
|
+
construct loops.</p>
|
190
|
+
|
191
|
+
<p>Template:</p>
|
192
|
+
|
193
|
+
<pre><code>{{#repo}}
|
194
|
+
<b>{{name}}</b>
|
195
|
+
{{/repo}}
|
196
|
+
</code></pre>
|
197
|
+
|
198
|
+
<p>Hash:</p>
|
199
|
+
|
200
|
+
<pre><code>{
|
201
|
+
"repo": [
|
202
|
+
{ "name": "resque" },
|
203
|
+
{ "name": "hub" },
|
204
|
+
{ "name": "rip" },
|
205
|
+
]
|
206
|
+
}
|
207
|
+
</code></pre>
|
208
|
+
|
209
|
+
<p>Output:</p>
|
210
|
+
|
211
|
+
<pre><code><b>resque</b>
|
212
|
+
<b>hub</b>
|
213
|
+
<b>rip</b>
|
214
|
+
</code></pre>
|
215
|
+
|
216
|
+
<h3>Comments</h3>
|
217
|
+
|
218
|
+
<p>Comments begin with a bang and are ignored. The following template:</p>
|
219
|
+
|
220
|
+
<pre><code><h1>Today{{! ignore me }}.</h1>
|
221
|
+
</code></pre>
|
222
|
+
|
223
|
+
<p>Will render as follows:</p>
|
224
|
+
|
225
|
+
<pre><code><h1>Today.</h1>
|
226
|
+
</code></pre>
|
227
|
+
|
228
|
+
<h3>Partials</h3>
|
229
|
+
|
230
|
+
<p>Partials begin with a greater than sign, like <code>{{> box}}</code>.</p>
|
231
|
+
|
232
|
+
<p>It is useful to think of partials as a "template expansion" - that is,
|
233
|
+
the actual partial tag will be replaced with the content of the
|
234
|
+
partial. Therefor partials share the current context.</p>
|
235
|
+
|
236
|
+
<p>For example, this template and partial:</p>
|
237
|
+
|
238
|
+
<pre><code>base.mustache:
|
239
|
+
<h2>Names</h2>
|
240
|
+
{{# names }}
|
241
|
+
{{> user }}
|
242
|
+
{{/ names }}
|
243
|
+
|
244
|
+
user.mustache:
|
245
|
+
<strong>{{ name }}</strong>
|
246
|
+
</code></pre>
|
247
|
+
|
248
|
+
<p>Can be thought of as a single, expanded template:</p>
|
249
|
+
|
250
|
+
<pre><code><h2>Names</h2>
|
251
|
+
{{# names }}
|
252
|
+
<strong>{{ name }}</strong>
|
253
|
+
{{/ names }}
|
254
|
+
</code></pre>
|
255
|
+
|
256
|
+
<h3>Set Delimiter</h3>
|
257
|
+
|
258
|
+
<p>Set Delimiter tags start with an equal sign and change the tag
|
259
|
+
delimiters from {{ and }} to custom strings.</p>
|
260
|
+
|
261
|
+
<p>Consider the following contrived example:</p>
|
262
|
+
|
263
|
+
<pre><code>* {{ default_tags }}
|
264
|
+
{{=<% %>=}}
|
265
|
+
* <% erb_style_tags %>
|
266
|
+
<%={{ }}=%>
|
267
|
+
* {{ default_tags_again }}
|
268
|
+
</code></pre>
|
269
|
+
|
270
|
+
<p>Here we have a list with three items. The first item uses the default
|
271
|
+
tag style, the second uses erb style as defined by the Set Delimiter
|
272
|
+
tag, and the third returns to the default style after yet another Set
|
273
|
+
Delimiter declaration.</p>
|
274
|
+
|
275
|
+
<p>According to <a href="http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html">ctemplates</a>, this "is useful for languages like TeX, where
|
276
|
+
double-braces may occur in the text and are awkward to use for
|
277
|
+
markup."</p>
|
278
|
+
|
279
|
+
<p>Custom delimiters may not contain whitespace or the equals sign.</p>
|
280
|
+
|
281
|
+
<h2>COPYRIGHT</h2>
|
282
|
+
|
283
|
+
<p>Mustache is Copyright (C) 2009 Chris Wanstrath</p>
|
284
|
+
|
285
|
+
<p>Original CTemplate by Google</p>
|
286
|
+
|
287
|
+
<h2>SEE ALSO</h2>
|
288
|
+
|
289
|
+
<p>mustache(1), mustache(7), gem(1),
|
290
|
+
<a href="http://defunkt.github.com/mustache/">http://defunkt.github.com/mustache/</a></p>
|
291
|
+
|
292
|
+
<ol class='foot man'>
|
293
|
+
<li class='tl'>DEFUNKT</li>
|
294
|
+
<li class='tc'>March 2010</li>
|
295
|
+
<li class='tr'>mustache(5)</li>
|
296
|
+
</ol>
|
297
|
+
|
298
|
+
</div>
|
299
|
+
</body>
|
300
|
+
</html>
|