2
2
3
3
const { match} = require ( 'posthtml/lib/api' ) ;
4
4
const { render} = require ( 'posthtml-render' ) ;
5
+ const { each, omit} = require ( 'underscore' ) ;
6
+
7
+ const separator = ':' ;
5
8
6
9
/**
7
10
* Set filled slots
@@ -17,15 +20,14 @@ function setFilledSlots(currentNode, filledSlots, {fill}) {
17
20
fillNode . attrs = { } ;
18
21
}
19
22
20
- const name = fillNode . tag . split ( ':' ) [ 1 ] ;
23
+ const name = fillNode . tag . split ( separator ) [ 1 ] ;
21
24
22
- /** @var {Object} locals - NOT YET TESTED */
23
- const locals = Object . fromEntries ( Object . entries ( fillNode . attrs ) . filter ( ( [ attributeName ] ) => ! [ name , 'type' ] . includes ( attributeName ) ) ) ;
25
+ const locals = omit ( fillNode . attrs , [ name , 'type' , 'append' , 'prepend' , 'aware' ] ) ;
24
26
25
27
if ( locals ) {
26
- Object . keys ( locals ) . forEach ( local => {
28
+ each ( locals , ( value , key , attrs ) => {
27
29
try {
28
- locals [ local ] = JSON . parse ( locals [ local ] ) ;
30
+ attrs [ key ] = JSON . parse ( value ) ;
29
31
} catch { }
30
32
} ) ;
31
33
}
@@ -54,7 +56,7 @@ function setFilledSlots(currentNode, filledSlots, {fill}) {
54
56
*/
55
57
function processFillContent ( tree , filledSlots , { fill} ) {
56
58
match . call ( tree , { tag : fill } , fillNode => {
57
- const name = fillNode . tag . split ( ':' ) [ 1 ] ;
59
+ const name = fillNode . tag . split ( separator ) [ 1 ] ;
58
60
59
61
if ( ! filledSlots [ name ] ) {
60
62
filledSlots [ name ] = { } ;
@@ -83,7 +85,7 @@ function processFillContent(tree, filledSlots, {fill}) {
83
85
*/
84
86
function processSlotContent ( tree , filledSlots , { slot} ) {
85
87
match . call ( tree , { tag : slot } , slotNode => {
86
- const name = slotNode . tag . split ( ':' ) [ 1 ] ;
88
+ const name = slotNode . tag . split ( separator ) [ 1 ] ;
87
89
88
90
slotNode . tag = false ;
89
91
0 commit comments