reworked macro attr inheritance...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-10-30 15:38:42 +03:00
parent 82fb5fa9ac
commit b5a8214263
2 changed files with 58 additions and 32 deletions

View File

@ -1325,30 +1325,8 @@ object.Constructor('Page', BasePage, {
['strict', 'nonstrict', 'isolated', 'unisolated']],
async function*(args, body, state){
var that = this
var name = args.name //?? args[0]
var src = args.src
var base = this.get(this.path.split(/\*/).shift())
var sort = (args.sort ?? '')
.split(/\s+/g)
.filter(function(e){
return e != '' })
// NOTE: args.text will need parsing...
var text = args.text
?? body
?? []
text = typeof(text) == 'string' ?
[...this.__parser__.group(this, text+'</macro>', 'macro')]
: text
var strict = args.strict
&& !args.nonstrict
var isolated = args.isolated
|| !args.unisolated
var join
var depends = state.depends =
state.depends
?? new Set()
// helpers...
var _getBlock = function(name){
var block = args[name] ?
[{
@ -1369,18 +1347,66 @@ object.Constructor('Page', BasePage, {
?? block.body
return block }
if(name){
name = await base.parse(name, state)
var base = this.get(this.path.split(/\*/).shift())
var depends = state.depends =
state.depends
?? new Set()
// uninheritable args...
// NOTE: arg handling is split in two, to make things simpler
// to process for retrieved named macros...
var src = args.src
var text = args.text
?? body
?? []
text = typeof(text) == 'string' ?
[...this.__parser__.group(this, text+'</macro>', 'macro')]
: text
var join
var iargs = {}
// stored macros...
if(args.name){
var name = await base.parse(args.name, state)
// define new named macro...
if(text.length != 0){
// NOTE: we do not need to worry about saving
// stateful text here because it is only
// grouped and not expanded...
;(state.macros = state.macros ?? {})[name] = [text, _getBlock('join')]
;(state.macros = state.macros ?? {})[name] =
// XXX should we store all the args???
[text, _getBlock('join'), JSON.parse(JSON.stringify(args))]
// use existing macro...
} else if(state.macros
&& name in state.macros){
[text, join] = state.macros[name] } }
;[itext, join, iargs] = state.macros[name] } }
// XXX is there a point in overloading text???
text = text.length > 0 ?
text
: itext
// inheritable args...
var sort = (args.sort
?? iargs.sort
?? '')
.split(/\s+/g)
.filter(function(e){
return e != '' })
// default is false...
var strict =
('strict' in args || 'nonstrict' in args) ?
args.strict
&& !args.nonstrict
: iargs.strict
&& !iargs.nonstrict
// default is true...
var isolated =
('isolated' in args || 'unisolated' in args) ?
args.isolated
|| !args.unisolated
: iargs.isolated
|| !iargs.unisolated
if(src){
src = await base.parse(src, state)

View File

@ -18,11 +18,11 @@
* - CLI -
*
*
* XXX MACRO: should <macro>'s isolated be on by default???
* ...do we need to isolate named macros too???
* ...should this isolation be one-directional???
* ...i.e. iterations see/overload things defined above but
* can not affect the above context...
* XXX macro: bug: see /NamedMacroTest...
* XXX macro: should isolated and other args be inherited???
* XXX macro: should macro isolation be one-directional???
* ...i.e. iterations see/overload things defined above but
* can not affect the above context...
* XXX STYLE: should style loading be done via the event mechanics
* (see: pwiki2.html) or via the base templates (see: pwiki/page.js:_view
* template)???