diff --git a/mustache.js b/mustache.js index fed6bde..f4578c8 100644 --- a/mustache.js +++ b/mustache.js @@ -212,11 +212,11 @@ var Mustache = (function(undefined) { return undefined; } - function get_variable_name(parserContext, token, prefix, postfix) { + function get_variable_name(state, token, prefix, postfix) { var fragment = token .substring( - parserContext.openTag.length + (prefix ? 1 : 0) - , token.length - parserContext.closeTag.length - (postfix ? 1 : 0) + state.openTag.length + (prefix ? 1 : 0) + , token.length - state.closeTag.length - (postfix ? 1 : 0) ); if (String.prototype.trim) { @@ -226,7 +226,7 @@ var Mustache = (function(undefined) { } } - function interpolate(parserContext, token, escape) { + function interpolate(state, token, escape) { function escapeHTML(str) { return str.replace(/&/g,'&') .replace(/ 0 && - parserContext.section.child_sections[parserContext.section.child_sections.length-1] === variable) { + if (state.section.child_sections.length > 0 && + state.section.child_sections[state.section.child_sections.length-1] === variable) { - parserContext.section.child_sections.pop(); - parserContext.section.template_buffer.push(token); - } else if (parserContext.section.variable===variable) { - section(parserContext); - delete parserContext.section; - parserContext.state = 'normal'; + state.section.child_sections.pop(); + state.section.template_buffer.push(token); + } else if (state.section.variable===variable) { + section(state); + delete state.section; + state.state = 'normal'; } else { - throw new Error('Unexpected section end tag. Expected: ' + parserContext.section.variable); + throw new Error('Unexpected section end tag. Expected: ' + state.section.variable); } } - function parse(parserContext, noReturn) { + function parse(state, noReturn) { var n, token; - for (n = parserContext.tokens.length;parserContext.cursor': // partial - partial(parserContext, token); + partial(state, token); break; case '=': // set delimiter change - change_delimiter(parserContext, token); + change_delimiter(state, token); break; default: // escaped variable - interpolate(parserContext, token); + interpolate(state, token); break; } } else { // plain jane text - parserContext.send_code_func(function(view, send_func) { send_func(token); }); + state.send_code_func(function(view, send_func) { send_func(token); }); } } - , 'scan_section': function(parserContext, token) { - if (token.indexOf(parserContext.openTag)===0) { - switch (token.charAt(parserContext.openTag.length)) { + , 'scan_section': function(state, token) { + if (token.indexOf(state.openTag)===0) { + switch (token.charAt(state.openTag.length)) { case '!': // comments // comments are just discarded, nothing to do break; case '#': // section - begin_section(parserContext, token, false); + begin_section(state, token, false); break; case '^': // inverted section - begin_section(parserContext, token, true); + begin_section(state, token, true); break; case '/': // end section - end_section(parserContext, token); + end_section(state, token); break; case '=': // set delimiter change - change_delimiter(parserContext, token); + change_delimiter(state, token); break; default: // all others - parserContext.section.template_buffer.push(token); + state.section.template_buffer.push(token); break; } } else { - parserContext.section.template_buffer.push(token); + state.section.template_buffer.push(token); } } }