Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Fixing syntax to correct lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Taka Kojima committed Jul 30, 2012
1 parent d1deac2 commit 28ec144
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
10 changes: 4 additions & 6 deletions index.js
Expand Up @@ -39,9 +39,9 @@ function TemplateError(error) {
}}; }};
} }


function createRenderFunc (code) { function createRenderFunc(code) {
// The compiled render function - this is all we need // The compiled render function - this is all we need
return new Function('_context', '_parents', '_filters', '_', '_ext', [ return new Function('_context', '_parents', '_filters', '_', '_ext', [
'_parents = _parents ? _parents.slice() : [];', '_parents = _parents ? _parents.slice() : [];',
'_context = _context || {};', '_context = _context || {};',
// Prevents circular includes (which will crash node without warning) // Prevents circular includes (which will crash node without warning)
Expand Down Expand Up @@ -94,15 +94,13 @@ function createTemplate(data, id) {


if (code !== false) { if (code !== false) {
render = createRenderFunc(code); render = createRenderFunc(code);
} } else {

else {
render = function (_context, _parents, _filters, _, _ext) { render = function (_context, _parents, _filters, _, _ext) {
template.tokens = tokens; template.tokens = tokens;
code = parser.compile.call(template, null, '', _context); code = parser.compile.call(template, null, '', _context);
var fn = createRenderFunc(code); var fn = createRenderFunc(code);
return fn.call(this, _context, _parents, _filters, _, _ext); return fn.call(this, _context, _parents, _filters, _, _ext);
} };
} }


template.render = function (context, parents) { template.render = function (context, parents) {
Expand Down
4 changes: 2 additions & 2 deletions index.test.js
Expand Up @@ -84,8 +84,8 @@ exports.compileFile = testCase({
r3 = tpl.render({baseTmpl: "extends_base.html"}); r3 = tpl.render({baseTmpl: "extends_base.html"});
r4 = tpl.render({baseTmpl: "extends_base2.html"}); r4 = tpl.render({baseTmpl: "extends_base2.html"});


test.strictEqual(r1,r3, "this should not throw"); test.strictEqual(r1, r3, "rendering the same template with the same context twice, should return identically.");
test.strictEqual(r2,r4, "this should not throw"); test.strictEqual(r2, r4, "rendering the same template with the same context twice, should return identically.");


test.notEqual(r1, r2, "these should not be equal, as they use different base templates."); test.notEqual(r1, r2, "these should not be equal, as they use different base templates.");


Expand Down
8 changes: 3 additions & 5 deletions lib/parser.js
Expand Up @@ -31,7 +31,7 @@ function getArgs(input) {
function getContextVar(varName, context) { function getContextVar(varName, context) {
var a = varName.split("."); var a = varName.split(".");
while (a.length) { while (a.length) {
context = context[a.splice(0,1)[0]]; context = context[a.splice(0, 1)[0]];
} }
return context; return context;
} }
Expand Down Expand Up @@ -325,16 +325,14 @@ exports.compile = function compile(indent, parentBlock, context) {
// Load the parent template // Load the parent template
if (token.name === 'extends') { if (token.name === 'extends') {
filepath = token.args[0]; filepath = token.args[0];

if (!helpers.isStringLiteral(filepath)) { if (!helpers.isStringLiteral(filepath)) {


if (!context) { if (!context) {
extendsHasVar = true; extendsHasVar = true;
return; return;
} }
else { filepath = "\"" + getContextVar(filepath, context) + "\"";
filepath = "\"" + getContextVar(filepath, context) + "\"";
}
} }


if (!helpers.isStringLiteral(filepath) || token.args.length > 1) { if (!helpers.isStringLiteral(filepath) || token.args.length > 1) {
Expand Down

0 comments on commit 28ec144

Please sign in to comment.