From cb39d246df2c507284244c437612b8f362ed6715 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Mon, 8 Mar 2010 23:50:07 -0800 Subject: [PATCH] throw exception when encountering an unknown pragma --- CHANGES.md | 2 ++ examples/pragma.html | 1 - examples/pragma.js | 3 --- examples/pragma.txt | 1 - examples/unknown_pragma.html | 1 + examples/unknown_pragma.js | 1 + examples/unknown_pragma.txt | 1 + mustache.js | 7 +++++++ 8 files changed, 12 insertions(+), 5 deletions(-) delete mode 100644 examples/pragma.html delete mode 100644 examples/pragma.js delete mode 100644 examples/pragma.txt create mode 100644 examples/unknown_pragma.html create mode 100644 examples/unknown_pragma.js create mode 100644 examples/unknown_pragma.txt diff --git a/CHANGES.md b/CHANGES.md index 5977b4b..7208204 100644 --- a/CHANGES.md +++ b/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) diff --git a/examples/pragma.html b/examples/pragma.html deleted file mode 100644 index ccccc93..0000000 --- a/examples/pragma.html +++ /dev/null @@ -1 +0,0 @@ -{{%PRAGMA}} diff --git a/examples/pragma.js b/examples/pragma.js deleted file mode 100644 index b9eb6e7..0000000 --- a/examples/pragma.js +++ /dev/null @@ -1,3 +0,0 @@ -var pragma = { - foo: 1 -}; diff --git a/examples/pragma.txt b/examples/pragma.txt deleted file mode 100644 index 8b13789..0000000 --- a/examples/pragma.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/examples/unknown_pragma.html b/examples/unknown_pragma.html new file mode 100644 index 0000000..113810d --- /dev/null +++ b/examples/unknown_pragma.html @@ -0,0 +1 @@ +{{%I-HAVE-THE-GREATEST-MUSTACHE}} diff --git a/examples/unknown_pragma.js b/examples/unknown_pragma.js new file mode 100644 index 0000000..68344a5 --- /dev/null +++ b/examples/unknown_pragma.js @@ -0,0 +1 @@ +var unknown_pragma = {}; diff --git a/examples/unknown_pragma.txt b/examples/unknown_pragma.txt new file mode 100644 index 0000000..a34840d --- /dev/null +++ b/examples/unknown_pragma.txt @@ -0,0 +1 @@ +ERROR: This implementation of mustache doesn't understand the 'I-HAVE-THE-GREATEST-MUSTACHE' pragma diff --git a/mustache.js b/mustache.js index 95a68d2..58e6460 100644 --- a/mustache.js +++ b/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("=");