Skip to content

Commit b162108

Browse files
committed
Allow to append content #1
1 parent 2b578ab commit b162108

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/extend.es6

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ function mergeContent(extendBlockContent, layoutBlockContent, extendBlockType) {
7878
layoutBlockContent = layoutBlockContent || [];
7979

8080
switch (extendBlockType) {
81+
case 'replace':
82+
layoutBlockContent = extendBlockContent;
83+
break;
84+
8185
case 'prepend':
8286
layoutBlockContent = extendBlockContent.concat(layoutBlockContent);
8387
break;
8488

85-
case 'replace':
86-
layoutBlockContent = extendBlockContent;
89+
case 'append':
90+
layoutBlockContent = layoutBlockContent.concat(extendBlockContent);
8791
break;
8892
}
8993

@@ -94,7 +98,7 @@ function mergeContent(extendBlockContent, layoutBlockContent, extendBlockType) {
9498
function getBlockType(blockNode) {
9599
let blockType = (blockNode.attrs && blockNode.attrs.type) || '';
96100
blockType = blockType.toLowerCase();
97-
if (['replace', 'prepend'].indexOf(blockType) === -1) {
101+
if (['replace', 'prepend', 'append'].indexOf(blockType) === -1) {
98102
blockType = 'replace';
99103
}
100104

test/extend.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,24 @@ describe('Extend', () => {
9292
});
9393

9494

95-
it('should extend layout and prepend content', () => {
95+
it('should append and prepend content', () => {
9696
mfs.writeFileSync('./layout.html', `
9797
<head><block name="head"><style></style></block></head>
9898
<body><block name="body">body</block></body>
99-
<footer><block name="footer">footer</block></footer>
99+
<footer><block name="footer">2015</block></footer>
100100
`);
101101

102102
return init(`
103103
<extends src="layout.html">
104104
<block name="head" type="prepend"><title>hello!</title></block>
105105
<block name="body">Some body content</block>
106+
<block name="footer" type="append">—2016</block>
106107
</extends>
107108
`).then(html => {
108109
expect(html).toBe(cleanHtml(`
109110
<head><title>hello!</title><style></style></head>
110111
<body>Some body content</body>
111-
<footer>footer</footer>
112+
<footer>2015—2016</footer>
112113
`));
113114
});
114115
});

0 commit comments

Comments
 (0)