ソースを参照

add pragma options, rename pragma according to mustache

tags/0.2.2
Jan Lehnardt 16年前
コミット
17630842a1
5個のファイルの変更18行の追加6行の削除
  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 ファイルの表示

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

+ 2
- 0
examples/array_of_strings_options.html ファイルの表示

@@ -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 ファイルの表示

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

+ 1
- 0
examples/array_of_strings_options.txt ファイルの表示

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

+ 13
- 5
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;
}
},



読み込み中…
キャンセル
保存