refactoring and bugfixing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-11-05 15:22:00 +03:00
parent 9a0b8d1ad2
commit 2cba0b91f0
2 changed files with 27 additions and 33 deletions

View File

@ -1551,36 +1551,37 @@ object.Constructor('Page', BasePage, {
'no' 'no'
: value } : value }
// XXX COUNT
// handle count... // handle count...
// NOTE: this duplicates <store>.match(..)'s functionality // NOTE: this duplicates <store>.match(..)'s functionality
// because we need to account for arbitrary macro // because we need to account for arbitrary macro
// nesting that .match(..) does not know about... // nesting that .match(..) does not know about...
// XXX we still end up with NaN in some cases... // XXX revise var naming...
var count = pwpath.splitArgs(src).args.count // XXX these can be overriden in nested macros...
if(count == 'inherit' var count = match.args.count
&& !('macro:count' in vars)){ if(count){
vars['macro:count'] = var c =
vars['macro:count'] count == 'inherit' ?
?? parseInt(this.args.count) } (!('macro:count' in vars) ?
if(count this.args.count
&& count != 'inherit'){ : undefined)
vars['macro:count'] = parseInt(count) } : count
//*/ if(c !== undefined){
vars['macro:count'] =
isNaN(parseInt(c)) ?
c
: parseInt(c)
vars['macro:index'] = 0 } }
// expand matches... // expand matches...
var first = true var first = true
for await(var page of match.asPages(strict)){ for await(var page of match.asPages(strict)){
// XXX COUNT
// handle count... // handle count...
if(vars['macro:count'] <= 0){
break }
if('macro:count' in vars){ if('macro:count' in vars){
var v = vars if(vars['macro:count'] <= vars['macro:index']){
while(!v.hasOwnProperty('macro:count')){ break }
v = v.__proto__ } object.sources(vars, 'macro:index')
v['macro:count']-- } .shift()['macro:index']++ }
//*/ // output join between elements....
if(join && !first){ if(join && !first){
yield join } yield join }
first = false first = false
@ -1602,9 +1603,9 @@ object.Constructor('Page', BasePage, {
text, _state), _state) text, _state), _state)
} else { } else {
yield this.__parser__.expand(page, text, state) } } yield this.__parser__.expand(page, text, state) } }
// XXX COUNT
// cleanup... // cleanup...
delete vars['macro:count'] delete vars['macro:count']
delete vars['macro:index']
// else... // else...
if(first if(first
&& (text || args['else'])){ && (text || args['else'])){
@ -2311,8 +2312,7 @@ module.System = {
<slot title/> <slot title/>
<!--@var(count "@(count)")--> <!--@var(count "@(count)")-->
<!--macro tree src="../*:$ARGS"--> <macro tree src="../*:$ARGS">
<macro tree src="../*:$ARGS:count=inherit">
@var(path "@source(s ./path)") @var(path "@source(s ./path)")
<div> <div>
<div class="item"> <div class="item">

View File

@ -25,18 +25,12 @@
* - * -
* *
* *
* XXX not yet sure why /tree's root macro needs to have count=inherit... * XXX macro: macro:count / macro:index vars can be overridden by count/index
* for an example see: * attributes....
* /Tests/MacroPageCountInheritTest:count=3 * ...this needs testing...
* ...adding :count=inherit after $ARGS fixes the issue...
* not sure why this works in this context:
* /Tests/MacroCountTest
* XXX should @macro(..) handle offset in the same manner as count??? * 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 BUG: count does not appear to affext /Test/list/generator and /Test/list/static...
* XXX macros: should vars and url args be unified??? * ...do we need to support this???
* ...likely no but need tho think about it some more...
* XXX should @quote(..)'s expandactions be on by default???
* XXX FEATURE store: mirror (slave) -- a way to hold data in one store * XXX FEATURE store: mirror (slave) -- a way to hold data in one store
* and to mirror everything (async) to a separate store... * and to mirror everything (async) to a separate store...
* example: * example: