diff --git a/CHANGELOG.md b/CHANGELOG.md index da918d5d8..fa8cf5f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/compiler/taglibs/TaglibLookup.js b/compiler/taglibs/TaglibLookup.js index 32b784ed7..4de119c52 100644 --- a/compiler/taglibs/TaglibLookup.js +++ b/compiler/taglibs/TaglibLookup.js @@ -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); }); }, diff --git a/taglibs/core/TagHandlerNode.js b/taglibs/core/TagHandlerNode.js index 0ca55ffda..1c3fbbfef 100644 --- a/taglibs/core/TagHandlerNode.js +++ b/taglibs/core/TagHandlerNode.js @@ -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'); } diff --git a/test/fixtures/marko-taglib.json b/test/fixtures/marko-taglib.json index c0f06e4b2..f0b2c0ec2 100644 --- a/test/fixtures/marko-taglib.json +++ b/test/fixtures/marko-taglib.json @@ -122,5 +122,6 @@ "taglib-imports": ["./package.json", "./nested-import/marko-taglib.json"], "": { "@foo": "string" - } + }, + "": "./taglib/test-nested-tags-deep/marko-tag.json" } \ No newline at end of file diff --git a/test/fixtures/taglib/test-nested-tags-deep/marko-tag.json b/test/fixtures/taglib/test-nested-tags-deep/marko-tag.json new file mode 100644 index 000000000..e78045946 --- /dev/null +++ b/test/fixtures/taglib/test-nested-tags-deep/marko-tag.json @@ -0,0 +1,10 @@ +{ + "renderer": "./renderer", + "@class": "string", + "@items []": { + "@foo": "string", + "@body ": { + + } + } +} \ No newline at end of file diff --git a/test/fixtures/taglib/test-nested-tags-deep/renderer.js b/test/fixtures/taglib/test-nested-tags-deep/renderer.js new file mode 100644 index 000000000..edb0a26ca --- /dev/null +++ b/test/fixtures/taglib/test-nested-tags-deep/renderer.js @@ -0,0 +1,5 @@ +var template = require('./template.marko'); + +module.exports = function(input, out) { + template.render(input, out); +}; \ No newline at end of file diff --git a/test/fixtures/taglib/test-nested-tags-deep/template.marko b/test/fixtures/taglib/test-nested-tags-deep/template.marko new file mode 100644 index 000000000..ab58c75be --- /dev/null +++ b/test/fixtures/taglib/test-nested-tags-deep/template.marko @@ -0,0 +1,4 @@ +
+ Foo: ${item.foo} + Body: +
\ No newline at end of file diff --git a/test/fixtures/templates/nested-tags-deep/expected.html b/test/fixtures/templates/nested-tags-deep/expected.html new file mode 100644 index 000000000..a841d19bb --- /dev/null +++ b/test/fixtures/templates/nested-tags-deep/expected.html @@ -0,0 +1 @@ +
Foo: bar Body: Deeply nested!
Foo: baz Body: Another deeply nested!
\ No newline at end of file diff --git a/test/fixtures/templates/nested-tags-deep/template.marko b/test/fixtures/templates/nested-tags-deep/template.marko new file mode 100644 index 000000000..c166228ee --- /dev/null +++ b/test/fixtures/templates/nested-tags-deep/template.marko @@ -0,0 +1,12 @@ + + + + Deeply nested! + + + + + Another deeply nested! + + + \ No newline at end of file diff --git a/test/fixtures/templates/nested-tags-deep/test.js b/test/fixtures/templates/nested-tags-deep/test.js new file mode 100644 index 000000000..c4013b344 --- /dev/null +++ b/test/fixtures/templates/nested-tags-deep/test.js @@ -0,0 +1 @@ +exports.templateData = {};