diff --git a/pwiki/page.js b/pwiki/page.js index 6278870..a01e91d 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -23,7 +23,7 @@ var markdown = require('./filters/markdown') var relProxy = function(name){ - var func = function(path='.', ...args){ + var func = function(path='.:$ARGS', ...args){ return this.store[name]( pwpath.relative(this.path, path), ...args) } @@ -31,10 +31,10 @@ function(name){ return func } var relMatchProxy = function(name){ - var func = function(path='.', strict=this.strict){ + var func = function(path='.:$ARGS', strict=this.strict){ if(path === true || path === false){ strict = path - path = '.' } + path = '.:$ARGS' } return this.store[name]( pwpath.relative(this.path, path), strict) } @@ -372,6 +372,7 @@ object.Constructor('BasePage', { // -> path // -> undefined // + // XXX ARGS preserve args... find: function(path='.', strict=false){ if(path === true || path === false){ strict = path @@ -403,7 +404,7 @@ object.Constructor('BasePage', { // we really have to... path = path ? pwpath.relative(this.path, path) - : this.path + : this.location var paths = path.includes('*') // XXX ENERGETIC... && !(await this.energetic @@ -844,7 +845,8 @@ object.Constructor('Page', BasePage, { key = key ?? 'included' } var base = this.get(this.path.split(/\*/).shift()) var src = args.src - && await base.parse(args.src, state) + //&& await base.parse(args.src, state) + && this.resolvePathVars(await base.parse(args.src, state)) if(!src){ return } var recursive = args.recursive ?? body @@ -875,7 +877,8 @@ object.Constructor('Page', BasePage, { yield join } first = false - var full = page.path + //var full = page.path + var full = page.location // handle recursion... var parent_seen = 'seen' in state @@ -1266,7 +1269,7 @@ object.Constructor('Page', BasePage, { '!': Object.assign( function(){ - return this.get('.', {energetic: true}).raw }, + return this.get('.:$ARGS', {energetic: true}).raw }, {energetic: true}), // XXX DEBUG -- remove these... @@ -1315,17 +1318,6 @@ object.Constructor('Page', BasePage, { state = state ?? {} return this.__parser__.parse(this, text, state) }, - // true if page has an array value but is not a pattern page... - // - // XXX the split into pattern and array pages feels a bit overcomplicated... - // ...can we merge the two and simplify things??? - // XXX EXPERIMENTAL - get isArray(){ return (async function(){ - return !this.isPattern - // NOTE: we can't only use .data here as it can be a function - // that will return an array... - && await this.raw instanceof Array }).call(this) }, - // raw page text... // // NOTE: writing to .raw is the same as writing to .text... @@ -1379,7 +1371,7 @@ object.Constructor('Page', BasePage, { // actions... // // XXX revise name... - asPages: async function*(path='.', strict=false, noexpandactions=false){ + asPages: async function*(path='.:$ARGS', strict=false, noexpandactions=false){ // options... var args = [...arguments] var opts = typeof(args.at(-1)) == 'object' ? @@ -1389,7 +1381,7 @@ object.Constructor('Page', BasePage, { ...opts, path: typeof(args[0]) == 'string' ? args.shift() - : '.', + : '.:$ARGS', strict: args.shift() ?? false, } diff --git a/pwiki/path.js b/pwiki/path.js index fb5d376..23f42bc 100755 --- a/pwiki/path.js +++ b/pwiki/path.js @@ -315,7 +315,6 @@ module = { splitArgs: function(path){ path = this.normalize(path, 'string') var [path, ...args] = path.split(/(? 0){ return (await this.match(p.join('/'), strict)) .map(function(p){ - return pwpath.join(p, tail) }) } } + return pwpath.join(p, tail) + args }) } } // direct... return this.match(path, strict) }, // @@ -419,6 +430,7 @@ module.BaseStore = { // XXX SANITIZE... path = pwpath.sanitize(path, 'string') //*/ + var path = pwpath.splitArgs(path).path path = path.includes('*') && (energetic == true ? await this.find(path) @@ -461,6 +473,7 @@ module.BaseStore = { // NOTE: setting/removing metadata is done via .update(..) / .delete(..) // NOTE: this uses .__get__(..) internally... metadata: async function(path, ...args){ + path = pwpath.splitArgs(path).path // set... if(args.length > 0){ return this.update(path, ...args) } @@ -491,6 +504,7 @@ module.BaseStore = { /*/ || pwpath.normalize(path, 'string') //*/ + path = pwpath.splitArgs(path).path data = data instanceof Promise ? await data : data @@ -517,6 +531,7 @@ module.BaseStore = { // read-only... if(this.__delete__ == null){ return this } + path = pwpath.splitArgs(path).path path = await this.exists(path) if(path){ await this.__delete__(path) diff --git a/pwiki2.js b/pwiki2.js index 32b4c1e..85c744e 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -19,6 +19,7 @@ * examples: * // NOTE: .text is redered via _view and thus is on a different * // level to .raw... +* // XXX should renderer.args be the same in .text and .parse(..)??? * // 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 @@ -29,28 +30,23 @@ * .args - x y z * .renderer.args - a b c * .root.args - a b c -* await pwiki.get('/path/testDirect:x:y:z').parse('@include(.)') -* .args - empty +* await pwiki.get('/path/testDirect:x:y:z').parse('@include(.:$ARGS)') +* .args - x y z * .renderer.args - a b c * .root.args - a b c -* XXX losing args on this path... * XXX triggered twice... -* await pwiki.get('/path/testAction:x:y:z').parse('@include(.)') -* .args - empty +* await pwiki.get('/path/testAction:x:y:z').parse('@include(.:$ARGS)') +* .args - x y z * .renderer.args - a b c * .root.args - a b c -* XXX losing args on this path... * XXX triggered twice... -* XXX .text uses .parse(..) internally... * await pwiki.get('/path/testDirect:x:y:z').text -* .args - empty +* .args - x y z * .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 +* .args - x y z * .renderer.args - x y z * .root.args - a b c * XXX triggered twice...