From 18e529897ab87e734b6d0c1caac14032718c6d27 Mon Sep 17 00:00:00 2001 From: thegrandpoobah Date: Tue, 22 Mar 2011 14:32:26 -0400 Subject: [PATCH] Remove interpreter code path and forward all to_html calls to compile --- mustache.js | 144 +++------------------------------------------------- 1 file changed, 8 insertions(+), 136 deletions(-) diff --git a/mustache.js b/mustache.js index 8a9d85c..22ca95b 100644 --- a/mustache.js +++ b/mustache.js @@ -10,28 +10,18 @@ var Mustache = function() { } ParserException.prototype = {}; - var Renderer = function(send_func, mode) { + var Renderer = function(send_func) { this._escapeCompiledRegex = null; if (!Renderer.TokenizerRegex) { Renderer.TokenizerRegex = this._createTokenizerRegex('{{', '}}'); } this.user_send_func = send_func; - if (mode==='interpreter' || !mode) { - this.commandSet = this.interpreter; - - this.send_func = function(text) { - this.user_send_func(text); - } - } else if (mode==='compiler') { - this.commandSet = this.compiler; - - this.cached_output = []; - this.send_func = function(text) { - this.cached_output.push(text); - } - } else { - throw new ParserException('Unsupported mode.'); + this.commandSet = this.compiler; + + this.cached_output = []; + this.send_func = function(text) { + this.cached_output.push(text); } this.pragmas = {}; @@ -599,110 +589,6 @@ var Mustache = function() { return Object.prototype.toString.call(a) === '[object Array]'; }, - interpreter: { - text: function() { - // in this implementation, rendering text is meaningless - // since the send_func method simply forwards to user_send_func - }, - variable: function(key, contextStack) { - function escapeHTML(str) { - return ('' + str).replace(/&/g,'&') - .replace(//g,'>'); - } - - var result = this.find_in_stack(key, contextStack); - if (result!==undefined) { - this.user_send_func(escapeHTML(result)); - } - }, - unescaped_variable: function(key, contextStack) { - var result = this.find_in_stack(key, contextStack); - if (result!==undefined) { - this.user_send_func(result); - } - }, - partial: function(key, contextStack, partials, openTag, closeTag) { - if (!partials || partials[key] === undefined) { - throw new ParserException('Unknown partial \'' + key + '\''); - } - - var res = this.find_in_stack(key, contextStack); - if (this.is_object(res)) { - contextStack.push(res); - } - - var tokens = this.tokenize(partials[key], openTag, closeTag); - - this.parse(this.createParserContext(tokens, partials, openTag, closeTag), contextStack); - - if (this.is_object(res)) { - contextStack.pop(); - } - }, - section: function(sectionType, fragmentTokens, key, contextStack, partials, openTag, closeTag) { - // by @langalex, support for arrays of strings - var that = this; - function create_context(_context) { - if(that.is_object(_context)) { - return _context; - } else { - var iterator = '.'; - - if(that.pragmas["IMPLICIT-ITERATOR"] && - that.pragmas["IMPLICIT-ITERATOR"].iterator) { - iterator = that.pragmas["IMPLICIT-ITERATOR"].iterator; - } - var ctx = {}; - ctx[iterator] = _context; - return ctx; - } - } - - var value = this.find_in_stack(key, contextStack); - - var tokens; - if (sectionType==='invertedSection') { - if (!value || this.is_array(value) && value.length === 0) { - // false or empty list, render it - this.parse(this.createParserContext(fragmentTokens, partials, openTag, closeTag), contextStack); - } - } else if (sectionType==='section') { - if (this.is_array(value)) { // Enumerable, Let's loop! - for (var i=0, n=value.length; i