From 95d6ca9ada028d9d0de6fec77053473ec64874a8 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 1 Aug 2012 22:16:17 -0700 Subject: [PATCH] Move views before templates in examples --- README.md | 90 +++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 1eb178d..7f9fa98 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,13 @@ All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable. +View: + + { + "name": "Chris", + "company": "GitHub" + } + Template: * {{name}} @@ -74,13 +81,6 @@ Template: * {{{company}}} * {{&company}} -View: - - { - "name": "Chris", - "company": "GitHub" - } - Output: * Chris @@ -92,11 +92,6 @@ Output: JavaScript's dot notation may be used to access keys that are properties of objects in a view. -Template: - - * {{name.first}} {{name.last}} - * {{age}} - View: { @@ -107,6 +102,11 @@ View: "age": "RIP" } +Template: + + * {{name.first}} {{name.last}} + * {{age}} + Output: * Michael Jackson @@ -128,6 +128,12 @@ The behavior of the section is determined by the value of the key. If the `person` key exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered. +View: + + { + "person": false + } + Template: Shown. @@ -135,12 +141,6 @@ Template: Never shown! {{/person}} -View: - - { - "person": false - } - Output: Shown. @@ -154,12 +154,6 @@ When the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections. -Template: - - {{#stooges}} - {{name}} - {{/stooges}} - View: { @@ -170,6 +164,12 @@ View: ] } +Template: + + {{#stooges}} + {{name}} + {{/stooges}} + Output: Moe @@ -179,18 +179,18 @@ Output: When looping over an array of strings, a `.` can be used to refer to the current item in the list. -Template: - - {{#musketeers}} - * {{.}} - {{/musketeers}} - View: { "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"] } +Template: + + {{#musketeers}} + * {{.}} + {{/musketeers}} + Output: * Athos @@ -201,12 +201,6 @@ Output: If the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration. -Template: - - {{#beatles}} - * {{name}} - {{/beatles}} - View: { @@ -221,6 +215,12 @@ View: } } +Template: + + {{#beatles}} + * {{name}} + {{/beatles}} + Output: * John Lennon @@ -235,10 +235,6 @@ literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object. -Template: - - {{#bold}}Hi {{name}}.{{/bold}} - View: { @@ -250,6 +246,10 @@ View: } } +Template: + + {{#bold}}Hi {{name}}.{{/bold}} + Output: Hi Tater. @@ -260,17 +260,17 @@ An inverted section opens with `{{^section}}` instead of `{{#section}}`. The block of an inverted section is rendered only if the value of that section's tag is `null`, `undefined`, `false`, or an empty list. -Template: - - {{#repos}}{{name}}{{/repos}} - {{^repos}}No repos :({{/repos}} - View: { "repos": [] } +Template: + + {{#repos}}{{name}}{{/repos}} + {{^repos}}No repos :({{/repos}} + Output: No repos :(