| @@ -1,9 +1,11 @@ | |||||
| # mustache.js Changes | # mustache.js Changes | ||||
| ## 0.3.0 (??-??-????) | ## 0.3.0 (??-??-????) | ||||
| * Use sections to dereference subcontexts. | |||||
| * Added higher order sections. | * Added higher order sections. | ||||
| ## 0.2.3 (28-03-2010) | ## 0.2.3 (28-03-2010) | ||||
| * Better error message for missing partials. | * Better error message for missing partials. | ||||
| @@ -115,6 +115,40 @@ implement caching, filters (like syntax highlighting), etc. | |||||
| You can use `this.name` to access the attribute `name` from your view. | 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 | ### View Partials | ||||
| @@ -109,6 +109,9 @@ var Mustache = function() { | |||||
| return that.render(content, that.merge(context, | return that.render(content, that.merge(context, | ||||
| that.create_context(row)), partials, true); | that.create_context(row)), partials, true); | ||||
| }).join(""); | }).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") { | } else if(typeof value === "function") { | ||||
| // higher order section | // higher order section | ||||
| return value.call(context, content, function(text) { | return value.call(context, content, function(text) { | ||||