Skip to content

Commit 2669bcd

Browse files
committed
feat: slot/fill tag name, close #22
1 parent 6f894b8 commit 2669bcd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/extend.es6

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ export default (options = {}) => {
1616
options.root = options.root || './';
1717
options.plugins = options.plugins || [];
1818
options.strict = Object.prototype.hasOwnProperty.call(options, 'strict') ? !!options.strict : true;
19+
options.slotTagName = options.slotTagName || 'block';
20+
options.fillTagName = options.fillTagName || 'block';
1921

2022
tree = handleExtendsNodes(tree, options, tree.messages);
2123

22-
const blockNodes = getBlockNodes(tree);
24+
const blockNodes = getBlockNodes(tree, options.slotTagName);
2325
for (let blockName of Object.keys(blockNodes)) {
2426
let blockNode = blockNodes[blockName];
2527
blockNode.tag = false;
@@ -42,7 +44,7 @@ function handleExtendsNodes(tree, options, messages) {
4244
let layoutTree = handleExtendsNodes(applyPluginsToTree(parseToPostHtml(layoutHtml), options.plugins), options, messages);
4345

4446
extendsNode.tag = false;
45-
extendsNode.content = mergeExtendsAndLayout(layoutTree, extendsNode, options.strict);
47+
extendsNode.content = mergeExtendsAndLayout(layoutTree, extendsNode, options.strict, options.slotTagName, options.fillTagName);
4648
messages.push({
4749
type: 'dependency',
4850
file: layoutPath,
@@ -60,13 +62,13 @@ function applyPluginsToTree(tree, plugins) {
6062
}
6163

6264

63-
function mergeExtendsAndLayout(layoutTree, extendsNode, strictNames) {
64-
const layoutBlockNodes = getBlockNodes(layoutTree);
65-
const extendsBlockNodes = getBlockNodes(extendsNode.content);
65+
function mergeExtendsAndLayout(layoutTree, extendsNode, strictNames, slotTagName, fillTagName) {
66+
const layoutBlockNodes = getBlockNodes(layoutTree, slotTagName);
67+
const extendsBlockNodes = getBlockNodes(extendsNode.content, fillTagName);
6668

6769
for (let layoutBlockName of Object.keys(layoutBlockNodes)) {
6870
let extendsBlockNode = extendsBlockNodes[layoutBlockName];
69-
if (! extendsBlockNode) {
71+
if (!extendsBlockNode) {
7072
continue;
7173
}
7274

@@ -123,10 +125,10 @@ function getBlockType(blockNode) {
123125
}
124126

125127

126-
function getBlockNodes(content = []) {
128+
function getBlockNodes(content = [], tag) {
127129
let blockNodes = {};
128130

129-
match.call(content, {tag: 'block'}, node => {
131+
match.call(content, {tag}, node => {
130132
if (! node.attrs || ! node.attrs.name) {
131133
throw getError(errors.BLOCK_NO_NAME);
132134
}

0 commit comments

Comments
 (0)