Просмотр исходного кода

throw exception when encountering an unknown pragma

tags/0.2.3
Jan Lehnardt 16 лет назад
Родитель
Сommit
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.
* Added more robust type detection.
* Parse pragmas only once.
* Throw exception when encountering an unknown pragma.


## 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: {},
buffer: [],
pragmas_parsed: false,
pragmas_implemented: {
"IMPLICIT-ITERATOR": true
},

render: function(template, context, partials, in_recursion) {
// fail fast
@@ -68,6 +71,10 @@ var Mustache = function() {
var regex = new RegExp(this.otag + "%([\\w_-]+) ?([\\w]+=[\\w]+)?"
+ this.ctag);
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] = {};
if(options) {
var opts = options.split("=");


Загрузка…
Отмена
Сохранить