Skip to content

Commit 09dc771

Browse files
committed
Implement template inheritance (~ partials with parameters)
The implementation follows the spec proposal: mustache/spec#75 which is supported by at least the following Mustache implementations: - hogan.js - mustache.php - mustache.java - GRMustache (Obj-C) and GRMustache.swift (Swift) - Text::Caml (Perl) - hxmustache (Haxe) - MuttonChop (Swift)
1 parent fd2d8ce commit 09dc771

File tree

12 files changed

+351
-107
lines changed

12 files changed

+351
-107
lines changed

bin/test/errors/parsing-errors.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Mismatch between section-start and section-end:
9797
$ mustache foo.json $PROBLEM
9898
Template parse error:
9999
File "foo-bar.mustache", lines 1-2, characters 23-0:
100-
Section mismatch: {{#foo}} is closed by {{/bar}}.
100+
Open/close tag mismatch: {{# foo }} is closed by {{/ bar }}.
101101
[3]
102102
103103
$ PROBLEM=foo-not-closed.mustache
@@ -112,7 +112,7 @@ Mismatch between section-start and section-end:
112112
$ mustache foo.json $PROBLEM
113113
Template parse error:
114114
File "wrong-nesting.mustache", lines 1-2, characters 41-0:
115-
Section mismatch: {{#foo}} is closed by {{/bar}}.
115+
Open/close tag mismatch: {{# foo }} is closed by {{/ bar }}.
116116
[3]
117117
118118
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
{{$header}}{{/header}}
3+
<body>
4+
{{$content}}{{/content}}
5+
</body>
6+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<head>
2+
<title>{{$title}}Default title{{/title}}</title>
3+
</head>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{<base}}
2+
{{$header}}
3+
{{<header}}
4+
{{$title}}My page title{{/title}}
5+
{{/header}}
6+
{{/header}}
7+
{{$content}}
8+
<h1>Hello world</h1>
9+
{{/content}}
10+
{{/base}}

bin/test/inheritance.t/run.t

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$ echo "{}" > data.json
2+
3+
This test is the reference example from the template-inheritance specification:
4+
https://github.com/mustache/spec/pull/75
5+
6+
$ mustache data.json mypage.mustache
7+
<html>
8+
<head>
9+
<title>My page title</title>
10+
</head>
11+
<body>
12+
<h1>Hello world</h1>
13+
</body>
14+
</html>
15+

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Contains the `mustache` command line utility for driving logic-less templates.
2727
ezjsonm
2828
(ounit :with-test)
2929
(menhir (>= 20180703))
30-
(ocaml (>= 4.06))))
30+
(ocaml (>= 4.08))))

0 commit comments

Comments
 (0)