Permalink
Browse files

remove deprecated argument for compile/tags

  • Loading branch information...
1 parent e2cfa13 commit afe9db16cb9887cb41d2c4d1f31d50c37d41d3f1 @paularmstrong committed Oct 20, 2012
Showing with 29 additions and 29 deletions.
  1. +5 −5 docs/custom-tags.md
  2. +1 −1 index.js
  3. +5 −5 lib/parser.js
  4. +3 −3 lib/parser.test.js
  5. +2 −2 lib/tags/autoescape.js
  6. +1 −1 lib/tags/else.js
  7. +2 −2 lib/tags/filter.js
  8. +2 −2 lib/tags/for.js
  9. +2 −2 lib/tags/if.js
  10. +1 −1 lib/tags/import.js
  11. +1 −1 lib/tags/include.js
  12. +2 −2 lib/tags/macro.js
  13. +2 −2 lib/tags/set.js
View
@@ -16,7 +16,7 @@ First, include the helpers.
Define your tag and whether or not it requires an "end" tag:
- exports.mytag = function (indent, parentBlock, parser) {
+ exports.mytag = function (indent, parser) {
return 'output';
};
exports.mytag.ends = true;
@@ -26,15 +26,15 @@ A Really Simple Tag <a name="example" href="#example">#</a>
To parse a swig variable with or without filters into a variable token, eg. `bar` or `foo|lowercase`
- exports.mytag = function (indent, parentBlock, parser) {
+ exports.mytag = function (indent, parser) {
var myArg = parser.parseVariable(this.args[0]);
return 'output';
};
exports.mytag.ends = true;
Use a parsed variable token with `helpers.setVar()` to bind a variable in your current scope into the templates scope. The `setVar` method cleans up variable output, applies filters and escaping for clean output:
- exports.mytag = function (indent, parentBlock, parser) {
+ exports.mytag = function (indent, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = '';
output += helpers.setVar(name, myArg);
@@ -44,7 +44,7 @@ Use a parsed variable token with `helpers.setVar()` to bind a variable in your c
To parse the inner content of a tag for outputting, use `parser.compile.apply(this, [indent, parentBlock])`:
- exports.mytag = function (indent, parentBlock, parser) {
+ exports.mytag = function (indent, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = [];
@@ -86,7 +86,7 @@ To access a third-party library or method that is defined outside of your templa
Once you've added it, your custom tag can reference the `i18next` extension via the `_ext` object:
- exports.trans = function (indent, parentBlock, parser) {
+ exports.trans = function (indent, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = [];
output.push(helpers.setVar('__myArg', myArg));
View
@@ -97,7 +97,7 @@ function createTemplate(data, id) {
} else {
render = function (_context, _parents, _filters, _, _ext) {
template.tokens = tokens;
- code = parser.compile.call(template, '', null, _context);
+ code = parser.compile.call(template, '', _context);
var fn = createRenderFunc(code);
return fn.call(this, _context, _parents, _filters, _, _ext);
};
View
@@ -420,7 +420,7 @@ function precompile(indent, context) {
}
}
-exports.compile = function compile(indent, /* option no longer needed */ deprecated, context, template) {
+exports.compile = function compile(indent, context, template) {
var code = '',
wrappedInMethod,
blockname,
@@ -496,25 +496,25 @@ exports.compile = function compile(indent, /* option no longer needed */ depreca
'\" is not in template block list.');
}
- code += compile.call(template.blocks[token.args[0]], indent + ' ', null, context, template);
+ code += compile.call(template.blocks[token.args[0]], indent + ' ', context, template);
} else if (token.name === 'parent') {
parentBlock = getParentBlock(token);
if (!parentBlock) {
throw new Error('No parent block found for parent tag at line ' +
token.line + '.');
}
- code += compile.call(parentBlock, indent + ' ', null, context);
+ code += compile.call(parentBlock, indent + ' ', context);
} else if (token.hasOwnProperty("compile")) {
if (token.strip.start && token.tokens.length && typeof token.tokens[0] === 'string') {
token.tokens[0] = token.tokens[0].replace(/^\s+/, '');
}
if (token.strip.end && token.tokens.length && typeof _.last(token.tokens) === 'string') {
token.tokens[token.tokens.length - 1] = _.last(token.tokens).replace(/\s+$/, '');
}
- code += token.compile(indent + ' ', null, exports);
+ code += token.compile(indent + ' ', exports);
} else {
- code += compile.call(token, indent + ' ', null, context);
+ code += compile.call(token, indent + ' ', context);
}
}, this);
View
@@ -177,10 +177,10 @@ exports.Tags = testCase({
exports.Whitespace = testCase({
setUp: function (callback) {
var tags = {
- foo: function (indent, parentBlock) {
- return parser.compile.apply(this, [indent + ' ', parentBlock]);
+ foo: function (indent) {
+ return parser.compile.apply(this, [indent + ' ']);
},
- bar: function (indent, parentBlock) {
+ bar: function (indent) {
return '';
}
};
@@ -2,7 +2,7 @@
* autoescape
* Special handling hardcoded into the parser to determine whether variable output should be escaped or not
*/
-module.exports = function (indent, parentBlock, parser) {
- return parser.compile.apply(this, [indent, parentBlock]);
+module.exports = function (indent, parser) {
+ return parser.compile.apply(this, [indent]);
};
module.exports.ends = true;
View
@@ -4,7 +4,7 @@ var helpers = require('../helpers'),
/**
* else
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var last = _.last(this.parent).name,
thisArgs = _.clone(this.args),
ifarg,
View
@@ -4,13 +4,13 @@ var helpers = require('../helpers'),
/**
* filter
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var thisArgs = _.clone(this.args),
name = thisArgs.shift(),
args = (thisArgs.length) ? thisArgs.join(', ') : '',
value = '(function () {\n';
value += ' var _output = "";\n';
- value += parser.compile.apply(this, [indent + ' ', parentBlock]) + '\n';
+ value += parser.compile.apply(this, [indent + ' ']) + '\n';
value += ' return _output;\n';
value += '})()\n';
View
@@ -4,7 +4,7 @@ var helpers = require('../helpers'),
/**
* for
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var thisArgs = _.clone(this.args),
operand1 = thisArgs[0],
operator = thisArgs[1],
@@ -35,7 +35,7 @@ module.exports = function (indent, parentBlock, parser) {
'loop.first = (__loopIndex === 0);\n' +
'loop.last = (__loopIndex === __loopLength - 1);\n' +
'_context["' + operand1 + '"] = __loopIter[loop.key];\n' +
- parser.compile.apply(this, [indent + ' ', parentBlock]);
+ parser.compile.apply(this, [indent + ' ']);
out = '(function () {\n' +
' var loop = {}, __loopKey, __loopIndex = 0, __loopLength = 0, __keys = [],' +
View
@@ -4,7 +4,7 @@ var helpers = require('../helpers'),
/**
* if
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var thisArgs = _.clone(this.args),
args = (helpers.parseIfArgs(thisArgs, parser)),
out = '(function () {\n';
@@ -20,7 +20,7 @@ module.exports = function (indent, parentBlock, parser) {
out += token.value + ' ';
});
out += ') {\n';
- out += parser.compile.apply(this, [indent + ' ', parentBlock]);
+ out += parser.compile.apply(this, [indent + ' ']);
out += '\n}\n';
out += '})();\n';
View
@@ -4,7 +4,7 @@ var helpers = require('../helpers'),
/**
* import
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
if (this.args.length !== 3) {
throw new Error('Import statements require three arguments: {% import [template] as [context] %}.');
}
View
@@ -4,7 +4,7 @@ var helpers = require('../helpers'),
/**
* include
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var args = _.clone(this.args),
template = args.shift(),
context = '_context',
View
@@ -3,7 +3,7 @@ var _ = require('underscore');
/**
* macro
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var thisArgs = _.clone(this.args),
macro = thisArgs.shift(),
args = '',
@@ -15,7 +15,7 @@ module.exports = function (indent, parentBlock, parser) {
out += '_context.' + macro + ' = function (' + args + ') {\n';
out += ' var _output = "";\n';
- out += parser.compile.apply(this, [indent + ' ', parentBlock]);
+ out += parser.compile.apply(this, [indent + ' ']);
out += ' return _output;\n';
out += '};\n';
View
@@ -4,7 +4,7 @@ var helpers = require('../helpers'),
/**
* set
*/
-module.exports = function (indent, parentBlock, parser) {
+module.exports = function (indent, parser) {
var thisArgs = _.clone(this.args),
varname = helpers.escapeVarName(thisArgs.shift(), '_context'),
value;
@@ -23,7 +23,7 @@ module.exports = function (indent, parentBlock, parser) {
return ' ' + varname + ' = ' +
'(function () {\n' +
' var _output;\n' +
- parser.compile.apply({ tokens: [value] }, [indent, parentBlock]) + '\n' +
+ parser.compile.apply({ tokens: [value] }, [indent]) + '\n' +
' return _output;\n' +
'})();\n';
};

0 comments on commit afe9db1

Please sign in to comment.