Skip to content

Commit

Permalink
Fix context
Browse files Browse the repository at this point in the history
  • Loading branch information
thewebartisan7 committed Oct 24, 2022
1 parent e78104f commit 5c3d3ba
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 3 deletions.
26 changes: 26 additions & 0 deletions docs/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="wrapper">
<div class="parent">
{"name":{"filled":true,"rendered":false,"tag":"fill:name","attrs":{},"content":["Slot parent"],"source":"Slot parent","locals":{}}}
<div class="parent-content">I'm parent</div>
<div class="parent-yield">
<h1>Parent yield</h1>
<div class="child">
{"name":{"filled":true,"rendered":false,"tag":"fill:name","attrs":{},"content":["Slot child"],"source":"Slot child","locals":{}}}
<div class="child-content">I'm child</div>
<div class="child-yield">
<h1>Child yield</h1>
</div>
<div class="child-slot">Slot child</div>
</div>
</div>
<div class="parent-slot">Slot parent</div>
</div>
{"name":{"filled":true,"rendered":false,"tag":"fill:name","attrs":{},"content":["\n ",{"tag":"div","attrs":{"class":"parent2-child2-slot"},"content":["\n parent2-child2 slot\n "]},"\n "],"source":"\n
<div class="\&quot;parent2-child2-slot\&quot;">\n parent2-child2 slot\n</div>
\n ","locals":{}}}


yes is filled
<div class="parent2-child2-slot">parent2-child2 slot</div>
<div class="parent2-child2-yield">parent2-child2 yield</div>
</div>
26 changes: 26 additions & 0 deletions examples/dist/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="wrapper">
<div class="parent">
{"name":{"filled":true,"rendered":false,"tag":"fill:name","attrs":{},"content":["Slot parent"],"source":"Slot parent","locals":{}}}
<div class="parent-content">I'm parent</div>
<div class="parent-yield">
<h1>Parent yield</h1>
<div class="child">
{"name":{"filled":true,"rendered":false,"tag":"fill:name","attrs":{},"content":["Slot child"],"source":"Slot child","locals":{}}}
<div class="child-content">I'm child</div>
<div class="child-yield">
<h1>Child yield</h1>
</div>
<div class="child-slot">Slot child</div>
</div>
</div>
<div class="parent-slot">Slot parent</div>
</div>
{"name":{"filled":true,"rendered":false,"tag":"fill:name","attrs":{},"content":["\n ",{"tag":"div","attrs":{"class":"parent2-child2-slot"},"content":["\n parent2-child2 slot\n "]},"\n "],"source":"\n
<div class="\&quot;parent2-child2-slot\&quot;">\n parent2-child2 slot\n</div>
\n ","locals":{}}}


yes is filled
<div class="parent2-child2-slot">parent2-child2 slot</div>
<div class="parent2-child2-yield">parent2-child2 yield</div>
</div>
15 changes: 15 additions & 0 deletions examples/src/components/child2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="child">
{{ $slots }}

<div class="child-content">
I'm child
</div>

<div class="child-yield">
<yield></yield>
</div>

<div class="child-slot">
<slot:name></slot:name>
</div>
</div>
26 changes: 26 additions & 0 deletions examples/src/components/parent2-child2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="wrapper">
<x-parent2>
<h1>Parent yield</h1>

<x-child2>

<h1>Child yield</h1>

<fill:name>Slot child</fill:name>

</x-child2>

<fill:name>Slot parent</fill:name>

</x-parent2>

{{ $slots }}

<if condition="{{ $slots.name.filled }}">
yes is filled
</if>

<slot:name></slot:name>

<yield></yield>
</div>
15 changes: 15 additions & 0 deletions examples/src/components/parent2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="parent">
{{ $slots }}

<div class="parent-content">
I'm parent
</div>

<div class="parent-yield">
<yield></yield>
</div>

<div class="parent-slot">
<slot:name></slot:name>
</div>
</div>
11 changes: 11 additions & 0 deletions examples/src/pages/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<x-parent2-child2>
<div class="parent2-child2-yield">
parent2-child2 yield
</div>

<fill:name>
<div class="parent2-child2-slot">
parent2-child2 slot
</div>
</fill:name>
</x-parent2-child2>
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = (options = {}) => tree => {
function processTree(options) {
const filledSlots = {};

// let processCounter = 0;
let processCounter = 0;

return function (tree) {
if (options.plugins.length > 0) {
Expand All @@ -121,13 +121,15 @@ function processTree(options) {
return currentNode;
}

// console.log(`${++processCounter}) Processing component ${componentPath}`);
console.log(`${++processCounter}) Processing component ${componentPath}`);

// log(currentNode, 'currentNode');

let nextNode = parser(readFileSync(componentPath, 'utf8'));

// Set filled slots
setFilledSlots(currentNode, filledSlots, options);
setFilledSlots(nextNode, filledSlots, options);
// setFilledSlots(nextNode, filledSlots, options);

// Reset previous locals with passed global and keep aware locals
options.expressions.locals = {...options.locals, ...options.aware};
Expand Down

0 comments on commit 5c3d3ba

Please sign in to comment.