From b96174ed7f2e9581509363db1a633d3ce3ddc0b4 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 21 Aug 2022 12:31:04 +0300 Subject: [PATCH] experimenting with path argument syntaxes... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 6 +++++- pwiki/parser.js | 2 +- pwiki/path.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index 6a15101..cc9068b 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -1507,7 +1507,7 @@ module.System = { this.render_root && (this.render_root.location = to.path) return this.render_root.path }, - + // // syntax: // //to:/move // @@ -1526,6 +1526,10 @@ module.System = { && (this.render_root.location = to) return '' }, + // + test_path: function(){ + }, + // XXX System/back // XXX System/forward // XXX System/sort diff --git a/pwiki/parser.js b/pwiki/parser.js index 50ff840..89d1fd9 100755 --- a/pwiki/parser.js +++ b/pwiki/parser.js @@ -402,7 +402,7 @@ module.BaseParser = { expand: async function*(page, ast, state={}){ ast = ast == null ? //this.group(page) - this.group(page, await page.raw) + this.group(page, await page.raw ?? '') : typeof(ast) == 'string' ? this.group(page, ast) : ast instanceof types.Generator ? diff --git a/pwiki/path.js b/pwiki/path.js index 5a9685a..32aa21d 100755 --- a/pwiki/path.js +++ b/pwiki/path.js @@ -221,6 +221,55 @@ module = { if(alt_pages){ for(var page of [...this.ALTERNATIVE_PAGES]){ yield* this.paths(path.concat(page), seen) }} }, + + + // XXX EXPERIMENTAL... + // + // .splitSrgs() + // -> + // + // Format: + // { + // path: + // args: { + // :, + // ... + // } + // action: + // } + // + // Syntax: + // /:/:/../action + // + // XXX the problem here is that we could legitimately create path + // items containing ":" -- it either needs to be a reserved char + // or this scheme will not work... + splitArgs: function(path){ + path = this.normalize(path, 'array') + + var res = { + path: '', + args: {}, + actions: path.pop(), + } + var state = 'path' + var cur, value + for(var elem of path){ + if(elem.includes(':')){ + state = 'arg' } + + if(state == 'path'){ + res.path += '/'+ elem + + } else if(state == 'arg'){ + ;[cur, value] = elem.split(':') + res[cur] = value + state = value + + } else if(state == 'value'){ + res[cur] += '/'+ value } } + + return res }, }