Skip to content

Commit c8da066

Browse files
committed
document partials with parameters
1 parent 27a89aa commit c8da066

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ let rendered =
2727
Mustache.render tmpl json
2828
```
2929

30-
Spec compliance
31-
-----------
30+
Supported template language
31+
---------------------------
32+
33+
ocaml-mustache accepts the whole Mustache template language, except:
34+
- it does not support setting delimiter tags to something else than '{{' and '}}'.
35+
- it does not support lambdas inside the provided data
3236

33-
ocaml-mustache complies¹ to the latest [mustache specification](https://github.com/mustache/spec/tree/v1.1.3), and is automatically tested against it.
37+
It is automatically tested against the latest
38+
[mustache specification testsuite](https://github.com/mustache/spec/tree/v1.1.3).
3439

35-
¹: except for lambdas and set delimiters tags.
40+
ocaml-mustache also supports template inheritance / partials with parameters,
41+
tested against the [semi-official specification](https://github.com/mustache/spec/pull/75).
3642

3743
Todo/Wish List
3844
-----------

bin/mustache_cli.ml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ let manpage = Cmdliner.[
8686
(leftmost $(b,-I) option) has precedence, and the current working directory has precedence
8787
over include directories.";
8888

89+
`S "TEMPLATE INHERITANCE / PARTIALS WITH PARAMETERS";
90+
91+
`P "$(i,ocaml-mustache) supports a common extension to the original Mustache specification,
92+
called 'template inheritance' or 'parent partials', or here 'partials with parameters'.
93+
In addition to usual partials '{{>foo}}', which include a partial template, one can use
94+
the syntax '{{<bar}} {{\\$param1}}...{{/param1}} {{\\$param2}}...{{/param2}} {{/bar}}' to
95+
pass parameters to the included partial template. Inside this included template, parameters
96+
are used as '{{\\$param}}...{{/param}}', with the inner content being used by default
97+
if this parameter was not specified by the caller.";
98+
99+
`P "This is typically used to define page layouts that are wrapped 'around' the current template.
100+
See our EXAMPLES.";
101+
89102
`S Manpage.s_examples;
90103
`Pre {|
91104
## Simple usage.
@@ -108,7 +121,7 @@ Mustache is:
108121
- fun
109122

110123

111-
## Using a partial to include a subpage; see $(b,PARTIALS).
124+
## Including a subpage; see $(b,PARTIALS).
112125

113126
\$ cat page.mustache
114127
<html>
@@ -125,6 +138,47 @@ Mustache is:
125138
- simple
126139
- fun
127140
</body>
141+
</html>
142+
143+
144+
## Including a layount around a page; see $(b,PARTIALS WITH PARAMETERS).
145+
146+
\$ cat new-post.json
147+
{
148+
"title": "New Post",
149+
"authors": "Foo and Bar",
150+
"date": "today",
151+
"content": "Shiny new content."
152+
}
153+
154+
\$ cat post.mustache
155+
{{<post-layout}}
156+
{{\$page-title}}Post: {{title}}{{/page-title}}
157+
{{\$content}}
158+
<h1>{{title}}</h1>
159+
<p>{{content}}</p>
160+
{{/content}}
161+
{{/post-layout}}
162+
163+
\$ cat post-layout.mustache
164+
<html>
165+
<head>
166+
<title>{{\$page-title}}Default Title{{/page-title}}</title>
167+
</head>
168+
<body>
169+
{{\$content}}{{/content}}
170+
</body>
171+
</html>
172+
173+
\$ $(tname) new-post.json post.mustache
174+
<html>
175+
<head>
176+
<title>Post: New Post</title>
177+
</head>
178+
<body>
179+
<h1>New Post</h1>
180+
<p>Shiny new content.</p>
181+
</body>
128182
</html>|};
129183

130184
`S "CONFORMING TO";
@@ -136,6 +190,9 @@ Mustache is:
136190
`I ("Mustache specification testsuite",
137191
"https://github.com/mustache/spec");
138192

193+
`I ("Semi-official specification of PARTIALS WITH PARAMETERS",
194+
"https://github.com/mustache/spec/pull/75");
195+
139196
`S "REPORTING BUGS";
140197
`P "Report bugs on https://github.com/rgrinberg/ocaml-mustache/issues";
141198
]

0 commit comments

Comments
 (0)