Explorar el Código

add pragma options, rename pragma according to mustache

tags/0.2.2
Jan Lehnardt hace 16 años
padre
commit
17630842a1
Se han modificado 5 ficheros con 18 adiciones y 6 borrados
  1. +1
    -1
      examples/array_of_strings.html
  2. +2
    -0
      examples/array_of_strings_options.html
  3. +1
    -0
      examples/array_of_strings_options.js
  4. +1
    -0
      examples/array_of_strings_options.txt
  5. +13
    -5
      mustache.js

+ 1
- 1
examples/array_of_strings.html Ver fichero

@@ -1,2 +1,2 @@
{{%JSTACHE-ENABLE-STRING-ARRAYS}}
{{%IMPLICIT-ITERATOR}}
{{#array_of_strings}} {{.}} {{/array_of_strings}}

+ 2
- 0
examples/array_of_strings_options.html Ver fichero

@@ -0,0 +1,2 @@
{{%IMPLICIT-ITERATOR iterator=rob}}
{{#array_of_strings_options}} {{rob}} {{/array_of_strings_options}}

+ 1
- 0
examples/array_of_strings_options.js Ver fichero

@@ -0,0 +1 @@
var array_of_strings_options = {array_of_strings_options: ['hello', 'world']};

+ 1
- 0
examples/array_of_strings_options.txt Ver fichero

@@ -0,0 +1 @@
hello world

+ 13
- 5
mustache.js Ver fichero

@@ -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;
}
},



Cargando…
Cancelar
Guardar