Skip to content

Commit 7c8b994

Browse files
committed
document partials with parameters
1 parent 0d905bc commit 7c8b994

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
@@ -36,12 +36,18 @@ let rendered =
3636
exit 2
3737
```
3838

39-
Spec compliance
40-
-----------
39+
Supported template language
40+
---------------------------
41+
42+
ocaml-mustache accepts the whole Mustache template language, except:
43+
- it does not support setting delimiter tags to something else than '{{' and '}}'.
44+
- it does not support lambdas inside the provided data
4145

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

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

4652
Todo/Wish List
4753
-----------

bin/mustache_cli.ml

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

153+
`S "TEMPLATE INHERITANCE / PARTIALS WITH PARAMETERS";
154+
155+
`P "$(i,ocaml-mustache) supports a common extension to the original Mustache specification,
156+
called 'template inheritance' or 'parent partials', or here 'partials with parameters'.
157+
In addition to usual partials '{{>foo}}', which include a partial template, one can use
158+
the syntax '{{<bar}} {{\\$param1}}...{{/param1}} {{\\$param2}}...{{/param2}} {{/bar}}' to
159+
pass parameters to the included partial template. Inside this included template, parameters
160+
are used as '{{\\$param}}...{{/param}}', with the inner content being used by default
161+
if this parameter was not specified by the caller.";
162+
163+
`P "This is typically used to define page layouts that are wrapped 'around' the current template.
164+
See our EXAMPLES.";
165+
153166
`S Manpage.s_examples;
154167
`Pre {|
155168
## Simple usage.
@@ -172,7 +185,7 @@ Mustache is:
172185
- fun
173186

174187

175-
## Using a partial to include a subpage; see $(b,PARTIALS).
188+
## Including a subpage; see $(b,PARTIALS).
176189

177190
\$ cat page.mustache
178191
<html>
@@ -189,6 +202,47 @@ Mustache is:
189202
- simple
190203
- fun
191204
</body>
205+
</html>
206+
207+
208+
## Including a layount around a page; see $(b,PARTIALS WITH PARAMETERS).
209+
210+
\$ cat new-post.json
211+
{
212+
"title": "New Post",
213+
"authors": "Foo and Bar",
214+
"date": "today",
215+
"content": "Shiny new content."
216+
}
217+
218+
\$ cat post.mustache
219+
{{<post-layout}}
220+
{{\$page-title}}Post: {{title}}{{/page-title}}
221+
{{\$content}}
222+
<h1>{{title}}</h1>
223+
<p>{{content}}</p>
224+
{{/content}}
225+
{{/post-layout}}
226+
227+
\$ cat post-layout.mustache
228+
<html>
229+
<head>
230+
<title>{{\$page-title}}Default Title{{/page-title}}</title>
231+
</head>
232+
<body>
233+
{{\$content}}{{/content}}
234+
</body>
235+
</html>
236+
237+
\$ $(tname) new-post.json post.mustache
238+
<html>
239+
<head>
240+
<title>Post: New Post</title>
241+
</head>
242+
<body>
243+
<h1>New Post</h1>
244+
<p>Shiny new content.</p>
245+
</body>
192246
</html>|};
193247

194248
`S "CONFORMING TO";
@@ -200,6 +254,9 @@ Mustache is:
200254
`I ("Mustache specification testsuite",
201255
"https://github.com/mustache/spec");
202256

257+
`I ("Semi-official specification of PARTIALS WITH PARAMETERS",
258+
"https://github.com/mustache/spec/pull/75");
259+
203260
`S "REPORTING BUGS";
204261
`P "Report bugs on https://github.com/rgrinberg/ocaml-mustache/issues";
205262
]

0 commit comments

Comments
 (0)