From d13cdef574cb4586a7c071fe94e563f9cf0f8527 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 21 Aug 2022 23:07:47 +0300 Subject: [PATCH] now @quote(..) handles actions without triggering them by deafult + fixes and notes... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 117 ++++++++++++++++++++++++++++++++++---------- pwiki/store/base.js | 10 ++++ pwiki2.html | 11 +++++ pwiki2.js | 8 +-- 4 files changed, 116 insertions(+), 30 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index 038822e..9839984 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -192,6 +192,13 @@ object.Constructor('BasePage', { set metadata(value){ this.__update__(value) }, + get type(){ return async function(){ + return this.store.isStore(this.path) ? + 'store' + : typeof(await this.data) == 'function' ? + 'action' + : 'page' }.bind(this)() }, + // number of matching pages... // NOTE: this can be both sync and async... get length(){ @@ -521,6 +528,8 @@ object.Constructor('Page', BasePage, { NOT_FOUND_TEMPLATE_ERROR: 'NotFoundTemplateError', + QUOTE_ACTION_PAGE: 'QuoteActionPage', + // XXX DEPENDS to be used for cache invalidation... // Format: // { @@ -793,7 +802,7 @@ object.Constructor('Page', BasePage, { // // XXX need a way to escape macros -- i.e. include in a quoted text... quote: Macro( - ['src', 'filter', 'text', 'join'], + ['src', 'filter', 'text', 'join', ['expandactions']], async function*(args, body, state){ var src = args.src //|| args[0] var base = this.get(this.path.split(/\*/).shift()) @@ -804,6 +813,7 @@ object.Constructor('Page', BasePage, { src = src ? await base.parse(src, state) : src + var expandactions = args.expandactions // XXX DEPENDS var depends = state.depends = @@ -811,7 +821,10 @@ object.Constructor('Page', BasePage, { ?? new Set() var pages = src ? - this.get(src).asPages() + (!expandactions + && await this.get(src).type == 'action' ? + base.get(this.QUOTE_ACTION_PAGE) + : this.get(src).asPages()) : text instanceof Array ? [text.join('')] : typeof(text) == 'string' ? @@ -830,8 +843,13 @@ object.Constructor('Page', BasePage, { first = false text = typeof(page) == 'string' ? - page + page + : (!expandactions + && await page.type == 'action') ? + base.get(this.QUOTE_ACTION_PAGE).raw : await page.raw + + // XXX DEPENDS... page.path && depends.add(page.path) @@ -1157,15 +1175,39 @@ object.Constructor('Page', BasePage, { // iterate matches or content list as pages... // + // .asPages() + // .asPages([, ]) + // .asPages([, ]) + // .asPages(, [, ]) + // .asPages() + // -> + // + // NOTE: this will get .raw for non-pattern pages this it can trigger + // actions... + // // XXX revise name... - asPages: async function*(path='.', strict=false){ - if(path === true - || path === false){ - strict = path - path = '.' } + asPages: async function*(path='.', strict=false, noexpandactions=false){ + // options... + var args = [...arguments] + var opts = typeof(args.at(-1)) == 'object' ? + args.pop() + : {} + var {path, strict, noexpandactions} = { + ...opts, + path: typeof(args[0]) == 'string' ? + args.shift() + : '.', + strict: args.shift() ?? false, + } + var page = this.get(path, strict) // handle lists in pages (actions, ... etc.)... if(!page.isPattern){ + if(noexpandactions + && await page.type == 'action'){ + //yield this.get(this.QUOTE_ACTION_PAGE) + yield page + return } var raw = await page.raw if(raw == null){ return } @@ -1417,18 +1459,27 @@ module.System = { @source(../path) - - @source(./name) + @source(./name) + + + a + + s + + + × ` }, // XXX this is really slow... tree: { text: object.doc` -
+
@source(./name) - * - × + + 🛈 + × +
@source(./tree)
@@ -1438,12 +1489,20 @@ module.System = { text: `@include(../**/path join="@source(line-separator)")`}, info: { text: object.doc` - Path: @source(../path)
- Resolved path: @source(../resolved)
- Referrer: @source(../referrer)
- Renderer: @source(../renderer)
+ Path: @source(../path) + (edit)
+ Resolved path: @source(../resolved) + (edit)
+ Referrer: @source(../referrer) + (edit)
+ Renderer: @source(../renderer) + (edit)
+ + type: @source(../type)
+ ctime: @source(../ctime)
mtime: @source(../mtime)
+
` }, @@ -1472,6 +1531,8 @@ module.System = {
` }, + QuoteActionPage: { + text: '[ native code ]' }, // page actions... @@ -1498,19 +1559,20 @@ module.System = { return p.title ?? p.name }, ctime: async function(){ - return (await this.get('..').data).ctime ?? '' }, + return (await this.get('..').data).ctime }, mtime: async function(){ - return (await this.get('..').data).mtime ?? '' }, + return (await this.get('..').data).mtime }, // XXX EXPERIMENTAL... type: async function(){ - // XXX also check if a page is a store... - return typeof(await this.get('..').data) == 'function' ? - 'action' - : 'page' }, + return await this.get('..').type }, isAction: async function(){ - return typeof(await this.get('..').data) == 'function' ? - ['action'] + return await this.get('..').type == 'action' ? + 'action' + : undefined }, + isStore: async function(){ + return await this.get('..').type == 'store' ? + 'store' : undefined }, @@ -1534,6 +1596,8 @@ module.System = { delete: function(){ var target = this.get('..') + console.log('DELETE:', target.path) + target.delete() // redirect... @@ -1542,7 +1606,7 @@ module.System = { // show info about the delete operation... return target.get('DeletingPage').text }, - // XXX EXPERIMENTAL + /*/ XXX EXPERIMENTAL // move page one level up... moveUp: function(){ var target = this.get('..') @@ -1587,6 +1651,7 @@ module.System = { this.render_root && (this.render_root.location = to) return '' }, + //*/ // test_path: function(){ diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 58e7990..ed0abee 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -457,12 +457,14 @@ module.MetaStore = { return object.childOf(value, BaseStore) }) .map(function([path, _]){ return path })) }, + // XXX do we need to account for trailing '/' here??? substore: function(path){ path = pwpath.normalize(path, 'string') if(this.substores.includes(path)){ return path } var root = path[0] == '/' var store = this.substores + // normalize store paths to the given path... .filter(function(p){ return path.startsWith( root ? @@ -477,6 +479,14 @@ module.MetaStore = { : store }, getstore: function(path){ return this.data[this.substore(path)] }, + // XXX do we need to account for trailing '/' here??? + isStore: function(path){ + path = pwpath.normalize(path, 'string') + path = path[0] == '/' ? + path.slice(1) + : path + return this.substores.includes(path) + || this.substores.includes('/'+ path) }, // XXX this depends on .data having keys... __paths__: async function(){ diff --git a/pwiki2.html b/pwiki2.html index 3b44cea..2bcdd55 100755 --- a/pwiki2.html +++ b/pwiki2.html @@ -25,6 +25,17 @@ diff --git a/pwiki2.js b/pwiki2.js index ca7ec2c..25fc494 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,8 +1,8 @@ /********************************************************************** * * -* XXX need a uniform way to track state in pwiki for things like paging -* and the like with simple user/macro access... +* XXX need 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: * - ?=&... @@ -10,12 +10,12 @@ * - /:/:/.../ * stack-style arguments... * + simple to implement -* - goes thrugh page search??? +* - goes through page search??? * - ::=:... * - ... * the general idea is to be: * - flexible enough to allow the basics done -* - restrictive enough to prevent missuse +* - 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)