{% extends someVar %} support. #95

Merged
merged 3 commits into from Aug 3, 2012

Projects

None yet

2 participants

@gigafied
Contributor

Added the option to use context vars when using the extends tag.

The main catch is that we can't cache the render function in cases where we do use a context var with {% extends %}. This is obviously a speed hit, so a disclaimer somewhere saying this is slower than using string literals may be in order.

Further optimizations can be made though. Creating a dictionary of some sort to store render functions based on certain context var values would work.

Taka Kojima added some commits Jul 28, 2012
Taka Kojima {% extends someVar %} support.
Added the option to use context vars when using the `extends` tag.
17a684d
Taka Kojima Adding tests for using extends with context vars d1deac2
@paularmstrong
Owner

Looks good, but can you fix the lint issues?

swig gigafied-master ⚒ make lint
./index.js, line 42, character 27: Unexpected space between 'createRenderFunc' and '('.
function createRenderFunc (code) {
./index.js, line 44, character 4: Expected 'return' at column 5, not column 4.
return new Function('_context', '_parents', '_filters', '_', '_ext', [
./index.js, line 99, character 5: Expected exactly one space between '}' and 'else'.
else {
./index.js, line 99, character 5: Expected 'else' at column 9, not column 5.
else {
./index.js, line 100, character 9: Expected 'render' at column 13, not column 9.
render = function (_context, _parents, _filters, _, _ext) {
./index.js, line 101, character 13: Expected 'template' at column 17, not column 13.
template.tokens = tokens;
./index.js, line 102, character 13: Expected 'code' at column 17, not column 13.
code = parser.compile.call(template, null, '', _context);
./index.js, line 103, character 13: Expected 'var' at column 17, not column 13.
var fn = createRenderFunc(code);
./index.js, line 104, character 13: Expected 'return' at column 17, not column 13.
return fn.call(this, _context, _parents, _filters, _, _ext);
./index.js, line 105, character 9: Expected '}' at column 13, not column 9.
}
./index.js, line 105, character 10: Expected ';' and instead saw '}'.
}
./index.js, line 106, character 5: Expected '}' at column 9, not column 5.
}
./index.test.js, line 87, character 29: Missing space between ',' and 'r3'.
test.strictEqual(r1,r3, "this should not throw");
./index.test.js, line 88, character 29: Missing space between ',' and 'r4'.
test.strictEqual(r2,r4, "this should not throw");
./lib/parser.js, line 34, character 38: Missing space between ',' and '1'.
context = context[a.splice(0,1)[0]];
./lib/parser.js, line 328, character 1: Unexpected '(space)'.

./lib/parser.js, line 333, character 29: Unexpected 'else' after 'return'.
return;
./lib/parser.js, line 335, character 25: Expected exactly one space between '}' and 'else'.
else {
./lib/parser.js, line 335, character 25: Expected 'else' at column 29, not column 25.
else {
./lib/parser.js, line 336, character 29: Expected 'filepath' at column 33, not column 29.
filepath = "\"" + getContextVar(filepath, context) + "\"";
./lib/parser.js, line 337, character 25: Expected '}' at column 29, not column 25.
}
21 errors
make: *** [lint] Error 2
@gigafied
Contributor

Gah, sorry. Fixed.

@paularmstrong
Owner

I didn't really read through the code too much, but it looks good for now!

@paularmstrong paularmstrong merged commit 2670e39 into paularmstrong:master Aug 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment