Skip to content

Commit 77e8f62

Browse files
committedOct 23, 2022
Allow to set slot separator via options
1 parent 39e7481 commit 77e8f62

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed
 

‎src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = (options = {}) => tree => {
3333
options.yield = options.yield || 'yield';
3434
options.slot = options.slot || 'slot';
3535
options.fill = options.fill || 'fill';
36+
options.slotSeparator = options.slotSeparator || ':';
3637
options.push = options.push || 'push';
3738
options.stack = options.stack || 'stack';
3839
options.localsAttr = options.localsAttr || 'props';
@@ -42,11 +43,11 @@ module.exports = (options = {}) => tree => {
4243
options.strict = typeof options.strict === 'undefined' ? true : options.strict;
4344

4445
if (!(options.slot instanceof RegExp)) {
45-
options.slot = new RegExp(`^${options.slot}:`, 'i');
46+
options.slot = new RegExp(`^${options.slot}${options.slotSeparator}`, 'i');
4647
}
4748

4849
if (!(options.fill instanceof RegExp)) {
49-
options.fill = new RegExp(`^${options.fill}:`, 'i');
50+
options.fill = new RegExp(`^${options.fill}${options.slotSeparator}`, 'i');
5051
}
5152

5253
if (!(options.tagPrefix instanceof RegExp)) {

‎src/slots.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@ const {match} = require('posthtml/lib/api');
44
const {render} = require('posthtml-render');
55
const {each, omit} = require('underscore');
66

7-
const separator = ':';
8-
97
/**
108
* Set filled slots
119
*
1210
* @param {Object} currentNode PostHTML tree
1311
* @param {Object} filledSlots
14-
* @param {Object} options Plugin options
12+
* @param {String} fill Fill tag name
13+
* @param {String} slotSeparator Slot separator
1514
* @return {void}
1615
*/
17-
function setFilledSlots(currentNode, filledSlots, {fill}) {
16+
function setFilledSlots(currentNode, filledSlots, {fill, slotSeparator}) {
1817
match.call(currentNode, {tag: fill}, fillNode => {
1918
if (!fillNode.attrs) {
2019
fillNode.attrs = {};
2120
}
2221

23-
const name = fillNode.tag.split(separator)[1];
22+
const name = fillNode.tag.split(slotSeparator)[1];
2423

2524
const locals = omit(fillNode.attrs, [name, 'type', 'append', 'prepend', 'aware']);
2625

@@ -51,12 +50,13 @@ function setFilledSlots(currentNode, filledSlots, {fill}) {
5150
*
5251
* @param {Object} tree PostHTML tree
5352
* @param {Object} filledSlots Filled slots content
54-
* @param {Object} options Plugin options
53+
* @param {String} fill Fill tag name
54+
* @param {String} slotSeparator Slot separator
5555
* @return {void}
5656
*/
57-
function processFillContent(tree, filledSlots, {fill}) {
57+
function processFillContent(tree, filledSlots, {fill, slotSeparator}) {
5858
match.call(tree, {tag: fill}, fillNode => {
59-
const name = fillNode.tag.split(separator)[1];
59+
const name = fillNode.tag.split(slotSeparator)[1];
6060

6161
if (!filledSlots[name]) {
6262
filledSlots[name] = {};
@@ -80,12 +80,13 @@ function processFillContent(tree, filledSlots, {fill}) {
8080
*
8181
* @param {Object} tree PostHTML tree
8282
* @param {Object} filledSlots Filled slots content
83-
* @param {Object} options Plugin options
83+
* @param {String} slot Slot tag name
84+
* @param {String} slotSeparator Slot separator
8485
* @return {void}
8586
*/
86-
function processSlotContent(tree, filledSlots, {slot}) {
87+
function processSlotContent(tree, filledSlots, {slot, slotSeparator}) {
8788
match.call(tree, {tag: slot}, slotNode => {
88-
const name = slotNode.tag.split(separator)[1];
89+
const name = slotNode.tag.split(slotSeparator)[1];
8990

9091
slotNode.tag = false;
9192

0 commit comments

Comments
 (0)