瀏覽代碼

throw exception when encountering an unknown pragma

tags/0.2.3
Jan Lehnardt 16 年之前
父節點
當前提交
cb39d246df
共有 8 個文件被更改,包括 12 次插入5 次删除
  1. +2
    -0
      CHANGES.md
  2. +0
    -1
      examples/pragma.html
  3. +0
    -3
      examples/pragma.js
  4. +0
    -1
      examples/pragma.txt
  5. +1
    -0
      examples/unknown_pragma.html
  6. +1
    -0
      examples/unknown_pragma.js
  7. +1
    -0
      examples/unknown_pragma.txt
  8. +7
    -0
      mustache.js

+ 2
- 0
CHANGES.md 查看文件

@@ -5,6 +5,8 @@
* Better error message for missing partials. * Better error message for missing partials.
* Added more robust type detection. * Added more robust type detection.
* Parse pragmas only once. * Parse pragmas only once.
* Throw exception when encountering an unknown pragma.



## 0.2.2 (11-02-2010) ## 0.2.2 (11-02-2010)




+ 0
- 1
examples/pragma.html 查看文件

@@ -1 +0,0 @@
{{%PRAGMA}}

+ 0
- 3
examples/pragma.js 查看文件

@@ -1,3 +0,0 @@
var pragma = {
foo: 1
};

+ 0
- 1
examples/pragma.txt 查看文件

@@ -1 +0,0 @@


+ 1
- 0
examples/unknown_pragma.html 查看文件

@@ -0,0 +1 @@
{{%I-HAVE-THE-GREATEST-MUSTACHE}}

+ 1
- 0
examples/unknown_pragma.js 查看文件

@@ -0,0 +1 @@
var unknown_pragma = {};

+ 1
- 0
examples/unknown_pragma.txt 查看文件

@@ -0,0 +1 @@
ERROR: This implementation of mustache doesn't understand the 'I-HAVE-THE-GREATEST-MUSTACHE' pragma

+ 7
- 0
mustache.js 查看文件

@@ -18,6 +18,9 @@ var Mustache = function() {
pragmas: {}, pragmas: {},
buffer: [], buffer: [],
pragmas_parsed: false, pragmas_parsed: false,
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},


render: function(template, context, partials, in_recursion) { render: function(template, context, partials, in_recursion) {
// fail fast // fail fast
@@ -68,6 +71,10 @@ var Mustache = function() {
var regex = new RegExp(this.otag + "%([\\w_-]+) ?([\\w]+=[\\w]+)?" var regex = new RegExp(this.otag + "%([\\w_-]+) ?([\\w]+=[\\w]+)?"
+ this.ctag); + this.ctag);
return template.replace(regex, function(match, pragma, options) { return template.replace(regex, function(match, pragma, options) {
if(!that.pragmas_implemented[pragma]) {
throw({message: "This implementation of mustache doesn't understand the '"
+ pragma + "' pragma"});
}
that.pragmas[pragma] = {}; that.pragmas[pragma] = {};
if(options) { if(options) {
var opts = options.split("="); var opts = options.split("=");


Loading…
取消
儲存