Skip to content

Commit

Permalink
Allow to append content #1
Browse files Browse the repository at this point in the history
  • Loading branch information
maltsev committed Jan 3, 2016
1 parent 2b578ab commit b162108
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/extend.es6
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ function mergeContent(extendBlockContent, layoutBlockContent, extendBlockType) {
layoutBlockContent = layoutBlockContent || [];

switch (extendBlockType) {
case 'replace':
layoutBlockContent = extendBlockContent;
break;

case 'prepend':
layoutBlockContent = extendBlockContent.concat(layoutBlockContent);
break;

case 'replace':
layoutBlockContent = extendBlockContent;
case 'append':
layoutBlockContent = layoutBlockContent.concat(extendBlockContent);
break;
}

Expand All @@ -94,7 +98,7 @@ function mergeContent(extendBlockContent, layoutBlockContent, extendBlockType) {
function getBlockType(blockNode) {
let blockType = (blockNode.attrs && blockNode.attrs.type) || '';
blockType = blockType.toLowerCase();
if (['replace', 'prepend'].indexOf(blockType) === -1) {
if (['replace', 'prepend', 'append'].indexOf(blockType) === -1) {
blockType = 'replace';
}

Expand Down
7 changes: 4 additions & 3 deletions test/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,24 @@ describe('Extend', () => {
});


it('should extend layout and prepend content', () => {
it('should append and prepend content', () => {
mfs.writeFileSync('./layout.html', `
<head><block name="head"><style></style></block></head>
<body><block name="body">body</block></body>
<footer><block name="footer">footer</block></footer>
<footer><block name="footer">2015</block></footer>
`);

return init(`
<extends src="layout.html">
<block name="head" type="prepend"><title>hello!</title></block>
<block name="body">Some body content</block>
<block name="footer" type="append">—2016</block>
</extends>
`).then(html => {
expect(html).toBe(cleanHtml(`
<head><title>hello!</title><style></style></head>
<body>Some body content</body>
<footer>footer</footer>
<footer>2015—2016</footer>
`));
});
});
Expand Down

0 comments on commit b162108

Please sign in to comment.