mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 16:41:39 +00:00
reworked count handling by @macro(..), still tweaking and fixing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
dd82f4fa53
commit
9a0b8d1ad2
@ -1299,29 +1299,70 @@ object.Constructor('Page', BasePage, {
|
|||||||
'content': ['slot'],
|
'content': ['slot'],
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
|
// XXX INC_DEC do we need inc/dec and parent???
|
||||||
'var': Macro(
|
'var': Macro(
|
||||||
['name', 'text',
|
['name', 'text',
|
||||||
|
// XXX INC_DEC
|
||||||
|
['shown', 'hidden', 'inc', 'dec', 'parent']],
|
||||||
|
/*/
|
||||||
['shown', 'hidden']],
|
['shown', 'hidden']],
|
||||||
|
//*/
|
||||||
async function(args, body, state){
|
async function(args, body, state){
|
||||||
var name = args.name
|
var name = args.name
|
||||||
if(!name){
|
if(!name){
|
||||||
return '' }
|
return '' }
|
||||||
name = await this.parse(name, state)
|
name = await this.parse(name, state)
|
||||||
|
// XXX INC_DEC
|
||||||
|
var inc = args.inc
|
||||||
|
var dec = args.dec
|
||||||
|
//*/
|
||||||
var text = args.text
|
var text = args.text
|
||||||
?? body
|
?? body
|
||||||
|
// NOTE: .hidden has priority...
|
||||||
|
var show =
|
||||||
|
('hidden' in args ?
|
||||||
|
!args.hidden
|
||||||
|
: undefined)
|
||||||
|
?? args.shown
|
||||||
|
|
||||||
var vars = state.vars =
|
var vars = state.vars =
|
||||||
state.vars
|
state.vars
|
||||||
?? {}
|
?? {}
|
||||||
|
// XXX INC_DEC
|
||||||
|
if(args.parent && name in vars){
|
||||||
|
while(!vars.hasOwnProperty(name)
|
||||||
|
&& vars.__proto__ !== Object.prototype){
|
||||||
|
vars = vars.__proto__ } }
|
||||||
|
|
||||||
|
// inc/dec...
|
||||||
|
if(inc || dec){
|
||||||
|
if(!(name in vars)
|
||||||
|
|| isNaN(parseInt(vars[name]))){
|
||||||
|
return '' }
|
||||||
|
var cur = parseInt(vars[name])
|
||||||
|
cur +=
|
||||||
|
inc === true ?
|
||||||
|
1
|
||||||
|
: !inc ?
|
||||||
|
0
|
||||||
|
: parseInt(inc)
|
||||||
|
cur -=
|
||||||
|
dec === true ?
|
||||||
|
1
|
||||||
|
: !dec ?
|
||||||
|
0
|
||||||
|
: parseInt(dec)
|
||||||
|
vars[name] = cur + ''
|
||||||
|
return show ?? true ?
|
||||||
|
vars[name]
|
||||||
|
: '' }
|
||||||
|
//*/
|
||||||
|
|
||||||
// set...
|
// set...
|
||||||
if(text){
|
if(text){
|
||||||
text = vars[name] =
|
text = vars[name] =
|
||||||
await this.parse(text, state)
|
await this.parse(text, state)
|
||||||
var show = args.shown
|
return show ?? false ?
|
||||||
|| ('hidden' in args
|
|
||||||
&& !args.hidden)
|
|
||||||
|| false
|
|
||||||
return show ?
|
|
||||||
text
|
text
|
||||||
: ''
|
: ''
|
||||||
// get...
|
// get...
|
||||||
@ -1359,7 +1400,13 @@ object.Constructor('Page', BasePage, {
|
|||||||
// </else>
|
// </else>
|
||||||
// </macro>
|
// </macro>
|
||||||
//
|
//
|
||||||
// XXX SORT sorting not implemented yet....
|
// NOTE: this handles src count argument internally partially
|
||||||
|
// overriding <store>.match(..)'s implementation, this is done
|
||||||
|
// because @macro(..) needs to account for arbitrary nesting
|
||||||
|
// that <store>.match(..) can not know about...
|
||||||
|
// XXX should we do the same for offset???
|
||||||
|
//
|
||||||
|
// XXX SORT sorting not implemented yet...
|
||||||
macro: Macro(
|
macro: Macro(
|
||||||
['name', 'src', 'sort', 'text', 'join', 'else',
|
['name', 'src', 'sort', 'text', 'join', 'else',
|
||||||
['strict', 'isolated', 'inheritmacros', 'inheritvars' ]],
|
['strict', 'isolated', 'inheritmacros', 'inheritvars' ]],
|
||||||
@ -1504,9 +1551,36 @@ object.Constructor('Page', BasePage, {
|
|||||||
'no'
|
'no'
|
||||||
: value }
|
: value }
|
||||||
|
|
||||||
|
// XXX COUNT
|
||||||
|
// handle count...
|
||||||
|
// NOTE: this duplicates <store>.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) }
|
||||||
|
//*/
|
||||||
|
|
||||||
// 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...
|
||||||
|
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(join && !first){
|
if(join && !first){
|
||||||
yield join }
|
yield join }
|
||||||
first = false
|
first = false
|
||||||
@ -1528,6 +1602,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...
|
||||||
|
delete vars['macro:count']
|
||||||
// else...
|
// else...
|
||||||
if(first
|
if(first
|
||||||
&& (text || args['else'])){
|
&& (text || args['else'])){
|
||||||
@ -2226,11 +2303,16 @@ module.System = {
|
|||||||
// ...for this we'll need to be able to either:
|
// ...for this we'll need to be able to either:
|
||||||
// - count our own pages or
|
// - count our own pages or
|
||||||
// - keep a global count
|
// - keep a global count
|
||||||
|
// ...with offset the issue is not solvable because we will not
|
||||||
|
// see/count the children of skipped nodes -- the only way to
|
||||||
|
// solve this is to completely handle offset in macro...
|
||||||
tree: {
|
tree: {
|
||||||
text: object.doc`
|
text: object.doc`
|
||||||
<slot title/>
|
<slot title/>
|
||||||
|
<!--@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">
|
||||||
@ -2241,7 +2323,7 @@ module.System = {
|
|||||||
>×</a>
|
>×</a>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding-left: 30px">
|
<div style="padding-left: 30px">
|
||||||
@macro(tree "./*:$ARGS")
|
@macro(tree "./*:$ARGS:count=inherit")
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</macro>` },
|
</macro>` },
|
||||||
|
|||||||
@ -35,7 +35,7 @@ module.BaseParser = {
|
|||||||
//
|
//
|
||||||
MACRO_ARGS: ['(\\s*(',[
|
MACRO_ARGS: ['(\\s*(',[
|
||||||
// arg='val' | arg="val" | arg=val
|
// arg='val' | arg="val" | arg=val
|
||||||
'(?<PREFIXArgName>[a-z:-]+)\\s*=\\s*(?<PREFIXArgValue>'+([
|
'(?<PREFIXArgName>[a-z:-_]+)\\s*=\\s*(?<PREFIXArgValue>'+([
|
||||||
// XXX CHROME/NODE BUG: this does not work yet...
|
// XXX CHROME/NODE BUG: this does not work yet...
|
||||||
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
|
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
|
||||||
'"(?<PREFIXDoubleQuotedValue>(\\"|[^"])*?)"',
|
'"(?<PREFIXDoubleQuotedValue>(\\"|[^"])*?)"',
|
||||||
@ -539,6 +539,13 @@ module.BaseParser = {
|
|||||||
return await this.resolve(page, ast, state)
|
return await this.resolve(page, ast, state)
|
||||||
// filters...
|
// filters...
|
||||||
.map(function(section){
|
.map(function(section){
|
||||||
|
// normalize types...
|
||||||
|
section =
|
||||||
|
typeof(section) == 'number' ?
|
||||||
|
section + ''
|
||||||
|
: section == null ?
|
||||||
|
''
|
||||||
|
: section
|
||||||
return (
|
return (
|
||||||
// expand section...
|
// expand section...
|
||||||
typeof(section) != 'string' ?
|
typeof(section) != 'string' ?
|
||||||
|
|||||||
11
pwiki2.js
11
pwiki2.js
@ -25,8 +25,15 @@
|
|||||||
* -
|
* -
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX macro-vars: should the vars be defined as macro:<name> (current) or
|
* XXX not yet sure why /tree's root macro needs to have count=inherit...
|
||||||
* simply as <name>???
|
* 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 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???
|
* XXX macros: should vars and url args be unified???
|
||||||
* ...likely no but need tho think about it some more...
|
* ...likely no but need tho think about it some more...
|
||||||
* XXX should @quote(..)'s expandactions be on by default???
|
* XXX should @quote(..)'s expandactions be on by default???
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user