From 5c086428384c8dc31e34226eb1179d17f26090e7 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Tue, 1 Jun 2010 16:40:37 +0200 Subject: [PATCH] Make IMPLICIT ITERATORS a first class feature. Closes #39. --- examples/array_of_partials_implicit_partial.html | 1 - examples/array_of_strings.html | 1 - examples/array_partial.2.html | 2 -- examples/array_partial.txt | 2 -- mustache.js | 7 +++++-- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/array_of_partials_implicit_partial.html b/examples/array_of_partials_implicit_partial.html index 11537e9..1af6d68 100644 --- a/examples/array_of_partials_implicit_partial.html +++ b/examples/array_of_partials_implicit_partial.html @@ -1,5 +1,4 @@ Here is some stuff! -{{%IMPLICIT-ITERATOR}} {{#numbers}} {{>partial}} {{/numbers}} diff --git a/examples/array_of_strings.html b/examples/array_of_strings.html index ab058c4..38fa5ab 100644 --- a/examples/array_of_strings.html +++ b/examples/array_of_strings.html @@ -1,2 +1 @@ -{{%IMPLICIT-ITERATOR}} {{#array_of_strings}} {{.}} {{/array_of_strings}} \ No newline at end of file diff --git a/examples/array_partial.2.html b/examples/array_partial.2.html index 80d1d09..c2ea36c 100644 --- a/examples/array_partial.2.html +++ b/examples/array_partial.2.html @@ -1,6 +1,4 @@ Here's a non-sense array of values - -{{%IMPLICIT-ITERATOR}} {{#array}} {{.}} {{/array}} \ No newline at end of file diff --git a/examples/array_partial.txt b/examples/array_partial.txt index a604ac2..fa87c28 100644 --- a/examples/array_partial.txt +++ b/examples/array_partial.txt @@ -1,6 +1,4 @@ Here's a non-sense array of values - - 1 2 3 diff --git a/mustache.js b/mustache.js index be1d7e6..4b0a43e 100644 --- a/mustache.js +++ b/mustache.js @@ -260,8 +260,11 @@ var Mustache = function() { create_context: function(_context) { if(this.is_object(_context)) { return _context; - } else if(this.pragmas["IMPLICIT-ITERATOR"]) { - var iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator || "."; + } else { + var iterator = "."; + if(this.pragmas["IMPLICIT-ITERATOR"]) { + iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator; + } var ctx = {}; ctx[iterator] = _context; return ctx;