mustache 1.1.1 → 1.1.3

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/man/mustache.5.html CHANGED
@@ -1,8 +1,8 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
- <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
4
+ <meta http-equiv='content-type' content='text/html;charset=utf8'>
5
+ <meta name='generator' content='Ronn-NG/v0.9.1 (http://github.com/apjanke/ronn-ng/tree/0.9.1)'>
6
6
  <title>mustache(5) - Logic-less templates.</title>
7
7
  <style type='text/css' media='all'>
8
8
  /* style: man */
@@ -67,11 +67,12 @@
67
67
  <li class='tr'>mustache(5)</li>
68
68
  </ol>
69
69
 
70
- <h2 id="NAME">NAME</h2>
70
+
71
+
72
+ <h2 id="NAME">NAME</h2>
71
73
  <p class="man-name">
72
74
  <code>mustache</code> - <span class="man-whatis">Logic-less templates.</span>
73
75
  </p>
74
-
75
76
  <h2 id="SYNOPSIS">SYNOPSIS</h2>
76
77
 
77
78
  <p>A typical Mustache template:</p>
@@ -111,6 +112,10 @@ clauses, or for loops. Instead there are only tags. Some tags are
111
112
  replaced with a value, some nothing, and others a series of
112
113
  values. This document explains the different types of Mustache tags.</p>
113
114
 
115
+ <p>The Mustache language has a <a href="https://github.com/mustache/spec">formal specification</a>. The current
116
+ manpage reflects version 1.3.0 of the specification, including the
117
+ official-but-optional extensions for lambdas and inheritance.</p>
118
+
114
119
  <h2 id="TAG-TYPES">TAG TYPES</h2>
115
120
 
116
121
  <p>Tags are indicated by the double mustaches. <code>{{person}}</code> is a tag, as
@@ -159,15 +164,121 @@ supports raising an exception in this situation, for instance.</p>
159
164
  * &lt;b&gt;GitHub&lt;/b&gt;
160
165
  </code></pre>
161
166
 
167
+ <p><strong>Dotted Names</strong></p>
168
+
169
+ <p>If the <code>name</code> contains dots, it is split on the dots to obtain multiple
170
+ keys. The first key is looked up in the context as described above. If it
171
+ is found, the next key is looked up within the previous result. This is
172
+ repeated until a key is not found or until the last key is found. The
173
+ final result is interpolated as above.</p>
174
+
175
+ <p>Template:</p>
176
+
177
+ <pre><code>* {{client.name}}
178
+ * {{age}}
179
+ * {{client.company.name}}
180
+ * {{{company.name}}}
181
+ </code></pre>
182
+
183
+ <p>Hash:</p>
184
+
185
+ <pre><code>{
186
+ "client": {
187
+ "name": "Chris &amp; Friends",
188
+ "age": 50
189
+ },
190
+ "company": {
191
+ "name": "&lt;b&gt;GitHub&lt;/b&gt;"
192
+ }
193
+ }
194
+ </code></pre>
195
+
196
+ <p>Output:</p>
197
+
198
+ <pre><code>* Chris &amp;amp; Friends
199
+ *
200
+ *
201
+ * &lt;b&gt;GitHub&lt;/b&gt;
202
+ </code></pre>
203
+
204
+ <p><strong>Implicit Iterator</strong></p>
205
+
206
+ <p>As a special case, if the <code>name</code> consists of only a dot and nothing else,
207
+ the value that is the current context is interpolated as a whole. This
208
+ is especially useful if the parent context is a list; see <strong>Sections</strong>
209
+ below.</p>
210
+
211
+ <p>Template:</p>
212
+
213
+ <pre><code>* {{.}}
214
+ </code></pre>
215
+
216
+ <p>Current context:</p>
217
+
218
+ <pre><code>"Hello!"
219
+ </code></pre>
220
+
221
+ <p>Output:</p>
222
+
223
+ <pre><code>* Hello!
224
+ </code></pre>
225
+
226
+ <p><strong>Lambdas</strong></p>
227
+
228
+ <p>If any value found during the lookup is a callable object, such as a
229
+ function or lambda, this object will be invoked with zero arguments. The
230
+ value that is returned is then used instead of the callable object itself.</p>
231
+
232
+ <p>An <strong>optional</strong> part of the specification states that if the final key in
233
+ the <code>name</code> is a lambda that returns a string, then that string should be
234
+ rendered as a Mustache template before interpolation. It will be rendered
235
+ using the default delimiters (see <strong>Set Delimiter</strong> below) against the
236
+ current context.</p>
237
+
238
+ <p>Template:</p>
239
+
240
+ <pre><code>* {{time.hour}}
241
+ * {{today}}
242
+ </code></pre>
243
+
244
+ <p>Hash:</p>
245
+
246
+ <pre><code>{
247
+ "year": 1970,
248
+ "month": 1,
249
+ "day": 1,
250
+ "time": function() {
251
+ return {
252
+ "hour": 0,
253
+ "minute": 0,
254
+ "second": 0
255
+ }
256
+ },
257
+ "today": function() {
258
+ return "{{year}}-{{month}}-{{day}}"
259
+ }
260
+ }
261
+ </code></pre>
262
+
263
+ <p>Output:</p>
264
+
265
+ <pre><code>* 0
266
+ * 1970-1-1
267
+ </code></pre>
268
+
162
269
  <h3 id="Sections">Sections</h3>
163
270
 
164
271
  <p>Sections render blocks of text zero or more times, depending on the
165
272
  value of the key in the current context.</p>
166
273
 
274
+ <p>Lookup of dotted names works in the same way as with variables, except for
275
+ slightly different treatment of lambdas. More on this below.</p>
276
+
167
277
  <p>A section begins with a pound and ends with a slash. That is,
168
278
  <code>{{#person}}</code> begins a "person" section while <code>{{/person}}</code> ends it.</p>
169
279
 
170
- <p>The behavior of the section is determined by the value of the key.</p>
280
+ <p>The behavior of the section is determined by the final value of the key
281
+ lookup.</p>
171
282
 
172
283
  <p><strong>False Values or Empty Lists</strong></p>
173
284
 
@@ -196,7 +307,7 @@ list, the HTML between the pound and slash will not be displayed.</p>
196
307
 
197
308
  <p><strong>Non-Empty Lists</strong></p>
198
309
 
199
- <p>If the <code>person</code> key exists and has a non-false value, the HTML between
310
+ <p>If the <code>repo</code> key exists and has a non-false value, the HTML between
200
311
  the pound and slash will be rendered and displayed one or more times.</p>
201
312
 
202
313
  <p>When the value is a non-empty list, the text in the block will be
@@ -224,34 +335,59 @@ loop over collections.</p>
224
335
 
225
336
  <p>Output:</p>
226
337
 
227
- <pre><code>&lt;b&gt;resque&lt;/b&gt;
228
- &lt;b&gt;hub&lt;/b&gt;
229
- &lt;b&gt;rip&lt;/b&gt;
338
+ <pre><code> &lt;b&gt;resque&lt;/b&gt;
339
+ &lt;b&gt;hub&lt;/b&gt;
340
+ &lt;b&gt;rip&lt;/b&gt;
341
+ </code></pre>
342
+
343
+ <p>The same effect as above can be obtained without nested objects, by using
344
+ the implicit iterator (see <strong>Variables</strong> above).</p>
345
+
346
+ <p>Template:</p>
347
+
348
+ <pre><code>{{#repo}}
349
+ &lt;b&gt;{{.}}&lt;/b&gt;
350
+ {{/repo}}
351
+ </code></pre>
352
+
353
+ <p>Hash:</p>
354
+
355
+ <pre><code>{
356
+ "repo": ["resque", "hub", "rip"]
357
+ }
358
+ </code></pre>
359
+
360
+ <p>Output:</p>
361
+
362
+ <pre><code> &lt;b&gt;resque&lt;/b&gt;
363
+ &lt;b&gt;hub&lt;/b&gt;
364
+ &lt;b&gt;rip&lt;/b&gt;
230
365
  </code></pre>
231
366
 
232
367
  <p><strong>Lambdas</strong></p>
233
368
 
234
- <p>When the value is a callable object, such as a function or lambda, the
235
- object will be invoked and passed the block of text. The text passed
236
- is the literal block, unrendered. <code>{{tags}}</code> will not have been expanded
237
- - the lambda should do that on its own. In this way you can implement
238
- filters or caching.</p>
369
+ <p>When any value found during the lookup is a callable object, such as a
370
+ function or lambda, the object will be invoked and passed the block of
371
+ text. The text passed is the literal block, unrendered. <code>{{tags}}</code> will
372
+ not have been expanded.</p>
373
+
374
+ <p>An <strong>optional</strong> part of the specification states that if the final key in
375
+ the <code>name</code> is a lambda that returns a string, then that string replaces
376
+ the content of the section. It will be rendered using the same delimiters
377
+ (see <strong>Set Delimiter</strong> below) as the original section content. In this way
378
+ you can implement filters or caching.</p>
239
379
 
240
380
  <p>Template:</p>
241
381
 
242
- <pre><code>{{#wrapped}}
243
- {{name}} is awesome.
244
- {{/wrapped}}
382
+ <pre><code>{{#wrapped}}{{name}} is awesome.{{/wrapped}}
245
383
  </code></pre>
246
384
 
247
385
  <p>Hash:</p>
248
386
 
249
387
  <pre><code>{
250
388
  "name": "Willy",
251
- "wrapped": function() {
252
- return function(text, render) {
253
- return "&lt;b&gt;" + render(text) + "&lt;/b&gt;"
254
- }
389
+ "wrapped": function(text) {
390
+ return "&lt;b&gt;" + text + "&lt;/b&gt;"
255
391
  }
256
392
  }
257
393
  </code></pre>
@@ -282,7 +418,7 @@ context for a single rendering of the block.</p>
282
418
 
283
419
  <p>Output:</p>
284
420
 
285
- <pre><code>Hi Jon!
421
+ <pre><code> Hi Jon!
286
422
  </code></pre>
287
423
 
288
424
  <h3 id="Inverted-Sections">Inverted Sections</h3>
@@ -315,7 +451,7 @@ if the key doesn't exist, is false, or is an empty list.</p>
315
451
 
316
452
  <p>Output:</p>
317
453
 
318
- <pre><code>No repos :(
454
+ <pre><code> No repos :(
319
455
  </code></pre>
320
456
 
321
457
  <h3 id="Comments">Comments</h3>
@@ -376,6 +512,147 @@ user.mustache:
376
512
  {{/names}}
377
513
  </code></pre>
378
514
 
515
+ <p><strong>Dynamic Names</strong></p>
516
+
517
+ <p>Partials can be loaded dynamically at runtime using Dynamic Names; an
518
+ <strong>optional</strong> part of the Mustache specification which allows to dynamically
519
+ determine a tag's content at runtime.</p>
520
+
521
+ <p>Dynamic Names consists of an asterisk, followed by a dotted name which follows
522
+ the same notation and the same resolution as in an variable tag. That is
523
+ <code>{{&gt;*dynamic}}</code>. It can be thought as the following <strong>hypothetical</strong> tag
524
+ (which is <strong>not allowed</strong>!): <code>{{&gt;{{dynamic}}}}</code>.</p>
525
+
526
+ <p>Templates:</p>
527
+
528
+ <pre><code>main.mustache:
529
+ Hello {{&gt;*dynamic}}
530
+
531
+ world.template:
532
+ everyone!
533
+ </code></pre>
534
+
535
+ <p>Hash:</p>
536
+
537
+ <pre><code>{
538
+ "dynamic": "world"
539
+ }
540
+ </code></pre>
541
+
542
+ <p>Output:</p>
543
+
544
+ <pre><code>Hello everyone!
545
+ </code></pre>
546
+
547
+ <h3 id="Blocks">Blocks</h3>
548
+
549
+ <p>A block begins with a dollar and ends with a slash. That is, <code>{{$title}}</code>
550
+ begins a "title" block and <code>{{/title}}</code> ends it.</p>
551
+
552
+ <p>Blocks mark parts of the template that may be overridden. This can be done
553
+ with a block of the same name within a parent section in the calling
554
+ template (see <strong>Parents</strong> below). If not overridden, the contents of a
555
+ block render just as if the <code>{{$title}}</code> and <code>{{/title}}</code> tags weren't
556
+ there.</p>
557
+
558
+ <p>Blocks could be thought of as template parameters or as inline partials
559
+ that may be passed to another template. They are part of the optional
560
+ inheritance extension.</p>
561
+
562
+ <p>Template <code>article.mustache</code>:</p>
563
+
564
+ <pre><code>&lt;h1&gt;{{$title}}The News of Today{{/title}}&lt;/h1&gt;
565
+ {{$body}}
566
+ &lt;p&gt;Nothing special happened.&lt;/p&gt;
567
+ {{/body}}
568
+ </code></pre>
569
+
570
+ <p>Output:</p>
571
+
572
+ <pre><code>&lt;h1&gt;The News of Today&lt;/h1&gt;
573
+ &lt;p&gt;Nothing special happened.&lt;/p&gt;
574
+ </code></pre>
575
+
576
+ <h3 id="Parents">Parents</h3>
577
+
578
+ <p>A parent begins with a less than sign and ends with a slash. That is,
579
+ <code>{{&lt;article}}</code> begins an "article" parent and <code>{{/article}}</code> ends it.</p>
580
+
581
+ <p>Like an <code>{{&gt;article}}</code> partial, a parent lets you expand another template
582
+ inside the current one. Unlike a partial, a parent also lets you override
583
+ blocks of the other template.</p>
584
+
585
+ <p>Blocks within a parent can again be overridden by another including
586
+ template. Other content within a parent is ignored, like comments.</p>
587
+
588
+ <p>Template:</p>
589
+
590
+ <pre><code>{{&lt;article}}
591
+ Never shown
592
+ {{$body}}
593
+ {{#headlines}}
594
+ &lt;p&gt;{{.}}&lt;/p&gt;
595
+ {{/headlines}}
596
+ {{/body}}
597
+ {{/article}}
598
+
599
+ {{&lt;article}}
600
+ {{$title}}Yesterday{{/title}}
601
+ {{/article}}
602
+ </code></pre>
603
+
604
+ <p>Hash:</p>
605
+
606
+ <pre><code>{
607
+ "headlines": [
608
+ "A pug's handler grew mustaches.",
609
+ "What an exciting day!"
610
+ ]
611
+ }
612
+ </code></pre>
613
+
614
+ <p>Output, assuming the <code>article.mustache</code> from before:</p>
615
+
616
+ <pre><code>&lt;h1&gt;The News of Today&lt;/h1&gt;
617
+ &lt;p&gt;A pug's handler grew mustaches.&lt;/p&gt;
618
+ &lt;p&gt;What an exciting day!&lt;/p&gt;
619
+
620
+ &lt;h1&gt;Yesterday&lt;/h1&gt;
621
+ &lt;p&gt;Nothing special happened.&lt;/p&gt;
622
+ </code></pre>
623
+
624
+ <p><strong>Dynamic Names</strong></p>
625
+
626
+ <p>Some mustache implementations may allow the use of Dynamic Names in
627
+ parent tags, similar to dynamic names in partials. Here's an example of
628
+ how Dynamic Names in parent tags work.</p>
629
+
630
+ <p>Templates:</p>
631
+
632
+ <pre><code>{{!normal.mustache}}
633
+ {{$text}}Here goes nothing.{{/text}}
634
+
635
+ {{!bold.mustache}}
636
+ &lt;b&gt;{{$text}}Here also goes nothing but it's bold.{{/text}}&lt;/b&gt;
637
+
638
+ {{!dynamic.mustache}}
639
+ {{&lt;*dynamic}}
640
+ {{$text}}Hello World!{{/text}}
641
+ {{/*dynamic}}
642
+ </code></pre>
643
+
644
+ <p>Hash:</p>
645
+
646
+ <pre><code>{
647
+ "dynamic": "bold"
648
+ }
649
+ </code></pre>
650
+
651
+ <p>Output:</p>
652
+
653
+ <pre><code>&lt;b&gt;Hello World!&lt;/b&gt;
654
+ </code></pre>
655
+
379
656
  <h3 id="Set-Delimiter">Set Delimiter</h3>
380
657
 
381
658
  <p>Set Delimiter tags start with an equal sign and change the tag
@@ -384,9 +661,9 @@ delimiters from <code>{{</code> and <code>}}</code> to custom strings.</p>
384
661
  <p>Consider the following contrived example:</p>
385
662
 
386
663
  <pre><code>* {{default_tags}}
387
- {{=&lt;% %>=}}
388
- * &lt;% erb_style_tags %>
389
- &lt;%={{ }}=%>
664
+ {{=&lt;% %&gt;=}}
665
+ * &lt;% erb_style_tags %&gt;
666
+ &lt;%={{ }}=%&gt;
390
667
  * {{ default_tags_again }}
391
668
  </code></pre>
392
669
 
@@ -395,7 +672,7 @@ tag style, the second uses erb style as defined by the Set Delimiter
395
672
  tag, and the third returns to the default style after yet another Set
396
673
  Delimiter declaration.</p>
397
674
 
398
- <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
675
+ <p>According to <a href="http://goog-ctemplate.sourceforge.net/doc/howto.html">ctemplates</a>, this "is useful for languages like TeX, where
399
676
  double-braces may occur in the text and are awkward to use for
400
677
  markup."</p>
401
678
 
@@ -409,13 +686,12 @@ markup."</p>
409
686
 
410
687
  <h2 id="SEE-ALSO">SEE ALSO</h2>
411
688
 
412
- <p><a class="man-ref" href="mustache.1.ronn.html">mustache<span class="s">(1)</span></a>,
689
+ <p><a class="man-ref" href="mustache.1.ron.html">mustache<span class="s">(1)</span></a>,
413
690
  <a href="http://mustache.github.io/" data-bare-link="true">http://mustache.github.io/</a></p>
414
691
 
415
-
416
692
  <ol class='man-decor man-foot man foot'>
417
693
  <li class='tl'>DEFUNKT</li>
418
- <li class='tc'>November 2016</li>
694
+ <li class='tc'>September 2022</li>
419
695
  <li class='tr'>mustache(5)</li>
420
696
  </ol>
421
697