Преглед изворни кода

allow using sections as context. Patch by dpree.

tags/0.3.0
Jan Lehnardt пре 16 година
родитељ
комит
2085b5f5a0
6 измењених фајлова са 61 додато и 0 уклоњено
  1. +2
    -0
      CHANGES.md
  2. +34
    -0
      README.md
  3. +9
    -0
      examples/section_as_context.html
  4. +7
    -0
      examples/section_as_context.js
  5. +6
    -0
      examples/section_as_context.txt
  6. +3
    -0
      mustache.js

+ 2
- 0
CHANGES.md Прегледај датотеку

@@ -1,9 +1,11 @@
# mustache.js Changes

## 0.3.0 (??-??-????)
* Use sections to dereference subcontexts.
* Added higher order sections.



## 0.2.3 (28-03-2010)

* Better error message for missing partials.


+ 34
- 0
README.md Прегледај датотеку

@@ -115,6 +115,40 @@ implement caching, filters (like syntax highlighting), etc.

You can use `this.name` to access the attribute `name` from your view.

### Dereferencing Section

If you have a nested object structure in your view, it can sometimes be easier
to use sections like this:

var objects = {
a_object: {
title: 'this is an object',
description: 'one of its attributes is a list',
a_list: [{label: 'listitem1'}, {label: 'listitem2'}]
}
};

This is our template:

{{#a_object}}
<h1>{{title}}</h1>
<p>{{description}}</p>
<ul>
{{#a_list}}
<li>{{label}}</li>
{{/a_list}}
</ul>
{{/a_object}}

Here is the result:

<h1>this is an object</h1>
<p>one of its attributes is a list</p>
<ul>
<li>listitem1</li>
<li>listitem2</li>
</ul>


### View Partials



+ 9
- 0
examples/section_as_context.html Прегледај датотеку

@@ -0,0 +1,9 @@
{{#a_object}}
<h1>{{title}}</h1>
<p>{{description}}</p>
<ul>
{{#a_list}}
<li>{{label}}</li>
{{/a_list}}
</ul>
{{/a_object}}

+ 7
- 0
examples/section_as_context.js Прегледај датотеку

@@ -0,0 +1,7 @@
var section_as_context = {
a_object: {
title: 'this is an object',
description: 'one of its attributes is a list',
a_list: [{label: 'listitem1'}, {label: 'listitem2'}]
}
};

+ 6
- 0
examples/section_as_context.txt Прегледај датотеку

@@ -0,0 +1,6 @@
<h1>this is an object</h1>
<p>one of its attributes is a list</p>
<ul>
<li>listitem1</li>
<li>listitem2</li>
</ul>

+ 3
- 0
mustache.js Прегледај датотеку

@@ -109,6 +109,9 @@ var Mustache = function() {
return that.render(content, that.merge(context,
that.create_context(row)), partials, true);
}).join("");
} else if(that.is_object(value)) { // Object, Use it as subcontext!
return that.render(content,
that.merge(context, that.create_context(value)), partials, true);
} else if(typeof value === "function") {
// higher order section
return value.call(context, content, function(text) {


Loading…
Откажи
Сачувај