experimenting with list pages...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-24 10:45:53 +03:00
parent 5b09be40c6
commit 4db50f0c25

107
pwiki2.js
View File

@ -832,6 +832,16 @@ object.Constructor('BasePage', {
return this.back(-offset) }, return this.back(-offset) },
//*/ //*/
// store interface...
//
// XXX we are only doing modifiers here...
__update__: function(data){
this.store.update(this.location, data)
return this },
__delete__: function(path='.'){
this.store.delete(module.path.relative(this.location, path))
return this },
// page data... // page data...
// //
strict: undefined, strict: undefined,
@ -849,7 +859,8 @@ object.Constructor('BasePage', {
: res }, : res },
//return this.store.get(this.location, !!this.strict) }, //return this.store.get(this.location, !!this.strict) },
set data(value){ set data(value){
this.store.update(this.location, value) }, //this.store.update(this.location, value) },
this.__update__(value) },
// metadata... // metadata...
// //
@ -858,7 +869,8 @@ object.Constructor('BasePage', {
get metadata(){ get metadata(){
return this.store.metadata(this.location) }, return this.store.metadata(this.location) },
set metadata(value){ set metadata(value){
this.store.update(this.location, value) }, //this.store.update(this.location, value) },
this.__update__(value) },
// number of matching pages... // number of matching pages...
get length(){ get length(){
@ -872,8 +884,9 @@ object.Constructor('BasePage', {
match: relMatchProxy('match'), match: relMatchProxy('match'),
resolve: relMatchProxy('resolve'), resolve: relMatchProxy('resolve'),
delete: function(path='.'){ delete: function(path='.'){
this.store.delete(module.path.relative(this.location, path)) //this.store.delete(module.path.relative(this.location, path))
return this }, //return this },
return this.__delete__() },
// //
// .get(<path>[, <data>]) // .get(<path>[, <data>])
@ -1643,12 +1656,16 @@ object.Constructor('Page', BasePage, {
// <text> // <text>
// </include> // </include>
// //
// XXX RECURSION recursion detection is still a bit off...
// XXX 'text' argument is changed to 'recursive'... // XXX 'text' argument is changed to 'recursive'...
// XXX revise recursion checks.... // XXX revise recursion checks....
// XXX should this be lazy??? // XXX should this be lazy???
include: Macro( include: Macro(
['src', 'recursive', ['isolated']], ['src', 'recursive', ['isolated']],
function(args, body, state, key='included', handler){ function(args, body, state, key='included', handler){
var macro = 'include'
if(typeof(args) == 'string'){
var [macro, args, body, state, key="included", handler] = arguments }
// positional args... // positional args...
var src = args.src var src = args.src
var recursive = args.recursive || body var recursive = args.recursive || body
@ -1680,10 +1697,15 @@ object.Constructor('Page', BasePage, {
//if(this.match() == this.match(src) //if(this.match() == this.match(src)
if(this.resolve() == this.resolve(src) if(this.resolve() == this.resolve(src)
|| seen.includes(src)){ || seen.includes(src)){
//* XXX this prevents recursion...
if(!recursive){ if(!recursive){
/* XXX RECURSION this prevents recursion...
throw new Error( throw new Error(
'include: include recursion detected: ' macro +': recursion detected: '
+ seen.concat([src]).join(' -> ')) }
/*/
// XXX
console.warn(
macro+': recursion detected: '
+ seen.concat([src]).join(' -> ')) } + seen.concat([src]).join(' -> ')) }
//*/ //*/
// have the 'recursive' arg... // have the 'recursive' arg...
@ -1709,6 +1731,7 @@ object.Constructor('Page', BasePage, {
this.parse(src, state) this.parse(src, state)
: src : src
return this.macros.include.call(this, return this.macros.include.call(this,
'source',
args, body, state, 'sources', args, body, state, 'sources',
function(){ function(){
return this.parse(this.get(src).raw +'', state) }) }), return this.parse(this.get(src).raw +'', state) }) }),
@ -1902,7 +1925,17 @@ object.Constructor('Page', BasePage, {
if(src){ if(src){
src = this.parse(src, state) src = this.parse(src, state)
/* XXX ARRAY page...
var pages = this.get(src, strict).each() var pages = this.get(src, strict).each()
/*/
var pages = this.get(src, strict)
pages = pages.isArray ?
// XXX should we wrap this in pages...
pages.raw
.map(function(data){
return that.virtual(data) })
: pages.each()
//*/
// no matching pages -> get the else block... // no matching pages -> get the else block...
if(pages.length == 0 if(pages.length == 0
&& (text || args['else'])){ && (text || args['else'])){
@ -1962,6 +1995,13 @@ object.Constructor('Page', BasePage, {
return this.__parser__.parse(this, text, state) }.bind(this)) } return this.__parser__.parse(this, text, state) }.bind(this)) }
return this.__parser__.parse(this, text, state) }, return this.__parser__.parse(this, text, state) },
// XXX not sure about the semantics here...
// XXX this feels a bit overcomplicated...
// ...can we merge pattern and array pages into one???
// XXX EXPERIMENTAL
get isArray(){
return !this.isPattern
&& this.raw instanceof Array },
// raw page text... // raw page text...
// //
@ -1997,7 +2037,8 @@ object.Constructor('Page', BasePage, {
.flat() .flat()
: data.text }, : data.text },
set raw(value){ set raw(value){
this.store.update(this.location, {text: value}) }, //this.store.update(this.location, {text: value}) },
this.__update__({text: value}) },
// expanded page text... // expanded page text...
// //
@ -2007,7 +2048,41 @@ object.Constructor('Page', BasePage, {
.flat() .flat()
.join('\n') }, .join('\n') },
set text(value){ set text(value){
this.store.update(this.location, {text: value}) }, //this.store.update(this.location, {text: value}) },
this.__update__({text: value}) },
// XXX EXPERIMENTAL...
ro: function(data={}){
return Object.assign({
__proto__: this,
__update__: function(){ return this },
__delete__: function(){ return this },
},
data) },
// XXX EXPERIMENTAL...
// XXX should we be able to change path/location here???
virtual: function(text){
var that = this
return Object.assign({
__proto__: this,
__update__: function(data){
Object.assign(this.data, data)
return this },
__delete__: function(){ return this },
// NOTE: we need to proxy .clone(..) back to parent so as to
// avoid overloading .data in the children too...
// XXX STUB...
clone: function(...args){
return that.clone(...args) },
data: {
ctime: Date.now(),
mtime: Date.now(),
text,
},
}) },
}) })
@ -2047,6 +2122,10 @@ module.store =
var System = { var System = {
// XXX tests...
test_list: function(){
return 'abcdef'.split('') },
// metadata... // metadata...
// //
path: function(){ path: function(){
@ -2075,6 +2154,18 @@ var System = {
// utils... // utils...
// //
// XXX System/subpaths // XXX System/subpaths
// XXX
links: function(){
// XXX
return '' },
// XXX links to current page...
to: function(){
// XXX
return '' },
// XXX links from current page...
'from': function(){
// XXX
return '' },
// actions... // actions...