From 738de0bcaeb6e6a413b8c05ae031bd1c99b82a32 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sun, 28 Feb 2010 19:30:06 -0800 Subject: [PATCH] Parse pragmas only once --- mustache.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mustache.js b/mustache.js index 5f6a601..8d94d58 100644 --- a/mustache.js +++ b/mustache.js @@ -17,6 +17,7 @@ var Mustache = function() { ctag: "}}", pragmas: {}, buffer: [], + pragmas_parsed: false, render: function(template, context, partials, in_recursion) { // fail fast @@ -32,7 +33,9 @@ var Mustache = function() { this.buffer = []; } - template = this.render_pragmas(template); + if(!this.pragmas_parsed) { + template = this.render_pragmas(template); + } var html = this.render_section(template, context, partials); if(in_recursion) { return this.render_tags(html, context, partials, in_recursion); @@ -54,6 +57,7 @@ var Mustache = function() { Looks for %PRAGMAS */ render_pragmas: function(template) { + this.pragmas_parsed = true; // no pragmas if(template.indexOf(this.otag + "%") == -1) { return template;