tweaking and experimenting...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-05 17:16:07 +03:00
parent ac90f4c9dc
commit c28cd6a336
2 changed files with 40 additions and 15 deletions

View File

@ -95,6 +95,8 @@ object.Constructor('BasePage', {
return this.name }, return this.name },
DIR: function(){ DIR: function(){
return this.dir }, return this.dir },
ARGS: function(){
return pwpath.obj2args(this.args) },
//TITLE: function(){ //TITLE: function(){
// return this.title }, // return this.title },
@ -161,8 +163,6 @@ object.Constructor('BasePage', {
&& this.__navigate__() && this.__navigate__()
handle() }), handle() }),
// .path is a proxy to .location
// XXX do we need this???
get path(){ get path(){
return pwpath.splitArgs(this.location).path }, return pwpath.splitArgs(this.location).path },
set path(value){ set path(value){
@ -171,7 +171,11 @@ object.Constructor('BasePage', {
get args(){ get args(){
return pwpath.splitArgs(this.location).args }, return pwpath.splitArgs(this.location).args },
set args(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 // NOTE: these are mostly here as helpers to be accessed via page
// actions... // actions...
@ -244,7 +248,7 @@ object.Constructor('BasePage', {
if(this.actions if(this.actions
&& this.actions.has(this.name)){ && this.actions.has(this.name)){
var name = this.name var name = this.name
var page = this.get('..') var page = this.get('..', {args: this.args})
var res = (this.isPattern var res = (this.isPattern
&& !this.__energetic && !this.__energetic
&& !page[name].energetic) ? && !page[name].energetic) ?
@ -281,7 +285,8 @@ object.Constructor('BasePage', {
?? (this.__title = res.title) ?? (this.__title = res.title)
//*/ //*/
return typeof(res) == 'function' ? return typeof(res) == 'function' ?
res.bind(this) //res.bind(this)
res.bind(this.get('..', {args: this.args}))
: res }).call(this) }, : res }).call(this) },
set data(value){ set data(value){
this.__update__(value) }, this.__update__(value) },
@ -726,20 +731,32 @@ object.Constructor('Page', BasePage, {
// <arg <name>[ <default>][ local]/> // <arg <name>[ <default>][ local]/>
// <arg name=<name>[ default=<value>][ local]/> // <arg name=<name>[ default=<value>][ local]/>
// //
// Resolution order:
// - local
// - .renderer
// - .root
//
arg: Macro( arg: Macro(
['name', 'default', ['local']], ['name', 'default', ['local']],
function(args){ function(args){
return this.args[args.name] var v = this.args[args.name]
|| (!args.local || (!args.local
&& this.root && (this.renderer
&& this.root.args[args.name]) && this.renderer.args[args.name])
|| (this.root
&& this.root.args[args.name]))
v = v === true ?
args.name
: v
return v
|| args.default }), || args.default }),
'': Macro( '': Macro(
['name', 'default', ['local']], ['name', 'default', ['local']],
function(args){ function(args){
return this.macros.arg.call(this, args) }), return this.macros.arg.call(this, args) }),
// XXX do we need this??? // XXX do we need this???
'args': function(){ args: function(){
console.log('!!!!')
return pwpath.obj2args(this.args) }, return pwpath.obj2args(this.args) },
// //
// @filter(<filter-spec>) // @filter(<filter-spec>)
@ -1418,7 +1435,7 @@ object.Constructor('Page', BasePage, {
|| path.push(this.PAGE_TEMPLATE) || path.push(this.PAGE_TEMPLATE)
var tpl = pwpath.join(path) var tpl = pwpath.join(path)
var tpl_name = path.pop() 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... // get the template relative to the top most pattern...
tpl = await this.get(tpl).find(true) tpl = await this.get(tpl).find(true)
@ -1432,7 +1449,11 @@ object.Constructor('Page', BasePage, {
// this is here for debugging and introspection... // this is here for debugging and introspection...
'__debug_last_render_state' in this '__debug_last_render_state' in this
&& (this.__debug_last_render_state = state) && (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) return this.get(path, data)
.parse( .parse(
this.get('/'+tpl, data).raw, this.get('/'+tpl, data).raw,
@ -1714,7 +1735,7 @@ module.System = {
// //
// XXX all of these should support pattern pages... // XXX all of these should support pattern pages...
_text: { _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... // XXX /rootpath here is not relative -- makes reuse harder...
_view: { _view: {
text: object.doc` text: object.doc`
@ -1730,7 +1751,7 @@ module.System = {
<!-- fill slots defaults --> <!-- fill slots defaults -->
<slot name="content" hidden> <slot name="content" hidden>
@include(. join="@source(file-separator)" recursive="") @include(.:$ARGS join="@source(file-separator)" recursive="")
</slot>` }, </slot>` },
// XXX add join... // XXX add join...
_raw: { _raw: {

View File

@ -1,6 +1,9 @@
/********************************************************************** /**********************************************************************
* *
* *
* XXX BUG: this does not call the args macro...
* await pwiki.get('/path/testDirect:x:y:z').parse('<args/>')
* ...syntax checking is done correctly though...
* XXX ARGS: arg passing is a mess... * XXX ARGS: arg passing is a mess...
* - need a consistent way to access args * - need a consistent way to access args
* - global * - global
@ -19,10 +22,9 @@
* // XXX for .text and .parse(..), the action is called twice... * // XXX for .text and .parse(..), the action is called twice...
* // root path: /System/testAction:a:b:c * // root path: /System/testAction:a:b:c
* await pwiki.get('/path/testDirect:x:y:z').raw * await pwiki.get('/path/testDirect:x:y:z').raw
* .args - empty * .args - x y z
* .renderer.args - a b c * .renderer.args - a b c
* .root.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 * await pwiki.get('/path/testAction:x:y:z').raw
* .args - x y z * .args - x y z
* .renderer.args - a b c * .renderer.args - a b c
@ -31,6 +33,8 @@
* .args - empty * .args - empty
* .renderer.args - x y z * .renderer.args - x y z
* .root.args - a b c * .root.args - a b c
* XXX args should be local...
* ... @include(.:$ARGS) not working???
* XXX triggered twice... * XXX triggered twice...
* await pwiki.get('/path/testAction:x:y:z').text * await pwiki.get('/path/testAction:x:y:z').text
* .args - empty * .args - empty