@@ -7,19 +7,19 @@ const {render} = require('posthtml-render');
7
7
* Set filled slots
8
8
*
9
9
* @param {Object } currentNode PostHTML tree
10
- * @param {Object } slots
10
+ * @param {Object } filledSlots
11
11
* @param {Object } options Plugin options
12
12
* @return {void }
13
13
*/
14
- function setFilledSlots ( currentNode , slots , { slot } ) {
15
- match . call ( currentNode , { tag : slot } , fillNode => {
14
+ function setFilledSlots ( currentNode , filledSlots , { fill } ) {
15
+ match . call ( currentNode , { tag : fill } , fillNode => {
16
16
if ( ! fillNode . attrs ) {
17
17
fillNode . attrs = { } ;
18
18
}
19
19
20
20
const name = fillNode . tag . split ( ':' ) [ 1 ] ;
21
21
22
- /** @var {Object} locals */
22
+ /** @var {Object} locals - NOT YET TESTED */
23
23
const locals = Object . fromEntries ( Object . entries ( fillNode . attrs ) . filter ( ( [ attributeName ] ) => ! [ name , 'type' ] . includes ( attributeName ) ) ) ;
24
24
25
25
if ( locals ) {
@@ -30,7 +30,7 @@ function setFilledSlots(currentNode, slots, {slot}) {
30
30
} ) ;
31
31
}
32
32
33
- slots [ name ] = {
33
+ filledSlots [ name ] = {
34
34
filled : true ,
35
35
rendered : false ,
36
36
tag : fillNode . tag ,
@@ -45,68 +45,68 @@ function setFilledSlots(currentNode, slots, {slot}) {
45
45
}
46
46
47
47
/**
48
- * Process <slot > tag
48
+ * Process <fill > tag
49
49
*
50
50
* @param {Object } tree PostHTML tree
51
- * @param {Object } content Content pushed by stack name
51
+ * @param {Object } filledSlots Filled slots content
52
52
* @param {Object } options Plugin options
53
53
* @return {void }
54
54
*/
55
- function processSlotContent ( tree , content , { slot } ) {
56
- match . call ( tree , { tag : slot } , slotNode => {
57
- const name = slotNode . tag . split ( ':' ) [ 1 ] ;
55
+ function processFillContent ( tree , filledSlots , { fill } ) {
56
+ match . call ( tree , { tag : fill } , fillNode => {
57
+ const name = fillNode . tag . split ( ':' ) [ 1 ] ;
58
58
59
- if ( ! content [ name ] ) {
60
- content [ name ] = { } ;
59
+ if ( ! filledSlots [ name ] ) {
60
+ filledSlots [ name ] = { } ;
61
61
}
62
62
63
- content [ name ] . tag = slotNode . tag ;
64
- content [ name ] . attrs = slotNode . attrs ;
65
- content [ name ] . content = slotNode . content ;
66
- content [ name ] . source = render ( slotNode . content ) ;
67
- content [ name ] . rendered = false ;
63
+ filledSlots [ name ] . tag = fillNode . tag ;
64
+ filledSlots [ name ] . attrs = fillNode . attrs ;
65
+ filledSlots [ name ] . content = fillNode . content ;
66
+ filledSlots [ name ] . source = render ( fillNode . content ) ;
67
+ filledSlots [ name ] . rendered = false ;
68
68
69
- slotNode . tag = false ;
70
- slotNode . content = null ;
69
+ fillNode . tag = false ;
70
+ fillNode . content = null ;
71
71
72
- return slotNode ;
72
+ return fillNode ;
73
73
} ) ;
74
74
}
75
75
76
76
/**
77
- * Process <fill > tag
77
+ * Process <slot > tag
78
78
*
79
79
* @param {Object } tree PostHTML tree
80
- * @param {Object } content Content pushed by stack name
80
+ * @param {Object } filledSlots Filled slots content
81
81
* @param {Object } options Plugin options
82
82
* @return {void }
83
83
*/
84
- function processFillContent ( tree , content , { fill } ) {
85
- match . call ( tree , { tag : fill } , fillNode => {
86
- const name = fillNode . tag . split ( ':' ) [ 1 ] ;
84
+ function processSlotContent ( tree , filledSlots , { slot } ) {
85
+ match . call ( tree , { tag : slot } , slotNode => {
86
+ const name = slotNode . tag . split ( ':' ) [ 1 ] ;
87
87
88
- fillNode . tag = false ;
88
+ slotNode . tag = false ;
89
89
90
- if ( content [ name ] ?. rendered ) {
91
- fillNode . content = null ;
92
- } else if ( fillNode . content && content [ name ] ?. attrs && ( typeof content [ name ] ?. attrs . append !== 'undefined' || typeof content [ name ] ?. attrs . prepend !== 'undefined' ) ) {
93
- fillNode . content = typeof content [ name ] ?. attrs . append === 'undefined' ? content [ name ] ?. content . concat ( fillNode . content ) : fillNode . content . concat ( content [ name ] ?. content ) ;
90
+ if ( filledSlots [ name ] ?. rendered ) {
91
+ slotNode . content = null ;
92
+ } else if ( slotNode . content && filledSlots [ name ] ?. attrs && ( typeof filledSlots [ name ] ?. attrs . append !== 'undefined' || typeof filledSlots [ name ] ?. attrs . prepend !== 'undefined' ) ) {
93
+ slotNode . content = typeof filledSlots [ name ] ?. attrs . append === 'undefined' ? filledSlots [ name ] ?. content . concat ( slotNode . content ) : slotNode . content . concat ( filledSlots [ name ] ?. content ) ;
94
94
} else {
95
- fillNode . content = content [ name ] ?. content ;
95
+ slotNode . content = filledSlots [ name ] ?. content ;
96
96
}
97
97
98
98
// Set rendered to true so a slot can be output only once,
99
99
// when not present "aware" attribute
100
- if ( content [ name ] && ( ! content [ name ] ?. attrs || typeof content [ name ] . attrs . aware === 'undefined' ) ) {
101
- content [ name ] . rendered = true ;
100
+ if ( filledSlots [ name ] && ( ! filledSlots [ name ] ?. attrs || typeof filledSlots [ name ] . attrs . aware === 'undefined' ) ) {
101
+ filledSlots [ name ] . rendered = true ;
102
102
}
103
103
104
- return fillNode ;
104
+ return slotNode ;
105
105
} ) ;
106
106
}
107
107
108
108
module . exports = {
109
109
setFilledSlots,
110
- processSlotContent ,
111
- processFillContent
110
+ processFillContent ,
111
+ processSlotContent
112
112
} ;
0 commit comments