Skip to content

Commit 8457090

Browse files
authored
Merge pull request #12 from andreyvolokitin/utilize-tree-messages
Make partials watchable by webpack
2 parents 7d5cece + abe5fc1 commit 8457090

4 files changed

Lines changed: 1096 additions & 1761 deletions

File tree

lib/extend.es6

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ import util from 'util';
44
import parseToPostHtml from 'posthtml-parser';
55
import { match } from 'posthtml/lib/api';
66

7-
87
const errors = {
98
'EXTENDS_NO_SRC': '<extends> has no "src"',
109
'BLOCK_NO_NAME': '<block> has no "name"',
1110
'UNEXPECTED_BLOCK': 'Unexpected block "%s"'
1211
};
1312

14-
1513
export default (options = {}) => {
1614
return tree => {
1715
options.encoding = options.encoding || 'utf8';
1816
options.root = options.root || './';
1917
options.plugins = options.plugins || [];
2018

21-
tree = handleExtendsNodes(tree, options);
19+
tree = handleExtendsNodes(tree, options, tree.messages);
2220

2321
const blockNodes = getBlockNodes(tree);
2422
for (let blockName of Object.keys(blockNodes)) {
@@ -32,19 +30,23 @@ export default (options = {}) => {
3230
};
3331
};
3432

35-
36-
function handleExtendsNodes(tree, options) {
33+
function handleExtendsNodes(tree, options, messages) {
3734
match.call(applyPluginsToTree(tree, options.plugins), {tag: 'extends'}, extendsNode => {
3835
if (! extendsNode.attrs || ! extendsNode.attrs.src) {
3936
throw getError(errors.EXTENDS_NO_SRC);
4037
}
4138

4239
const layoutPath = path.resolve(options.root, extendsNode.attrs.src);
4340
const layoutHtml = fs.readFileSync(layoutPath, options.encoding);
44-
let layoutTree = handleExtendsNodes(applyPluginsToTree(parseToPostHtml(layoutHtml), options.plugins), options);
41+
let layoutTree = handleExtendsNodes(applyPluginsToTree(parseToPostHtml(layoutHtml), options.plugins), options, messages);
4542

4643
extendsNode.tag = false;
4744
extendsNode.content = mergeExtendsAndLayout(layoutTree, extendsNode);
45+
messages.push({
46+
type: 'dependency',
47+
file: layoutPath,
48+
from: options.from
49+
});
4850

4951
return extendsNode;
5052
});

0 commit comments

Comments
 (0)