mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Allow template-data to be combined with other attrs on the <include> tag
This commit is contained in:
parent
9f4085e5b9
commit
44fcba5651
@ -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;
|
||||
|
||||
1
test/fixtures/templates/include-template-data/expected.html
vendored
Normal file
1
test/fixtures/templates/include-template-data/expected.html
vendored
Normal 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.
|
||||
4
test/fixtures/templates/include-template-data/include-target.marko
vendored
Normal file
4
test/fixtures/templates/include-template-data/include-target.marko
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<var name="name" value="data.name"/>
|
||||
<var name="count" value="data.count"/>
|
||||
|
||||
Hello $name! You have $count new messages.
|
||||
3
test/fixtures/templates/include-template-data/template.marko
vendored
Normal file
3
test/fixtures/templates/include-template-data/template.marko
vendored
Normal 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}"/>
|
||||
1
test/fixtures/templates/include-template-data/test.js
vendored
Normal file
1
test/fixtures/templates/include-template-data/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user