Allow template-data to be combined with other attrs on the <include> tag

This commit is contained in:
Patrick Steele-Idem 2015-07-06 11:04:38 -06:00
parent 9f4085e5b9
commit 44fcba5651
5 changed files with 31 additions and 9 deletions

View File

@ -46,14 +46,13 @@ IncludeNode.prototype = {
var resourcePath;
var _this = this;
if (templatePath) {
this.removeProperty('template');
this.removeProperty('template');
this.removeProperty('templateData');
this.removeProperty('template-data');
var dataExpression;
if (templateData) {
dataExpression = templateData;
} else {
dataExpression = {
if (templatePath) {
var dataExpression = {
toString: function () {
var propParts = [];
@ -68,10 +67,24 @@ IncludeNode.prototype = {
propParts.push(stringify('body') + ': ' + _this.getBodyContentExpression(template, false));
}
return '{' + propParts.join(', ') + '}';
var propsCode = '{' + propParts.join(', ') + '}';
if (templateData) {
if (propParts.length) {
var extendVar = template.addStaticVar('__extend', '__helpers.xt');
propsCode = extendVar + '(' +
extendVar + '({}, ' + templateData + '), ' +
propsCode +
')';
} else {
propsCode = templateData;
}
}
return propsCode;
}
};
}
template.include(templatePath, dataExpression);
} else if ((resourcePath = this.getAttribute('resource'))) {
var isStatic = this.getProperty('static') !== false;

View File

@ -0,0 +1 @@
Hello Frank! You have 20 new messages.Hello Frank! You have 20 new messages.Hello Frank! You have 20 new messages.

View File

@ -0,0 +1,4 @@
<var name="name" value="data.name"/>
<var name="count" value="data.count"/>
Hello $name! You have $count new messages.

View File

@ -0,0 +1,3 @@
<include template="./include-target.marko" template-data="{name: 'Frank', count: 20}"/>
<include template="./include-target.marko" template-data="{name: 'Frank'}" count="${20}"/>
<include template="./include-target.marko" name="Frank" count="${20}"/>

View File

@ -0,0 +1 @@
exports.templateData = {};