From 90bc5a9a84d32b55035ce04cb3fb936a4e0cc224 Mon Sep 17 00:00:00 2001 From: Ben Cherry Date: Fri, 3 Dec 2010 14:35:50 -0800 Subject: [PATCH] clean up some logic --- mustache.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mustache.js b/mustache.js index aa2a1d4..78c0574 100644 --- a/mustache.js +++ b/mustache.js @@ -40,28 +40,24 @@ var Mustache = function() { context['_mode'] = this.pragmas['TRANSLATION-HINT']['mode']; } + // get the pragmas together template = this.render_pragmas(template); + // handle all translations template = this.render_i18n(template, context, partials); + // render the template var html = this.render_section(template, context, partials); - if (html === template) { - if (in_recursion) { - return this.render_tags(html, context, partials, true); - } + // render_section did not find any sections, we still need to render the tags + if (html === false) { + html = this.render_tags(template, context, partials, in_recursion); + } - this.render_tags(html, context, partials, false); + if (in_recursion) { + return html; } else { - if(in_recursion) { - return html; - } else { - var lines = html.split("\n"); - for (var i = 0; i < lines.length; i++) { - this.send(lines[i]); - } - return; - } + this.sendLines(html); } }, @@ -74,6 +70,15 @@ var Mustache = function() { } }, + sendLines: function(text) { + if (text) { + var lines = text.split("\n"); + for (var i = 0; i < lines.length; i++) { + this.send(lines[i]); + } + } + }, + /* Looks for %PRAGMAS */ @@ -142,7 +147,8 @@ var Mustache = function() { */ render_section: function(template, context, partials) { if(!this.includes("#", template) && !this.includes("^", template)) { - return template; + // did not render anything, there were no sections + return false; } var that = this;