mirror of
https://github.com/flynx/pWiki.git
synced 2026-08-25 00:36:41 +00:00
working on slots...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e3246c7fb2
commit
26912453ce
@ -517,6 +517,8 @@ object.Constructor('Page', BasePage, {
|
|||||||
|
|
||||||
RECURSION_ERROR: 'RecursionError',
|
RECURSION_ERROR: 'RecursionError',
|
||||||
|
|
||||||
|
NOT_FOUND_TEMPLATE_ERROR: 'NotFoundTemplateError',
|
||||||
|
|
||||||
// The page that started the current render...
|
// The page that started the current render...
|
||||||
//
|
//
|
||||||
// This is set by .text and maintained by .clone(..).
|
// This is set by .text and maintained by .clone(..).
|
||||||
@ -828,6 +830,9 @@ object.Constructor('Page', BasePage, {
|
|||||||
// Force hide a slot...
|
// Force hide a slot...
|
||||||
// <slot hidden ... />
|
// <slot hidden ... />
|
||||||
//
|
//
|
||||||
|
// Insert previous slot content...
|
||||||
|
// <content/>
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// NOTE: by default only the first slot with <name> is visible,
|
// NOTE: by default only the first slot with <name> is visible,
|
||||||
// all other slots with <name> will replace its content, unless
|
// all other slots with <name> will replace its content, unless
|
||||||
@ -836,8 +841,6 @@ object.Constructor('Page', BasePage, {
|
|||||||
//
|
//
|
||||||
// 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...
|
||||||
// XXX how do we handle a slot defined within a slot????
|
|
||||||
// ...seems that we'll fall into recursion on definition...
|
|
||||||
slot: Macro(
|
slot: Macro(
|
||||||
['name', 'text', ['shown', 'hidden']],
|
['name', 'text', ['shown', 'hidden']],
|
||||||
async function(args, body, state){
|
async function(args, body, state){
|
||||||
@ -869,17 +872,31 @@ object.Constructor('Page', BasePage, {
|
|||||||
: name in slots)
|
: name in slots)
|
||||||
|
|
||||||
// NOTE: we prioritize the nested slots over the current...
|
// NOTE: we prioritize the nested slots over the current...
|
||||||
|
var parent_slot = 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)
|
||||||
slots[name] =
|
parent_slot = slot[name] == null ?
|
||||||
|
parent_slot
|
||||||
|
: slot
|
||||||
|
slot = slots[name] =
|
||||||
slots[name]
|
slots[name]
|
||||||
?? slot
|
?? slot
|
||||||
|
|
||||||
|
// handle slot-content...
|
||||||
|
for(var i in slot){
|
||||||
|
if(typeof(slot[i]) != 'string'
|
||||||
|
&& slot[i].name == 'content'){
|
||||||
|
break }
|
||||||
|
i = null }
|
||||||
|
i != null
|
||||||
|
&& parent_slot
|
||||||
|
&& (slot[i] = parent_slot)
|
||||||
|
|
||||||
return hidden ?
|
return hidden ?
|
||||||
''
|
''
|
||||||
: function(state){
|
: function(state){
|
||||||
return state.slots[name] } }),
|
return state.slots[name] } }),
|
||||||
'slot-content': ['slot'],
|
'content': ['slot'],
|
||||||
|
|
||||||
//
|
//
|
||||||
// <macro src=<url>> .. </macro>
|
// <macro src=<url>> .. </macro>
|
||||||
@ -1091,10 +1108,10 @@ object.Constructor('Page', BasePage, {
|
|||||||
path = pwpath.join(path)
|
path = pwpath.join(path)
|
||||||
|
|
||||||
// get the template relative to the top most pattern...
|
// get the template relative to the top most pattern...
|
||||||
// XXX BUG: this sometimes returns undefined on load...
|
|
||||||
tpl = await this.get(tpl).find(true)
|
tpl = await this.get(tpl).find(true)
|
||||||
if(!tpl){
|
if(!tpl){
|
||||||
throw new Error('UNKNOWN RENDER TEMPLATE: '+ tpl_name) }
|
console.warn('UNKNOWN RENDER TEMPLATE: '+ tpl_name)
|
||||||
|
return this.get(this.NOT_FOUND_TEMPLATE_ERROR).parse() }
|
||||||
|
|
||||||
// render template in context of page...
|
// render template in context of page...
|
||||||
var data = { render_root: this }
|
var data = { render_root: this }
|
||||||
@ -1355,6 +1372,8 @@ module.System = {
|
|||||||
text: 'RECURSION ERROR: @quote(../path)' },
|
text: 'RECURSION ERROR: @quote(../path)' },
|
||||||
NotFoundError: {
|
NotFoundError: {
|
||||||
text: 'NOT FOUND ERROR: @quote(./path)' },
|
text: 'NOT FOUND ERROR: @quote(./path)' },
|
||||||
|
NotFoundTemplateError: {
|
||||||
|
text: 'NOT FOUND TEMPLATE ERROR: @quote(../path)' },
|
||||||
|
|
||||||
DeletingPage: {
|
DeletingPage: {
|
||||||
text: 'Deleting: @source(../path)' },
|
text: 'Deleting: @source(../path)' },
|
||||||
@ -1381,23 +1400,21 @@ module.System = {
|
|||||||
return this.get('..').path },
|
return this.get('..').path },
|
||||||
location: function(){
|
location: function(){
|
||||||
return this.get('..').path },
|
return this.get('..').path },
|
||||||
|
// XXX this can be a list for pattern paths...
|
||||||
|
resolved: function(){
|
||||||
|
return this.get('..').resolve() },
|
||||||
dir: function(){
|
dir: function(){
|
||||||
return this.get('..').dir },
|
return this.get('..').dir },
|
||||||
name: function(){
|
name: function(){
|
||||||
return this.get('..').name },
|
return this.get('..').name },
|
||||||
ctime: function(){
|
|
||||||
return this.get('..').data.ctime ?? '' },
|
|
||||||
mtime: function(){
|
|
||||||
return this.get('..').data.mtime ?? '' },
|
|
||||||
|
|
||||||
// XXX this can be a list for pattern paths...
|
|
||||||
resolved: function(){
|
|
||||||
return this.get('..').resolve() },
|
|
||||||
|
|
||||||
title: function(){
|
title: function(){
|
||||||
var p = this.get('..')
|
var p = this.get('..')
|
||||||
return p.title
|
return p.title
|
||||||
?? p.name },
|
?? p.name },
|
||||||
|
ctime: function(){
|
||||||
|
return this.get('..').data.ctime ?? '' },
|
||||||
|
mtime: function(){
|
||||||
|
return this.get('..').data.mtime ?? '' },
|
||||||
|
|
||||||
|
|
||||||
// utils...
|
// utils...
|
||||||
@ -1437,6 +1454,42 @@ module.System = {
|
|||||||
// XXX broken...
|
// XXX broken...
|
||||||
test_list: function(){
|
test_list: function(){
|
||||||
return 'abcdef'.split('') },
|
return 'abcdef'.split('') },
|
||||||
|
test_slots: {
|
||||||
|
/* XXX
|
||||||
|
text: object.doc`
|
||||||
|
Sequential:
|
||||||
|
<slot name="sequential">unfilled</slot>
|
||||||
|
<slot name="sequential">filled</slot>
|
||||||
|
<slot name="sequential">refilled</slot>
|
||||||
|
<br><br>
|
||||||
|
Nested:
|
||||||
|
<slot name="nested">
|
||||||
|
unfilled
|
||||||
|
<slot name="nested">
|
||||||
|
filled
|
||||||
|
<slot name="nested">
|
||||||
|
refilled
|
||||||
|
</slot>
|
||||||
|
</slot>
|
||||||
|
</slot>
|
||||||
|
<br><br>
|
||||||
|
Content: A B C:
|
||||||
|
<slot name="slot-content">A</slot>
|
||||||
|
<slot name="slot-content"><content/> B</slot>
|
||||||
|
<slot name="slot-conten"><content/> C</slot>
|
||||||
|
<br><br>
|
||||||
|
//*/
|
||||||
|
text: object.doc`
|
||||||
|
Nested content: A B C:
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
A
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
<content/> B
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
<content/> C
|
||||||
|
</slot>
|
||||||
|
</slot>
|
||||||
|
</slot> ` },
|
||||||
}
|
}
|
||||||
|
|
||||||
var Settings =
|
var Settings =
|
||||||
|
|||||||
@ -392,6 +392,7 @@ module.BaseParser = {
|
|||||||
// <func>
|
// <func>
|
||||||
// | <promise>
|
// | <promise>
|
||||||
// | <string>
|
// | <string>
|
||||||
|
// | { skip: true, ... }
|
||||||
// | { data: <ast> }
|
// | { data: <ast> }
|
||||||
// | <ast>
|
// | <ast>
|
||||||
//
|
//
|
||||||
@ -422,6 +423,7 @@ module.BaseParser = {
|
|||||||
var {name, args, body} = value
|
var {name, args, body} = value
|
||||||
// nested macro -- skip...
|
// nested macro -- skip...
|
||||||
if(typeof(page.macros[name]) != 'function'){
|
if(typeof(page.macros[name]) != 'function'){
|
||||||
|
yield {...value, skip: true}
|
||||||
continue }
|
continue }
|
||||||
|
|
||||||
var res =
|
var res =
|
||||||
@ -451,10 +453,15 @@ module.BaseParser = {
|
|||||||
e.call(page, state)
|
e.call(page, state)
|
||||||
: e
|
: e
|
||||||
|
|
||||||
|
// expand arrays...
|
||||||
if(e instanceof Array){
|
if(e instanceof Array){
|
||||||
yield* this.resolve(page, e, state)
|
yield* this.resolve(page, e, state)
|
||||||
|
// data -- unwrap content...
|
||||||
} else if(e instanceof Object && 'data' in e){
|
} else if(e instanceof Object && 'data' in e){
|
||||||
yield { data: await this.resolve(page, e.data, state) }
|
yield { data: await this.resolve(page, e.data, state) }
|
||||||
|
// skipped items...
|
||||||
|
} else if(e instanceof Object && e.skip){
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
yield e } } },
|
yield e } } },
|
||||||
|
|
||||||
|
|||||||
@ -191,6 +191,22 @@ pwiki.pwiki
|
|||||||
refilled
|
refilled
|
||||||
</slot>
|
</slot>
|
||||||
</slot>
|
</slot>
|
||||||
|
</slot>
|
||||||
|
<br><br>
|
||||||
|
Content: A B C:
|
||||||
|
<slot name="slot-content">A</slot>
|
||||||
|
<slot name="slot-content"><content/> B</slot>
|
||||||
|
<slot name="slot-conten"><content/> C</slot>
|
||||||
|
<br><br>
|
||||||
|
Nested content: A B C:
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
A
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
<content/> B
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
<content/> C
|
||||||
|
</slot>
|
||||||
|
</slot>
|
||||||
</slot> `, })
|
</slot> `, })
|
||||||
.update({
|
.update({
|
||||||
location: '/test/nesting',
|
location: '/test/nesting',
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX might be a good idea for slots to support getting previous slot
|
* XXX slot <content/> does not work in nested slots...
|
||||||
* content, e.g.:
|
* XXX ranges in pattern paths...
|
||||||
* <slot name="header"><slot-content/> new text</slot>
|
* ...url syntax???
|
||||||
* XXX BUG?: markdown: when parsing chunks each chunk gets an open/closed
|
* XXX BUG?: markdown: when parsing chunks each chunk gets an open/closed
|
||||||
* <p> inserted at start/end -- this breaks stuff returned by macros...
|
* <p> inserted at start/end -- this breaks stuff returned by macros...
|
||||||
* ...there are two ways to dance around this:
|
* ...there are two ways to dance around this:
|
||||||
@ -43,7 +43,7 @@
|
|||||||
* - zip (json/tree) --
|
* - zip (json/tree) --
|
||||||
* - page actions
|
* - page actions
|
||||||
* - delete -- DONE
|
* - delete -- DONE
|
||||||
* - copy/move --
|
* - copy/move -- DONE
|
||||||
* - migrate bootstrap --
|
* - migrate bootstrap --
|
||||||
* - store topology --
|
* - store topology --
|
||||||
* - sync and sync conf --
|
* - sync and sync conf --
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user