Allow property values to be functions that resolve to the actual value

This commit is contained in:
Patrick Steele-Idem 2014-07-29 13:40:25 -06:00
parent 4752706da3
commit 2e52266d50

View File

@ -32,6 +32,10 @@ function getPropsStr(props, template) {
if (props) {
template.indent(function () {
forEachEntry(props, function (name, value) {
if (typeof value === 'function') {
value = value();
}
if (template.isExpression(value)) {
var expressionStr;
template.indent(function () {
@ -63,15 +67,26 @@ function TagHandlerNode(tag) {
this.tag = tag;
this.dynamicAttributes = null;
this.inputExpression = null;
this.additionalVars = [];
}
TagHandlerNode.nodeType = 'element';
TagHandlerNode.convertNode = function (node, tag) {
if (node._TagHandlerNode) {
return;
}
extend(node, TagHandlerNode.prototype);
TagHandlerNode.call(node, tag);
};
TagHandlerNode.prototype = {
_TagHandlerNode: true,
addNestedVariable: function(name) {
this.additionalVars.push(name);
},
addDynamicAttribute: function (name, value) {
if (!this.dynamicAttributes) {
this.dynamicAttributes = {};
@ -129,6 +144,10 @@ TagHandlerNode.prototype = {
variableNames.push(varName);
}, this);
if (this.additionalVars.length) {
variableNames = variableNames.concat(this.additionalVars);
}
template.functionCall(tagHelperVar, function () {
template.code('context,\n').indent(function () {
template.line(handlerVar + ',').indent();