From 2cba0b91f0198f7957f15ebf0d0e5d37859baedd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 5 Nov 2022 15:22:00 +0300 Subject: [PATCH] refactoring and bugfixing... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 46 +++++++++++++++++++++++----------------------- pwiki2.js | 14 ++++---------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index 0436055..a0d3ee1 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -1551,36 +1551,37 @@ object.Constructor('Page', BasePage, { 'no' : value } - // XXX COUNT // handle count... // NOTE: this duplicates .match(..)'s functionality // because we need to account for arbitrary macro // nesting that .match(..) does not know about... - // XXX we still end up with NaN in some cases... - var count = pwpath.splitArgs(src).args.count - if(count == 'inherit' - && !('macro:count' in vars)){ - vars['macro:count'] = - vars['macro:count'] - ?? parseInt(this.args.count) } - if(count - && count != 'inherit'){ - vars['macro:count'] = parseInt(count) } - //*/ + // XXX revise var naming... + // XXX these can be overriden in nested macros... + var count = match.args.count + if(count){ + var c = + count == 'inherit' ? + (!('macro:count' in vars) ? + this.args.count + : undefined) + : count + if(c !== undefined){ + vars['macro:count'] = + isNaN(parseInt(c)) ? + c + : parseInt(c) + vars['macro:index'] = 0 } } // expand matches... var first = true for await(var page of match.asPages(strict)){ - // XXX COUNT // handle count... - if(vars['macro:count'] <= 0){ - break } if('macro:count' in vars){ - var v = vars - while(!v.hasOwnProperty('macro:count')){ - v = v.__proto__ } - v['macro:count']-- } - //*/ + if(vars['macro:count'] <= vars['macro:index']){ + break } + object.sources(vars, 'macro:index') + .shift()['macro:index']++ } + // output join between elements.... if(join && !first){ yield join } first = false @@ -1602,9 +1603,9 @@ object.Constructor('Page', BasePage, { text, _state), _state) } else { yield this.__parser__.expand(page, text, state) } } - // XXX COUNT // cleanup... delete vars['macro:count'] + delete vars['macro:index'] // else... if(first && (text || args['else'])){ @@ -2311,8 +2312,7 @@ module.System = { - - + @var(path "@source(s ./path)")
diff --git a/pwiki2.js b/pwiki2.js index 3d511e4..90de9fc 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -25,18 +25,12 @@ * - * * -* XXX not yet sure why /tree's root macro needs to have count=inherit... -* for an example see: -* /Tests/MacroPageCountInheritTest:count=3 -* ...adding :count=inherit after $ARGS fixes the issue... -* not sure why this works in this context: -* /Tests/MacroCountTest +* XXX macro: macro:count / macro:index vars can be overridden by count/index +* attributes.... +* ...this needs testing... * XXX should @macro(..) handle offset in the same manner as count??? -* XXX BUG: @var(macro:count) can still be NaN in some cases... * XXX BUG: count does not appear to affext /Test/list/generator and /Test/list/static... -* XXX macros: should vars and url args be unified??? -* ...likely no but need tho think about it some more... -* XXX should @quote(..)'s expandactions be on by default??? +* ...do we need to support this??? * XXX FEATURE store: mirror (slave) -- a way to hold data in one store * and to mirror everything (async) to a separate store... * example: