From c28cd6a33624fc91650bc5e9d5e577ae4e862fcd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 5 Sep 2022 17:16:07 +0300 Subject: [PATCH] tweaking and experimenting... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 47 ++++++++++++++++++++++++++++++++++------------- pwiki2.js | 8 ++++++-- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index e99cd1b..6278870 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -95,6 +95,8 @@ object.Constructor('BasePage', { return this.name }, DIR: function(){ return this.dir }, + ARGS: function(){ + return pwpath.obj2args(this.args) }, //TITLE: function(){ // return this.title }, @@ -161,8 +163,6 @@ object.Constructor('BasePage', { && this.__navigate__() handle() }), - // .path is a proxy to .location - // XXX do we need this??? get path(){ return pwpath.splitArgs(this.location).path }, set path(value){ @@ -171,7 +171,11 @@ object.Constructor('BasePage', { get args(){ return pwpath.splitArgs(this.location).args }, set args(args){ - this.location = this.path +':'+ pwpath.obj2args(args) }, + args = pwpath.obj2args(args) ?? '' + this.location = + args == '' ? + '.' + : '.:'+ args }, // NOTE: these are mostly here as helpers to be accessed via page // actions... @@ -244,7 +248,7 @@ object.Constructor('BasePage', { if(this.actions && this.actions.has(this.name)){ var name = this.name - var page = this.get('..') + var page = this.get('..', {args: this.args}) var res = (this.isPattern && !this.__energetic && !page[name].energetic) ? @@ -281,7 +285,8 @@ object.Constructor('BasePage', { ?? (this.__title = res.title) //*/ return typeof(res) == 'function' ? - res.bind(this) + //res.bind(this) + res.bind(this.get('..', {args: this.args})) : res }).call(this) }, set data(value){ this.__update__(value) }, @@ -726,20 +731,32 @@ object.Constructor('Page', BasePage, { // [ ][ local]/> // [ default=][ local]/> // + // Resolution order: + // - local + // - .renderer + // - .root + // arg: Macro( ['name', 'default', ['local']], function(args){ - return this.args[args.name] + var v = this.args[args.name] || (!args.local - && this.root - && this.root.args[args.name]) + && (this.renderer + && this.renderer.args[args.name]) + || (this.root + && this.root.args[args.name])) + v = v === true ? + args.name + : v + return v || args.default }), '': Macro( ['name', 'default', ['local']], function(args){ return this.macros.arg.call(this, args) }), // XXX do we need this??? - 'args': function(){ + args: function(){ + console.log('!!!!') return pwpath.obj2args(this.args) }, // // @filter() @@ -1418,7 +1435,7 @@ object.Constructor('Page', BasePage, { || path.push(this.PAGE_TEMPLATE) var tpl = pwpath.join(path) var tpl_name = path.pop() - path = pwpath.joinArgs(path, this.args) + //path = pwpath.joinArgs(path, this.args) // get the template relative to the top most pattern... tpl = await this.get(tpl).find(true) @@ -1432,7 +1449,11 @@ object.Constructor('Page', BasePage, { // this is here for debugging and introspection... '__debug_last_render_state' in this && (this.__debug_last_render_state = state) - var data = { renderer: this } + //var data = { renderer: this } + var data = { + renderer: this, + args: this.args, + } return this.get(path, data) .parse( this.get('/'+tpl, data).raw, @@ -1714,7 +1735,7 @@ module.System = { // // XXX all of these should support pattern pages... _text: { - text: '@include(. isolated join="@source(file-separator)")' }, + text: '@include(.:$ARGS isolated join="@source(file-separator)")' }, // XXX /rootpath here is not relative -- makes reuse harder... _view: { text: object.doc` @@ -1730,7 +1751,7 @@ module.System = { ` }, // XXX add join... _raw: { diff --git a/pwiki2.js b/pwiki2.js index 3608812..3cfcdbd 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,6 +1,9 @@ /********************************************************************** * * +* XXX BUG: this does not call the args macro... +* await pwiki.get('/path/testDirect:x:y:z').parse('') +* ...syntax checking is done correctly though... * XXX ARGS: arg passing is a mess... * - need a consistent way to access args * - global @@ -19,10 +22,9 @@ * // XXX for .text and .parse(..), the action is called twice... * // root path: /System/testAction:a:b:c * await pwiki.get('/path/testDirect:x:y:z').raw -* .args - empty +* .args - x y z * .renderer.args - a b c * .root.args - a b c -* XXX seem to be losing args on this path... * await pwiki.get('/path/testAction:x:y:z').raw * .args - x y z * .renderer.args - a b c @@ -31,6 +33,8 @@ * .args - empty * .renderer.args - x y z * .root.args - a b c +* XXX args should be local... +* ... @include(.:$ARGS) not working??? * XXX triggered twice... * await pwiki.get('/path/testAction:x:y:z').text * .args - empty