From 12c602ff653359a5b98b1ff9af9c4bc7810ad4db Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 30 Aug 2022 10:58:04 +0300 Subject: [PATCH] added energetic actions (experimental)... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 37 +++++++++--------- pwiki/store/base.js | 6 ++- pwiki2.js | 92 ++++++++++++++++++++++----------------------- 3 files changed, 67 insertions(+), 68 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index 1bcf1e4..560dc3d 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -166,18 +166,21 @@ object.Constructor('BasePage', { // page data... // strict: undefined, + energetic: undefined, get data(){ return (async function(){ var that = this // NOTE: we need to make sure each page gets the chance to handle // its context (i.e. bind action to page).... if(this.isPattern // XXX ENERGETIC... - && !this.store.isEnergetic(this.path)){ + && !(this.energetic + || await this.store.isEnergetic(this.path))){ return this .map(function(page){ return page.data }) } // single page... - var res = await this.store.get(this.location, !!this.strict) + // XXX ENERGETIC... + var res = await this.store.get(this.location, !!this.strict, !!this.energetic) return typeof(res) == 'function' ? res.bind(this) : res }).call(this) }, @@ -299,7 +302,8 @@ object.Constructor('BasePage', { : this.path var paths = path.includes('*') // XXX ENERGETIC... - && !await this.store.isEnergetic(path) ? + && !(this.energetic + || await this.store.isEnergetic(path)) ? this.resolve(path) : path paths = paths instanceof Array ? @@ -1527,9 +1531,9 @@ module.System = { _view: { text: object.doc` - - @source(./!path) - (edit) + + @source(./path/!) + (edit)
@@ -1611,7 +1615,7 @@ module.System = { list: { text: object.doc` - /list + @source(../path) @@ -1625,7 +1629,7 @@ module.System = { - (@include(./*/!count)) + (@include(./*/count/!))   × ` }, @@ -1712,11 +1716,6 @@ module.System = { return this.get('..').location }, path: function(){ return this.get('..').path }, - // XXX ENERGETIC... - '!path': Object.assign( - function(){ - return this.get('..').path }, - {energetic: true}), rootpath: function(){ return this.root.path }, resolved: async function(){ @@ -1731,11 +1730,6 @@ module.System = { ?? p.name }, count: async function(){ return this.get('..').length }, - // XXX ENERGETIC... - '!count': Object.assign( - async function(){ - return this.get('..').length }, - {energetic: true}), ctime: async function(){ var date = (await this.get('..').data).ctime return date ? @@ -1747,6 +1741,13 @@ module.System = { (new Date(date)).getTimeStamp() : date }, + // XXX ENERGETIC -- a better name??? + // XXX test this with pages... + '!': Object.assign( + async function(){ + return this.get('..', {energetic: true}).raw }, + {energetic: true}), + // XXX EXPERIMENTAL -- page types... type: async function(){ return await this.get('..').type }, diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 4f03d6b..3f617dc 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -354,13 +354,15 @@ module.BaseStore = { // XXX should this return a map for pattern matches??? __get__: async function(key){ return this.data[key] }, - get: async function(path, strict=false){ + get: async function(path, strict=false, energetic=false){ var that = this /* XXX ENERGETIC... path = await this.resolve(path, strict) /*/ path = path.includes('*') - && await this.isEnergetic(path) + && (energetic == true ? + await this.find(path) + : await this.isEnergetic(path)) || await this.resolve(path, strict) //*/ return path instanceof Array ? diff --git a/pwiki2.js b/pwiki2.js index c43b972..2ceb167 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,20 +1,13 @@ /********************************************************************** * * -* XXX FEATURE need to be able to call some actions on the root page -* before it gets .each()'ed... -* ...for things like: -* - count -* - unexpandedpath (name?) -* - ... -* this can be done in one of two ways: -* - syntax -* + will enable any action to be called energetically... -* - a complication... -* - special actions -* + transparent -* - extra concept -- might be confusing -* - duplicate actions +* XXX ENERGETIC do we need to make this a path syntax thing??? +* ...i.e. +* /some/path/action/! (current) +* vs. +* /some/path/!action +* ..."!" is removed before the .____(..) calls... +* XXX ENERGETIC revise naming... * XXX FEATURE tags and accompanying API... * - add tags to page -- macro/filter * .text -> .tags (cached on .update(..)) @@ -22,6 +15,43 @@ * - tag cache .tags * - tag-path filtering... * i.e. only show tags within a specific path/pattern... +* - path integration... +* i.e. a way to pass tags through path... +* /some/path:tags=a,b,c +* XXX FEATURE add a uniform way to track some state in links in pwiki +* for things like paging and the like with simple user/macro +* access (???)... +* ...the simplest that comes to mind is to store in in path +* somehow: +* - ?=&... +* traditional "query string"... +* - /:/:/.../ +* stack-style arguments... +* + simple to implement +* - goes through page search??? +* - ::=:... +* - ... +* the general idea is to be: +* - flexible enough to allow the basics done +* - restrictive enough to prevent misuse +* ...the rest of the state can simply be stored in the root pwiki +* object in one of the following ways: +* - directly (attrs/dict) +* - a special page +* - virtual (path-specific) +* e.g. +* /some/path/@state/page -> 4 +* ...might be fun to implement a basic json editor +* and viewer with this api... +* ...controlled via js +* ...or special actions: +* /some/path/@state/page/next (increment) +* /some/path/@state/page/prev (decrement) +* /some/path/@state/page=10 (assign) +* ... +* - session +* - stored (config) +* ...css selector as path.... * XXX revise/update sort... * XXX fs store: metadata and cache... * XXX sub/nested store mixing... @@ -67,40 +97,6 @@ * XXX FEATURE self-doc: * - some thing lile Action(, , |) * - System/doc -- show for action... -* XXX FEATURE add a uniform way to track some state in links in pwiki -* for things like paging and the like with simple user/macro -* access (???)... -* ...the simplest that comes to mind is to store in in path -* somehow: -* - ?=&... -* traditional "query string"... -* - /:/:/.../ -* stack-style arguments... -* + simple to implement -* - goes through page search??? -* - ::=:... -* - ... -* the general idea is to be: -* - flexible enough to allow the basics done -* - restrictive enough to prevent misuse -* ...the rest of the state can simply be stored in the root pwiki -* object in one of the following ways: -* - directly (attrs/dict) -* - a special page -* - virtual (path-specific) -* e.g. -* /some/path/@state/page -> 4 -* ...might be fun to implement a basic json editor -* and viewer with this api... -* ...controlled via js -* ...or special actions: -* /some/path/@state/page/next (increment) -* /some/path/@state/page/prev (decrement) -* /some/path/@state/page=10 (assign) -* ... -* - session -* - stored (config) -* ...css selector as path.... * XXX GENERATOR make pattern path parsing a generator... * ...experiment with a controllable iterator/range thing... * This would require: