| 1 |
mustache(1) -- Mustache processor |
| 2 |
================================= |
| 3 |
|
| 4 |
## SYNOPSIS |
| 5 |
|
| 6 |
mustache <YAML> <FILE> |
| 7 |
mustache --compile <FILE> |
| 8 |
mustache --tokens <FILE> |
| 9 |
|
| 10 |
|
| 11 |
## DESCRIPTION |
| 12 |
|
| 13 |
Mustache is a logic-less templating system for HTML, config files, |
| 14 |
anything. |
| 15 |
|
| 16 |
The `mustache` command processes a Mustache template preceded by YAML |
| 17 |
frontmatter from standard input and prints one or more documents to |
| 18 |
standard output. |
| 19 |
|
| 20 |
YAML frontmatter begins with `---` on a single line, followed by YAML, |
| 21 |
ending with another `---` on a single line, e.g. |
| 22 |
|
| 23 |
--- |
| 24 |
names: [ {name: chris}, {name: mark}, {name: scott} ] |
| 25 |
--- |
| 26 |
|
| 27 |
If you are unfamiliar with YAML, it is a superset of JSON. Valid JSON |
| 28 |
should work fine. |
| 29 |
|
| 30 |
After the frontmatter should come any valid Mustache template. See |
| 31 |
mustache(5) for an overview of Mustache templates. |
| 32 |
|
| 33 |
For example: |
| 34 |
|
| 35 |
{{#names}} |
| 36 |
Hi {{name}}! |
| 37 |
{{/names}} |
| 38 |
|
| 39 |
Now let's combine them. |
| 40 |
|
| 41 |
$ cat data.yml |
| 42 |
--- |
| 43 |
names: [ {name: chris}, {name: mark}, {name: scott} ] |
| 44 |
--- |
| 45 |
|
| 46 |
$ cat template.mustache |
| 47 |
{{#names}} |
| 48 |
Hi {{name}}! |
| 49 |
{{/names}} |
| 50 |
|
| 51 |
$ mustache data.yml template.mustache |
| 52 |
Hi chris! |
| 53 |
Hi mark! |
| 54 |
Hi scott! |
| 55 |
|
| 56 |
If you provide multiple YAML documents (as delimited by `---`), your |
| 57 |
template will be rendered multiple times. Like a mail merge. |
| 58 |
|
| 59 |
For example: |
| 60 |
|
| 61 |
$ cat data.yml |
| 62 |
--- |
| 63 |
name: chris |
| 64 |
--- |
| 65 |
name: mark |
| 66 |
--- |
| 67 |
name: scott |
| 68 |
--- |
| 69 |
|
| 70 |
$ cat template.mustache |
| 71 |
Hi {{name}}! |
| 72 |
|
| 73 |
$ mustache data.yml template.mustache |
| 74 |
Hi chris! |
| 75 |
Hi mark! |
| 76 |
Hi scott! |
| 77 |
|
| 78 |
## OPTIONS |
| 79 |
|
| 80 |
By default `mustache` will try to render a Mustache template using the |
| 81 |
YAML frontmatter you provide. It can do a few other things, however. |
| 82 |
|
| 83 |
* `-c`, `--compile`: |
| 84 |
Print the compiled Ruby version of a given template. This is the |
| 85 |
code that is actually used when rendering a template into a |
| 86 |
string. Useful for debugging but only if you are familiar with |
| 87 |
Mustache's internals. |
| 88 |
|
| 89 |
* `-t`, `--tokens`: |
| 90 |
Print the tokenized form of a given Mustache template. This can be |
| 91 |
used to understand how Mustache parses a template. The tokens are |
| 92 |
handed to a generator which compiles them into a Ruby |
| 93 |
string. Syntax errors and confused tags, therefore, can probably be |
| 94 |
identified by examining the tokens produced. |
| 95 |
|
| 96 |
|
| 97 |
## INSTALLATION |
| 98 |
|
| 99 |
If you have RubyGems installed: |
| 100 |
|
| 101 |
gem install mustache |
| 102 |
|
| 103 |
|
| 104 |
## EXAMPLES |
| 105 |
|
| 106 |
$ mustache data.yml template.mustache |
| 107 |
$ cat data.yml | mustache - template.mustache |
| 108 |
$ mustache -c template.mustache |
| 109 |
$ cat <<data | ruby mustache - template.mustache |
| 110 |
--- |
| 111 |
name: Bob |
| 112 |
age: 30 |
| 113 |
--- |
| 114 |
data |
| 115 |
|
| 116 |
|
| 117 |
## COPYRIGHT |
| 118 |
|
| 119 |
Mustache is Copyright (C) 2009 Chris Wanstrath |
| 120 |
|
| 121 |
Original CTemplate by Google |
| 122 |
|
| 123 |
|
| 124 |
## SEE ALSO |
| 125 |
|
| 126 |
mustache(5), gem(1), |
| 127 |
<http://mustache.github.io/> |