From cae229cc6ae334ea2212b165aa7c03b1a7d43dce Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Wed, 7 May 2014 14:52:12 -0600 Subject: [PATCH] Added support for addBeforeCode and addAfterCode to all nodes --- compiler/Node.js | 24 ++++++++++++++++++++++++ taglibs/core/TagHandlerNode.js | 21 --------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/compiler/Node.js b/compiler/Node.js index 2714a9df8..244f0bf59 100644 --- a/compiler/Node.js +++ b/compiler/Node.js @@ -37,6 +37,8 @@ function Node(nodeType) { this.prefixMappings = {}; this.transformersApplied = {}; this.properties = {}; + this.beforeCode = []; + this.afterCode = []; } } @@ -359,8 +361,24 @@ Node.prototype = { setStripExpression: function (stripExpression) { this.stripExpression = stripExpression; }, + + addBeforeCode: function (code) { + this.beforeCode.push(code); + }, + addAfterCode: function (code) { + this.afterCode.push(code); + }, + generateCode: function (template) { this.compiler = template.compiler; + + if (this.beforeCode.length) { + this.beforeCode.forEach(function (code) { + template.indent().code(code).code('\n'); + }); + } + + var preserveWhitespace = this.isPreserveWhitespace(); if (preserveWhitespace == null) { preserveWhitespace = template.options.preserveWhitespace; @@ -409,6 +427,12 @@ Node.prototype = { } catch (e) { throw createError(new Error('Unable to generate code for node ' + this + ' at position [' + this.getPosition() + ']. Exception: ' + e), e); } + + if (this.afterCode.length) { + this.afterCode.forEach(function (code) { + template.indent().code(code).code('\n'); + }); + } }, isPreserveWhitespace: function () { return this.preserveWhitespace; diff --git a/taglibs/core/TagHandlerNode.js b/taglibs/core/TagHandlerNode.js index ea539ab12..d1a9ad1dc 100644 --- a/taglibs/core/TagHandlerNode.js +++ b/taglibs/core/TagHandlerNode.js @@ -63,8 +63,6 @@ function TagHandlerNode(tag) { } this.tag = tag; this.dynamicAttributes = null; - this.preInvokeCode = []; - this.postInvokeCode = []; this.inputExpression = null; } TagHandlerNode.convertNode = function (node, tag) { @@ -81,12 +79,6 @@ TagHandlerNode.prototype = { setDynamicAttributesProperty: function(name) { this.dynamicAttributesProperty = name; }, - addPreInvokeCode: function (code) { - this.preInvokeCode.push(code); - }, - addPostInvokeCode: function (code) { - this.postInvokeCode.push(code); - }, setInputExpression: function (expression) { this.inputExpression = expression; }, @@ -133,13 +125,6 @@ TagHandlerNode.prototype = { } variableNames.push(varName); }, this); - if (_this.preInvokeCode.length) { - _this.preInvokeCode.forEach(function (code) { - template.indent().code(code).code('\n'); - }); - } - - template.contextHelperMethodCall('t', function () { template.code('\n').indent(function () { @@ -166,12 +151,6 @@ TagHandlerNode.prototype = { } }); }); - - if (_this.postInvokeCode.length) { - _this.postInvokeCode.forEach(function (code) { - template.indent().code(code).code('\n'); - }); - } } };