diff --git a/examples/array_of_strings.html b/examples/array_of_strings.html index dcd1c92..ab058c4 100644 --- a/examples/array_of_strings.html +++ b/examples/array_of_strings.html @@ -1,2 +1,2 @@ -{{%JSTACHE-ENABLE-STRING-ARRAYS}} +{{%IMPLICIT-ITERATOR}} {{#array_of_strings}} {{.}} {{/array_of_strings}} \ No newline at end of file diff --git a/examples/array_of_strings_options.html b/examples/array_of_strings_options.html new file mode 100644 index 0000000..87fbf5e --- /dev/null +++ b/examples/array_of_strings_options.html @@ -0,0 +1,2 @@ +{{%IMPLICIT-ITERATOR iterator=rob}} +{{#array_of_strings_options}} {{rob}} {{/array_of_strings_options}} \ No newline at end of file diff --git a/examples/array_of_strings_options.js b/examples/array_of_strings_options.js new file mode 100644 index 0000000..2e29adf --- /dev/null +++ b/examples/array_of_strings_options.js @@ -0,0 +1 @@ +var array_of_strings_options = {array_of_strings_options: ['hello', 'world']}; diff --git a/examples/array_of_strings_options.txt b/examples/array_of_strings_options.txt new file mode 100644 index 0000000..4a1f475 --- /dev/null +++ b/examples/array_of_strings_options.txt @@ -0,0 +1 @@ +hello world diff --git a/mustache.js b/mustache.js index e785424..534e336 100644 --- a/mustache.js +++ b/mustache.js @@ -55,9 +55,14 @@ var Mustache = function() { } var that = this; - var regex = new RegExp(this.otag + "%(.+)" + this.ctag); - return template.replace(regex, function(match, pragma) { - that.pragmas[pragma] = true; + var regex = new RegExp(this.otag + "%([A-Z0-9-]+) ?([a-z0-9]+=[a-z0-9]+)?" + + this.ctag); + return template.replace(regex, function(match, pragma, options) { + that.pragmas[pragma] = {}; + if(options) { + var opts = options.split("="); + that.pragmas[pragma][opts[0]] = opts[1]; + } return ""; // ignore unknown pragmas silently }); @@ -219,8 +224,11 @@ var Mustache = function() { create_context: function(_context) { if(this.is_object(_context)) { return _context; - } else if(this.pragmas["JSTACHE-ENABLE-STRING-ARRAYS"]) { - return {'.': _context}; + } else if(this.pragmas["IMPLICIT-ITERATOR"]) { + var iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator || "."; + var ctx = {}; + ctx[iterator] = _context + return ctx; } },