Fixes #167 - Nested tags only work one level deep

This commit is contained in:
Patrick Steele-Idem 2015-12-07 11:44:08 -07:00
parent 032a5da4fa
commit f98a7dfef9
10 changed files with 61 additions and 18 deletions

View File

@ -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

View File

@ -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);
});
},

View File

@ -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');
}

View File

@ -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"
}

View File

@ -0,0 +1,10 @@
{
"renderer": "./renderer",
"@class": "string",
"@items <item>[]": {
"@foo": "string",
"@body <body>": {
}
}
}

View File

@ -0,0 +1,5 @@
var template = require('./template.marko');
module.exports = function(input, out) {
template.render(input, out);
};

View 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>

View File

@ -0,0 +1 @@
<div>Foo: bar Body: <b>Deeply nested!</b></div><div>Foo: baz Body: <b>Another deeply nested!</b></div>

View 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>

View File

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