diff --git a/lib/index.js b/lib/index.js index 25883cb..ea7c0ba 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,7 +25,15 @@ module.exports = function reshapeLayouts (options = {}) { function handleExtendsNodes (tree, options, ctx) { return tree.reduce((m, node) => { // if it's not an "extends" tag, move on - if (node.name !== 'extends') { m.push(node); return m } + if (node.name !== 'extends') { + if (Array.isArray(node.content)) { + node.content = handleExtendsNodes(node.content, options, ctx) + m.push(node) + } else { + m.push(node) + } + return m + } // if the extends tag has no "src", throw an error if (!node.attrs || !node.attrs.src) { @@ -51,7 +59,7 @@ function handleExtendsNodes (tree, options, ctx) { } // merge the contents of the current node into the layout - m = m.concat(mergeExtendsAndLayout(layoutTree, node.content, ctx)) + m = m.concat(mergeExtendsAndLayout(layoutTree, handleExtendsNodes(node.content, options, ctx), ctx)) return m }, []) } diff --git a/test/index.js b/test/index.js index 9ca97df..70bf302 100644 --- a/test/index.js +++ b/test/index.js @@ -194,6 +194,27 @@ test('uses the correct source location for layouts and templates', (t) => { } }) +test('recursive layout extension', (t) => { + mfs.writeFileSync('./layout.html', '

default

') + mfs.writeFileSync('./component.html', '

this is a very interesting component

this is default content
') + + return init(` + +

blah

+ + + Hello! + + +
+
+ `).then((html) => { + t.truthy((html) === cleanHtml(`

blah

this is a very interesting component

+ Hello! +
`)) + }) +}) + function assertError (t, promise, expectedErrorMessage) { return promise .catch((error) => error.message)