-
Notifications
You must be signed in to change notification settings - Fork 25
Hogan-style template inheritance #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7d6b3fb
reimplement and document the handling of standalone tokens
gasche b7e36c3
Implement template inheritance (~ partials with parameters)
gasche 0d905bc
add inheritance specs to the specification testsuite
gasche 7c8b994
document partials with parameters
gasche d21c4d6
test the examples from the manpage
gasche 7c3bc53
indentation tests (currently exhibiting poor results)
gasche 9e4daeb
try harder to indent partial parameters as the user would naturally e…
gasche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <html> | ||
| {{$header}}{{/header}} | ||
| <body> | ||
| {{$content}}{{/content}} | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <head> | ||
| <title>{{$title}}Default title{{/title}}</title> | ||
| </head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| {{<base}} | ||
| {{$header}} | ||
| {{<header}} | ||
| {{$title}}My page title{{/title}} | ||
| {{/header}} | ||
| {{/header}} | ||
| {{$content}} | ||
| <h1>Hello world</h1> | ||
| {{/content}} | ||
| {{/base}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| $ echo "{}" > data.json | ||
|
|
||
| This test is the reference example from the template-inheritance specification: | ||
| https://github.com/mustache/spec/pull/75 | ||
|
|
||
| $ mustache data.json mypage.mustache | ||
| <html> | ||
| <head> | ||
| <title>My page title</title> | ||
| </head> | ||
| <body> | ||
| <h1>Hello world</h1> | ||
| </body> | ||
| </html> | ||
|
|
||
|
|
||
| We also test the indentation of parameter blocks. | ||
|
|
||
| $ mustache data.json test-indent-more.mustache | ||
| <p> | ||
| The test below should be indented in the same way as this line. | ||
| This text is not indented in the source, | ||
| it should be indented naturally in the output. | ||
| </p> | ||
|
|
||
| $ mustache data.json test-indent-less.mustache | ||
| <p> | ||
| The test below should be indented in the same way as this line. | ||
| This text is very indented in the source, | ||
| it should be indented naturally in the output. | ||
| </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| {{<test-indentation}} | ||
| {{$indented-block}} | ||
| This text is very indented in the source, | ||
| it should be indented naturally in the output. | ||
| {{/indented-block}} | ||
| {{/test-indentation}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| {{<test-indentation}} | ||
| {{$indented-block}} | ||
| This text is not indented in the source, | ||
| it should be indented naturally in the output. | ||
| {{/indented-block}} | ||
| {{/test-indentation}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <p> | ||
| The test below should be indented in the same way as this line. | ||
| {{$indented-block}}{{/indented-block}} | ||
| </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| { "name": "OCaml", | ||
| "qualities": [{"name": "simple"}, {"name": "fun"}] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Hello {{name}}! | ||
| Mustache is: | ||
| {{#qualities}} | ||
| - {{name}} | ||
| {{/qualities}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "title": "New Post", | ||
| "content": "Shiny new content." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <html> | ||
| <head> | ||
| <title>{{$page-title}}Default Title{{/page-title}}</title> | ||
| </head> | ||
| <body> | ||
| {{$content}}{{/content}} | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <html> | ||
| <body> | ||
| {{>hello}} | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| {{<page-layout}} | ||
| {{$page-title}}Post: {{title}}{{/page-title}} | ||
| {{$content}} | ||
| <h1>{{title}}</h1> | ||
| <p>{{content}}</p> | ||
| {{/content}} | ||
| {{/page-layout}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| Simple usage: | ||
|
|
||
| $ cat data.json | ||
| { "name": "OCaml", | ||
| "qualities": [{"name": "simple"}, {"name": "fun"}] } | ||
|
|
||
| $ cat hello.mustache | ||
| Hello {{name}}! | ||
| Mustache is: | ||
| {{#qualities}} | ||
| - {{name}} | ||
| {{/qualities}} | ||
|
|
||
| $ mustache data.json hello.mustache | ||
| Hello OCaml! | ||
| Mustache is: | ||
| - simple | ||
| - fun | ||
|
|
||
|
|
||
| Using a partial to include a subpage: | ||
|
|
||
| $ cat page.mustache | ||
| <html> | ||
| <body> | ||
| {{>hello}} | ||
| </body> | ||
| </html> | ||
|
|
||
| $ mustache data.json page.mustache | ||
| <html> | ||
| <body> | ||
| Hello OCaml! | ||
| Mustache is: | ||
| - simple | ||
| - fun | ||
| </body> | ||
| </html> | ||
|
|
||
|
|
||
| Using a partial with parameters to include a layout around a page: | ||
|
|
||
| $ cat new-post.json | ||
| { | ||
| "title": "New Post", | ||
| "content": "Shiny new content." | ||
| } | ||
|
|
||
| $ cat post.mustache | ||
| {{<page-layout}} | ||
| {{$page-title}}Post: {{title}}{{/page-title}} | ||
| {{$content}} | ||
| <h1>{{title}}</h1> | ||
| <p>{{content}}</p> | ||
| {{/content}} | ||
| {{/page-layout}} | ||
|
|
||
| $ cat page-layout.mustache | ||
| <html> | ||
| <head> | ||
| <title>{{$page-title}}Default Title{{/page-title}}</title> | ||
| </head> | ||
| <body> | ||
| {{$content}}{{/content}} | ||
| </body> | ||
| </html> | ||
|
|
||
| $ mustache new-post.json post.mustache | ||
| <html> | ||
| <head> | ||
| <title>Post: New Post</title> | ||
| </head> | ||
| <body> | ||
| <h1>New Post</h1> | ||
| <p>Shiny new content.</p> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this style not apply to variables? E.g.
{{$ foo }}..{{/ foo}}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, I just added test cases for
{{$foo}}and{{<foo}}. Feel free to recommend improvements to the wording.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, what I meant was that
pp_partial_paramisn't consistent with this printing style. It's still printing{{$foo}}instead of{{$ foo }}.