mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #167 - Nested tags only work one level deep
This commit is contained in:
parent
032a5da4fa
commit
f98a7dfef9
@ -5,6 +5,14 @@ Changelog
|
||||
|
||||
## 2.7.x
|
||||
|
||||
### 2.7.31
|
||||
|
||||
- Fixes #167 - Nested tags only work one level deep
|
||||
|
||||
### 2.7.30
|
||||
|
||||
- docs: don't exclude docs in .npmignore
|
||||
|
||||
### 2.7.29
|
||||
|
||||
- Fixes #161 - Nested tags with no body content are not handled correctly
|
||||
|
||||
@ -100,24 +100,24 @@ TaglibLookup.prototype = {
|
||||
|
||||
var merged = this.merged;
|
||||
|
||||
function handleNestedTag(nestedTag, parentTagName) {
|
||||
var fullyQualifiedName = parentTagName + '.' + nestedTag.name;
|
||||
|
||||
// Create a clone of the nested tag since we need to add some new
|
||||
// properties
|
||||
var clonedNestedTag = new Tag();
|
||||
extend(clonedNestedTag ,nestedTag);
|
||||
// Record the fully qualified name of the parent tag that this
|
||||
// custom tag is associated with.
|
||||
clonedNestedTag.parentTagName = parentTagName;
|
||||
clonedNestedTag.name = fullyQualifiedName;
|
||||
merged.tags[fullyQualifiedName] = clonedNestedTag;
|
||||
function handleNestedTags(tag, parentTagName) {
|
||||
tag.forEachNestedTag(function(nestedTag) {
|
||||
var fullyQualifiedName = parentTagName + '.' + nestedTag.name;
|
||||
// Create a clone of the nested tag since we need to add some new
|
||||
// properties
|
||||
var clonedNestedTag = new Tag();
|
||||
extend(clonedNestedTag, nestedTag);
|
||||
// Record the fully qualified name of the parent tag that this
|
||||
// custom tag is associated with.
|
||||
clonedNestedTag.parentTagName = parentTagName;
|
||||
clonedNestedTag.name = fullyQualifiedName;
|
||||
merged.tags[fullyQualifiedName] = clonedNestedTag;
|
||||
handleNestedTags(clonedNestedTag, fullyQualifiedName);
|
||||
});
|
||||
}
|
||||
|
||||
taglib.forEachTag(function(tag) {
|
||||
tag.forEachNestedTag(function(nestedTag) {
|
||||
handleNestedTag(nestedTag, tag.name);
|
||||
});
|
||||
handleNestedTags(tag, tag.name);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@ -153,6 +153,7 @@ TagHandlerNode.prototype = {
|
||||
|
||||
var nestedTagVar;
|
||||
var nestedTagParentNode = null;
|
||||
var parentNestedTagVar;
|
||||
|
||||
if (isNestedTag) {
|
||||
nestedTagParentNode = getNestedTagParentNode(this, tag);
|
||||
@ -161,7 +162,7 @@ TagHandlerNode.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
nestedTagVar = nestedTagParentNode.data.nestedTagVar;
|
||||
parentNestedTagVar = nestedTagParentNode.data.nestedTagVar;
|
||||
}
|
||||
|
||||
if (hasNestedTags) {
|
||||
@ -314,7 +315,7 @@ TagHandlerNode.prototype = {
|
||||
|
||||
if (isNestedTag) {
|
||||
options.push('targetProperty: ' + JSON.stringify(tag.targetProperty));
|
||||
options.push('parent: ' + nestedTagVar);
|
||||
options.push('parent: ' + parentNestedTagVar);
|
||||
if (tag.isRepeated) {
|
||||
options.push('isRepeated: 1');
|
||||
}
|
||||
|
||||
3
test/fixtures/marko-taglib.json
vendored
3
test/fixtures/marko-taglib.json
vendored
@ -122,5 +122,6 @@
|
||||
"taglib-imports": ["./package.json", "./nested-import/marko-taglib.json"],
|
||||
"<test-invalid-attr>": {
|
||||
"@foo": "string"
|
||||
}
|
||||
},
|
||||
"<test-nested-tags-deep>": "./taglib/test-nested-tags-deep/marko-tag.json"
|
||||
}
|
||||
10
test/fixtures/taglib/test-nested-tags-deep/marko-tag.json
vendored
Normal file
10
test/fixtures/taglib/test-nested-tags-deep/marko-tag.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"renderer": "./renderer",
|
||||
"@class": "string",
|
||||
"@items <item>[]": {
|
||||
"@foo": "string",
|
||||
"@body <body>": {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
5
test/fixtures/taglib/test-nested-tags-deep/renderer.js
vendored
Normal file
5
test/fixtures/taglib/test-nested-tags-deep/renderer.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
var template = require('./template.marko');
|
||||
|
||||
module.exports = function(input, out) {
|
||||
template.render(input, out);
|
||||
};
|
||||
4
test/fixtures/taglib/test-nested-tags-deep/template.marko
vendored
Normal file
4
test/fixtures/taglib/test-nested-tags-deep/template.marko
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<div for="item in data.items">
|
||||
Foo: ${item.foo}
|
||||
Body: <invoke function="item.body.renderBody(out)" if="item.body"/>
|
||||
</div>
|
||||
1
test/fixtures/templates/nested-tags-deep/expected.html
vendored
Normal file
1
test/fixtures/templates/nested-tags-deep/expected.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div>Foo: bar Body: <b>Deeply nested!</b></div><div>Foo: baz Body: <b>Another deeply nested!</b></div>
|
||||
12
test/fixtures/templates/nested-tags-deep/template.marko
vendored
Normal file
12
test/fixtures/templates/nested-tags-deep/template.marko
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<test-nested-tags-deep class="nested-tags-deep">
|
||||
<test-nested-tags-deep.item foo="bar">
|
||||
<test-nested-tags-deep.item.body>
|
||||
<b>Deeply nested!</b>
|
||||
</test-nested-tags-deep.item.body>
|
||||
</test-nested-tags-deep.item>
|
||||
<test-nested-tags-deep.item foo="baz">
|
||||
<test-nested-tags-deep.item.body>
|
||||
<b>Another deeply nested!</b>
|
||||
</test-nested-tags-deep.item.body>
|
||||
</test-nested-tags-deep.item>
|
||||
</test-nested-tags-deep>
|
||||
1
test/fixtures/templates/nested-tags-deep/test.js
vendored
Normal file
1
test/fixtures/templates/nested-tags-deep/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user