Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing syntax to correct lint errors

  • Loading branch information...
commit 28ec144ab2de38ad8ee6dd291244d5cb3a92b97d 1 parent d1deac2
Taka Kojima authored
Showing with 9 additions and 13 deletions.
  1. +4 −6 index.js
  2. +2 −2 index.test.js
  3. +3 −5 lib/parser.js
View
10 index.js
@@ -39,9 +39,9 @@ function TemplateError(error) {
}};
}
-function createRenderFunc (code) {
+function createRenderFunc(code) {
// 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() : [];',
'_context = _context || {};',
// Prevents circular includes (which will crash node without warning)
@@ -94,15 +94,13 @@ function createTemplate(data, id) {
if (code !== false) {
render = createRenderFunc(code);
- }
-
- else {
+ } else {
render = function (_context, _parents, _filters, _, _ext) {
template.tokens = tokens;
code = parser.compile.call(template, null, '', _context);
var fn = createRenderFunc(code);
return fn.call(this, _context, _parents, _filters, _, _ext);
- }
+ };
}
template.render = function (context, parents) {
View
4 index.test.js
@@ -84,8 +84,8 @@ exports.compileFile = testCase({
r3 = tpl.render({baseTmpl: "extends_base.html"});
r4 = tpl.render({baseTmpl: "extends_base2.html"});
- test.strictEqual(r1,r3, "this should not throw");
- test.strictEqual(r2,r4, "this should not throw");
+ test.strictEqual(r1, r3, "rendering the same template with the same context twice, should return identically.");
+ 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.");
View
8 lib/parser.js
@@ -31,7 +31,7 @@ function getArgs(input) {
function getContextVar(varName, context) {
var a = varName.split(".");
while (a.length) {
- context = context[a.splice(0,1)[0]];
+ context = context[a.splice(0, 1)[0]];
}
return context;
}
@@ -325,16 +325,14 @@ exports.compile = function compile(indent, parentBlock, context) {
// Load the parent template
if (token.name === 'extends') {
filepath = token.args[0];
-
+
if (!helpers.isStringLiteral(filepath)) {
if (!context) {
extendsHasVar = true;
return;
}
- else {
- filepath = "\"" + getContextVar(filepath, context) + "\"";
- }
+ filepath = "\"" + getContextVar(filepath, context) + "\"";
}
if (!helpers.isStringLiteral(filepath) || token.args.length > 1) {
Please sign in to comment.
Something went wrong with that request. Please try again.