From afe9db16cb9887cb41d2c4d1f31d50c37d41d3f1 Mon Sep 17 00:00:00 2001 From: Paul Armstrong Date: Sat, 20 Oct 2012 14:18:24 -0700 Subject: [PATCH] remove deprecated argument for compile/tags --- docs/custom-tags.md | 10 +++++----- index.js | 2 +- lib/parser.js | 10 +++++----- lib/parser.test.js | 6 +++--- lib/tags/autoescape.js | 4 ++-- lib/tags/else.js | 2 +- lib/tags/filter.js | 4 ++-- lib/tags/for.js | 4 ++-- lib/tags/if.js | 4 ++-- lib/tags/import.js | 2 +- lib/tags/include.js | 2 +- lib/tags/macro.js | 4 ++-- lib/tags/set.js | 4 ++-- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/custom-tags.md b/docs/custom-tags.md index 797dcf2d..eb2e0861 100644 --- a/docs/custom-tags.md +++ b/docs/custom-tags.md @@ -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,7 +26,7 @@ A Really Simple Tag # 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'; }; @@ -34,7 +34,7 @@ To parse a swig variable with or without filters into a variable token, eg. `bar 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)); diff --git a/index.js b/index.js index 3a50022d..c0ced33e 100644 --- a/index.js +++ b/index.js @@ -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); }; diff --git a/lib/parser.js b/lib/parser.js index 83c46e32..f3f60229 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -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,7 +496,7 @@ 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) { @@ -504,7 +504,7 @@ exports.compile = function compile(indent, /* option no longer needed */ depreca 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+/, ''); @@ -512,9 +512,9 @@ exports.compile = function compile(indent, /* option no longer needed */ depreca 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); diff --git a/lib/parser.test.js b/lib/parser.test.js index 7ec22cf9..b071dbf6 100644 --- a/lib/parser.test.js +++ b/lib/parser.test.js @@ -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 ''; } }; diff --git a/lib/tags/autoescape.js b/lib/tags/autoescape.js index 1d9c25cb..9b3a6a82 100644 --- a/lib/tags/autoescape.js +++ b/lib/tags/autoescape.js @@ -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; diff --git a/lib/tags/else.js b/lib/tags/else.js index 4e84efc7..da9cdefd 100644 --- a/lib/tags/else.js +++ b/lib/tags/else.js @@ -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, diff --git a/lib/tags/filter.js b/lib/tags/filter.js index c34b762b..1add24bb 100644 --- a/lib/tags/filter.js +++ b/lib/tags/filter.js @@ -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'; diff --git a/lib/tags/for.js b/lib/tags/for.js index 871ee29b..78094196 100644 --- a/lib/tags/for.js +++ b/lib/tags/for.js @@ -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 = [],' + diff --git a/lib/tags/if.js b/lib/tags/if.js index 19cc07ef..b1acf47e 100644 --- a/lib/tags/if.js +++ b/lib/tags/if.js @@ -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'; diff --git a/lib/tags/import.js b/lib/tags/import.js index 54ae440c..f6a2fff3 100644 --- a/lib/tags/import.js +++ b/lib/tags/import.js @@ -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] %}.'); } diff --git a/lib/tags/include.js b/lib/tags/include.js index 982d4db0..f41261f2 100644 --- a/lib/tags/include.js +++ b/lib/tags/include.js @@ -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', diff --git a/lib/tags/macro.js b/lib/tags/macro.js index 9eb3ae61..a7f7de18 100644 --- a/lib/tags/macro.js +++ b/lib/tags/macro.js @@ -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'; diff --git a/lib/tags/set.js b/lib/tags/set.js index 6bd67202..2761aad1 100644 --- a/lib/tags/set.js +++ b/lib/tags/set.js @@ -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'; };