fixed slot content...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-08-19 13:13:17 +03:00
parent 0fcfe08ce2
commit 2eabff3ab9
3 changed files with 64 additions and 29 deletions

View File

@ -853,6 +853,11 @@ object.Constructor('Page', BasePage, {
// all other slots with <name> will replace its content, unless // all other slots with <name> will replace its content, unless
// explicit shown/hidden arguments are given. // explicit shown/hidden arguments are given.
// NOTE: hidden has precedence over shown if both are given. // NOTE: hidden has precedence over shown if both are given.
// NOTE: slots are handled in order of occurrence of opening tags
// in text and not by hierarchy, i.e. the later slot overrides
// the former and the most nested overrides the parent.
// This also works for cases where slots override slots they
// are contained in, this will not lead to recursion.
// //
// XXX revise the use of hidden/shown use mechanic and if it's // XXX revise the use of hidden/shown use mechanic and if it's
// needed... // needed...
@ -886,32 +891,40 @@ object.Constructor('Page', BasePage, {
// show first instance... // show first instance...
: name in slots) : name in slots)
// NOTE: we prioritize the nested slots over the current... var stack = []
var parent_slot = slots[name] slots[name]
&& stack.push(slots[name])
delete slots[name] delete slots[name]
var slot = await this.__parser__.expand(this, text, state) var slot = await this.__parser__.expand(this, text, state)
parent_slot = slot[name] == null ? slots[name]
parent_slot && stack.unshift(slot)
: slot
slot = slots[name] = slot = slots[name] =
slots[name] slots[name]
?? slot ?? slot
// handle <content/>... // handle <content/>...
// XXX BUG: nested slots are not handled correctly here... for(prev of stack){
for(var i in slot){ // get the first <content/>
if(typeof(slot[i]) != 'string' for(var i in slot){
&& slot[i].name == 'content'){ if(typeof(slot[i]) != 'string'
break } && slot[i].name == 'content'){
i = null } break }
i != null i = null }
&& parent_slot i != null
&& (slot[i] = parent_slot) && slot.splice(i, 1,
...prev
// remove nested slot handlers...
.filter(function(e){
return typeof(e) != 'function'
|| e.slot != name }) ) }
return hidden ? return hidden ?
'' ''
: function(state){ : Object.assign(
return state.slots[name] } }), function(state){
return state.slots[name] },
{slot: name}) }),
//*/
'content': ['slot'], 'content': ['slot'],
// //
@ -1504,18 +1517,23 @@ module.System = {
<content/> C <content/> C
</slot> </slot>
</slot> </slot>
</slot> ` }, </slot>
test_nested_slots: { <br><br>
text: object.doc` Mixed content: X A B C Z:
Nested content: A B C: <slot name="mixed-slot-content">
<slot name="nested-slot-content"> X
A </slot>
<slot name="nested-slot-content"> <slot name="mixed-slot-content">
<content/> A
<slot name="mixed-slot-content">
<content/> B <content/> B
<slot name="nested-slot-content">
<content/> C
</slot>
</slot> </slot>
<slot name="mixed-slot-content">
<content/> C
</slot>
</slot>
<slot name="mixed-slot-content">
<content/> Z
</slot> ` }, </slot> ` },
} }

View File

@ -207,6 +207,23 @@ pwiki.pwiki
<content/> C <content/> C
</slot> </slot>
</slot> </slot>
</slot>
<br><br>
Mixed content: X A B C Z:
<slot name="mixed-slot-content">
X
</slot>
<slot name="mixed-slot-content">
<content/> A
<slot name="mixed-slot-content">
<content/> B
<slot name="mixed-slot-content">
<content/> C
</slot>
</slot>
</slot>
<slot name="mixed-slot-content">
<content/> Z
</slot> `, }) </slot> `, })
.update({ .update({
location: '/test/nesting', location: '/test/nesting',

View File

@ -1,7 +1,6 @@
/********************************************************************** /**********************************************************************
* *
* *
* XXX slot <content/> does not work in nested slots...
* XXX GENERATOR make pattern path parsing a generator... * XXX GENERATOR make pattern path parsing a generator...
* ...experiment with a controllable iterator/range thing... * ...experiment with a controllable iterator/range thing...
* This would require: * This would require:
@ -19,7 +18,7 @@
* 2) all the macros that can source pages to produce generators: * 2) all the macros that can source pages to produce generators:
* @include(..) -- DONE * @include(..) -- DONE
* @source(..) -- DONE * @source(..) -- DONE
* @quote(..) -- * @quote(..) -- DONE
* @macro(..) -- * @macro(..) --
* 3) experiment with back-drivable generators... * 3) experiment with back-drivable generators...
* this can be implemented/tested in parallel and integrated into * this can be implemented/tested in parallel and integrated into
@ -171,7 +170,8 @@
* mistakes, bugs and inconsistencies. * mistakes, bugs and inconsistencies.
* - types of recursion * - types of recursion
* (see: pwiki/page.js: Page.macros.include(..) notes) * (see: pwiki/page.js: Page.macros.include(..) notes)
* - * - slot <content/> order --
* (see: page.js: Page's .macros.slot(..) notes)
* *
* *
* XXX weaknesses to review: * XXX weaknesses to review: