making things a bit more intuitive -- location/argstr actions now inherit parent arguments by default...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-17 13:26:49 +03:00
parent c4b77f231f
commit 1e32383c26
2 changed files with 53 additions and 10 deletions

View File

@ -63,6 +63,7 @@ object.Constructor('BasePage', {
'path', 'path',
'name', 'name',
'dir', 'dir',
'argstr',
'title', 'title',
'resolved', 'resolved',
'rootpath', 'rootpath',
@ -71,6 +72,13 @@ object.Constructor('BasePage', {
'ctime', 'ctime',
'mtime', 'mtime',
]), ]),
// These actions will be default get :$ARGS appended if no args are
// explicitly given...
// XXX INHERIT_ARGS
actions_inherit_args: new Set([
'location',
'argstr',
]),
// NOTE: this can be inherited... // NOTE: this can be inherited...
@ -854,6 +862,11 @@ object.Constructor('Page', BasePage, {
await base.parse(args.src, state)) await base.parse(args.src, state))
if(!src){ if(!src){
return } return }
// XXX INHERIT_ARGS special-case: inherit args by default...
if(this.actions_inherit_args
&& this.actions_inherit_args.has(pwpath.basename(src))
&& this.get(pwpath.dirname(src)).path == this.path){
src += ':$ARGS' }
var recursive = args.recursive ?? body var recursive = args.recursive ?? body
var isolated = args.isolated var isolated = args.isolated
var strict = args.strict var strict = args.strict
@ -972,6 +985,11 @@ object.Constructor('Page', BasePage, {
src = src ? src = src ?
await base.parse(src, state) await base.parse(src, state)
: src : src
// XXX INHERIT_ARGS special-case: inherit args by default...
if(this.actions_inherit_args
&& this.actions_inherit_args.has(pwpath.basename(src))
&& this.get(pwpath.dirname(src)).path == this.path){
src += ':$ARGS' }
var expandactions = args.expandactions var expandactions = args.expandactions
var depends = state.depends = var depends = state.depends =
@ -1227,12 +1245,20 @@ object.Constructor('Page', BasePage, {
[text, join] = state.macros[name] } } [text, join] = state.macros[name] } }
if(src){ if(src){
src = await base.parse(src, state)
// XXX INHERIT_ARGS special-case: inherit args by default...
if(this.actions_inherit_args
&& this.actions_inherit_args.has(pwpath.basename(src))
&& this.get(pwpath.dirname(src)).path == this.path){
src += ':$ARGS' }
join = _getBlock('join') join = _getBlock('join')
?? join ?? join
join = join join = join
&& await base.parse(join, state) && await base.parse(join, state)
var match = this.get(await base.parse(src, state)) //var match = this.get(await base.parse(src, state))
var match = this.get(src)
// NOTE: thie does not introduce a dependency on each // NOTE: thie does not introduce a dependency on each
// of the iterated pages, that is handled by the // of the iterated pages, that is handled by the
@ -1744,14 +1770,14 @@ module.System = {
// XXX /rootpath here is not relative -- makes reuse harder... // XXX /rootpath here is not relative -- makes reuse harder...
_view: { _view: {
// XXX can we avoid explicitly passing args to ./location ???? // XXX can we avoid explicitly passing args to ./location ????
// i.e.: // i.e. do:
// <a href="#@source(./location)">@source(./path)</a> // @source(./location)
// instead of (current): // instead of (current):
// <a href="#@source(./location:$ARGS)">@source(./path)</a> // @source(./location:$ARGS)
text: object.doc` text: object.doc`
<slot name="header"> <slot name="header">
<a href="#/list">&#9776</a> <a href="#/list">&#9776</a>
<a href="#@source(./location)">@source(./path)</a> @source(./location)
<a href="#@source(./path)/_edit">&#9998;</a> <a href="#@source(./path)/_edit">&#9998;</a>
</slot> </slot>
<hr> <hr>

View File

@ -1,11 +1,28 @@
/********************************************************************** /**********************************************************************
* *
* *
* XXX can we avoid explicitly passing args to ./location ???? * XXX EXPERIMENTAL DOC INHERIT_ARGS added a special-case...
* i.e.: * as basename will get appended :$ARGS if no args are given...
* <a href="#@source(./location)">@source(./path)</a> * ...this only applies to paths referring to the current context
* instead of (current): * page, i.e.:
* <a href="#@source(./location:$ARGS)">@source(./path)</a> * await pwiki
* .get('/page:x:y:z')
* // this will get the args...
* .parse('@source(./location)')
*
* await pwiki
* .get('/page:x:y:z')
* // this will not get the args -- different page...
* .parse('@source(./x/location)')
*
* await pwiki
* .get('/page:x:y:z')
* // this will get explicitly given empty args...
* .parse('@source(./location:)')
*
* special args that auto-inherit are given in .actions_inherit_args
* XXX this is currently implemented on the level of macro parsing,
* should this be in a more general way???
* XXX BUG: * XXX BUG:
* /System/info * /System/info
* and: * and: