mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-30 18:40:08 +00:00
cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b35a8ad346
commit
f2bf23f0d9
@ -663,11 +663,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
// XXX should we use .__parser__.expand(..) instead of .parse(..) ???
|
// XXX should we use .__parser__.expand(..) instead of .parse(..) ???
|
||||||
include: Macro(
|
include: Macro(
|
||||||
['src', 'recursive', 'join', ['isolated']],
|
['src', 'recursive', 'join', ['isolated']],
|
||||||
// XXX GENERATOR...
|
|
||||||
async function*(args, body, state, key='included', handler){
|
async function*(args, body, state, key='included', handler){
|
||||||
/*/
|
|
||||||
async function(args, body, state, key='included', handler){
|
|
||||||
//*/
|
|
||||||
var macro = 'include'
|
var macro = 'include'
|
||||||
if(typeof(args) == 'string'){
|
if(typeof(args) == 'string'){
|
||||||
var [macro, args, body, state, key, handler] = arguments
|
var [macro, args, body, state, key, handler] = arguments
|
||||||
@ -691,12 +687,12 @@ object.Constructor('Page', BasePage, {
|
|||||||
: this.get(src)
|
: this.get(src)
|
||||||
.parse(state) }
|
.parse(state) }
|
||||||
|
|
||||||
//* XXX GENERATOR...
|
|
||||||
var first = true
|
var first = true
|
||||||
for(var page of await this.get(src).each()){
|
for await (var page of this.get(src).each()){
|
||||||
if(!first){
|
if(!first){
|
||||||
yield join }
|
yield join }
|
||||||
first = false
|
first = false
|
||||||
|
|
||||||
var full = page.path
|
var full = page.path
|
||||||
|
|
||||||
// handle recursion...
|
// handle recursion...
|
||||||
@ -732,60 +728,14 @@ object.Constructor('Page', BasePage, {
|
|||||||
delete state.seen }
|
delete state.seen }
|
||||||
|
|
||||||
yield res } }),
|
yield res } }),
|
||||||
/*/
|
|
||||||
var res = this.get(src)
|
|
||||||
.each()
|
|
||||||
.map(async function(page){
|
|
||||||
var full = page.path
|
|
||||||
|
|
||||||
// handle recursion...
|
|
||||||
var parent_seen = 'seen' in state
|
|
||||||
var seen = state.seen =
|
|
||||||
new Set(state.seen ?? [])
|
|
||||||
// recursion detected...
|
|
||||||
if(seen.has(full)
|
|
||||||
// nesting path recursion...
|
|
||||||
// XXX a more general way to check would be to see if the
|
|
||||||
// path resolves to the same source (done below) and
|
|
||||||
// check if the context has changed -- i.e. if the paths
|
|
||||||
// actually contain anything...
|
|
||||||
|| (seen.size % (this.NESTING_RECURSION_THRESHOLD || 10) == 0
|
|
||||||
&& new Set([...seen]
|
|
||||||
.map(function(p){
|
|
||||||
return page.get(p).match()[0] }))
|
|
||||||
.size < seen.size)){
|
|
||||||
if(recursive == null){
|
|
||||||
return page.get(page.RECURSION_ERROR).parse(state) }
|
|
||||||
// have the 'recursive' arg...
|
|
||||||
return base.parse(recursive, state) }
|
|
||||||
seen.add(full)
|
|
||||||
|
|
||||||
// load the included page...
|
|
||||||
var res = await handler.call(page, full)
|
|
||||||
|
|
||||||
// NOTE: we only track recursion down and not sideways...
|
|
||||||
seen.delete(full)
|
|
||||||
if(!parent_seen){
|
|
||||||
delete state.seen }
|
|
||||||
|
|
||||||
return res })
|
|
||||||
return join ?
|
|
||||||
res.between(join)
|
|
||||||
: res }),
|
|
||||||
//*/
|
|
||||||
// NOTE: the main difference between this and @include is that
|
// NOTE: the main difference between this and @include is that
|
||||||
// this renders the src in the context of current page while
|
// this renders the src in the context of current page while
|
||||||
// include is rendered in the context of its page but with
|
// include is rendered in the context of its page but with
|
||||||
// the same state...
|
// the same state...
|
||||||
source: Macro(
|
source: Macro(
|
||||||
['src'],
|
['src'],
|
||||||
// XXX GENERATOR...
|
|
||||||
async function*(args, body, state){
|
async function*(args, body, state){
|
||||||
yield* this.macros.include.call(this,
|
yield* this.macros.include.call(this,
|
||||||
/*/
|
|
||||||
async function(args, body, state){
|
|
||||||
return this.macros.include.call(this,
|
|
||||||
//*/
|
|
||||||
'source',
|
'source',
|
||||||
args, body, state, 'sources',
|
args, body, state, 'sources',
|
||||||
async function(src){
|
async function(src){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user