mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-16 16:11:39 +00:00
refactoring and fixing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a25322c397
commit
8a78fabb46
132
pwiki/page.js
132
pwiki/page.js
@ -56,6 +56,22 @@ object.Constructor('BasePage', {
|
|||||||
// different "class"...
|
// different "class"...
|
||||||
//__clone_proto__: undefined,
|
//__clone_proto__: undefined,
|
||||||
|
|
||||||
|
actions: new Set([
|
||||||
|
'location',
|
||||||
|
'referrer',
|
||||||
|
'path',
|
||||||
|
'name',
|
||||||
|
'dir',
|
||||||
|
'resolved',
|
||||||
|
'rootpath',
|
||||||
|
'renderer',
|
||||||
|
'length',
|
||||||
|
'type',
|
||||||
|
'ctime',
|
||||||
|
'mtime',
|
||||||
|
]),
|
||||||
|
|
||||||
|
|
||||||
// NOTE: this can be inherited...
|
// NOTE: this can be inherited...
|
||||||
//store: undefined,
|
//store: undefined,
|
||||||
//__store: undefined,
|
//__store: undefined,
|
||||||
@ -172,6 +188,17 @@ object.Constructor('BasePage', {
|
|||||||
get isPattern(){
|
get isPattern(){
|
||||||
return this.path.includes('*') },
|
return this.path.includes('*') },
|
||||||
|
|
||||||
|
get ctime(){ return async function(){
|
||||||
|
var t = ((await this.data) ?? {}).ctime
|
||||||
|
return t ?
|
||||||
|
new Date(t).getTimeStamp()
|
||||||
|
: t }.call(this) },
|
||||||
|
get mtime(){ return async function(){
|
||||||
|
var t = ((await this.data) ?? {}).mtime
|
||||||
|
return t ?
|
||||||
|
new Date(t).getTimeStamp()
|
||||||
|
: t }.call(this) },
|
||||||
|
|
||||||
// store interface...
|
// store interface...
|
||||||
//
|
//
|
||||||
// XXX we are only doing modifiers here...
|
// XXX we are only doing modifiers here...
|
||||||
@ -181,24 +208,58 @@ object.Constructor('BasePage', {
|
|||||||
__delete__: function(path='.'){
|
__delete__: function(path='.'){
|
||||||
return this.store.delete(pwpath.relative(this.path, path)) },
|
return this.store.delete(pwpath.relative(this.path, path)) },
|
||||||
|
|
||||||
|
//* XXX
|
||||||
|
__energetic: undefined,
|
||||||
|
get energetic(){ return async function(){
|
||||||
|
return this.__energetic === true
|
||||||
|
|| ((this.actions
|
||||||
|
&& this.actions.has(this.name)
|
||||||
|
&& !!this[this.name].energetic)
|
||||||
|
|| !!await this.store.isEnergetic(this.path)) }.call(this) },
|
||||||
|
set energetic(value){
|
||||||
|
this.__energetic = value },
|
||||||
|
//*/
|
||||||
|
|
||||||
// page data...
|
// page data...
|
||||||
//
|
//
|
||||||
strict: undefined,
|
strict: undefined,
|
||||||
energetic: undefined,
|
//energetic: undefined,
|
||||||
get data(){ return (async function(){
|
get data(){ return (async function(){
|
||||||
|
// direct actions...
|
||||||
|
if(this.actions
|
||||||
|
&& this.actions.has(this.name)){
|
||||||
|
var name = this.name
|
||||||
|
var page = this.get('..')
|
||||||
|
var res = (this.isPattern
|
||||||
|
&& !await this.energetic
|
||||||
|
//&& !page[name].energetic) ?
|
||||||
|
&& !await page.energetic) ?
|
||||||
|
page
|
||||||
|
.map(function(page){
|
||||||
|
var res = page[name]
|
||||||
|
return typeof(res) == 'function' ?
|
||||||
|
res.bind(page)
|
||||||
|
: function(){
|
||||||
|
return res } })
|
||||||
|
: page[name]
|
||||||
|
return typeof(res) == 'function' ?
|
||||||
|
res.bind(page)
|
||||||
|
: function(){
|
||||||
|
return res } }
|
||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
// NOTE: we need to make sure each page gets the chance to handle
|
// NOTE: we need to make sure each page gets the chance to handle
|
||||||
// its context (i.e. bind action to page)....
|
// its context (i.e. bind action to page)....
|
||||||
if(this.isPattern
|
if(this.isPattern
|
||||||
// XXX ENERGETIC...
|
// XXX ENERGETIC...
|
||||||
&& !(this.energetic
|
&& !(await this.energetic
|
||||||
|| await this.store.isEnergetic(this.path))){
|
|| await this.store.isEnergetic(this.path))){
|
||||||
return this
|
return this
|
||||||
.map(function(page){
|
.map(function(page){
|
||||||
return page.data }) }
|
return page.data }) }
|
||||||
// single page...
|
// single page...
|
||||||
// XXX ENERGETIC...
|
// XXX ENERGETIC...
|
||||||
var res = await this.store.get(this.path, !!this.strict, !!this.energetic)
|
var res = await this.store.get(this.path, !!this.strict, !!await this.energetic)
|
||||||
return typeof(res) == 'function' ?
|
return typeof(res) == 'function' ?
|
||||||
res.bind(this)
|
res.bind(this)
|
||||||
: res }).call(this) },
|
: res }).call(this) },
|
||||||
@ -320,7 +381,8 @@ object.Constructor('BasePage', {
|
|||||||
: this.path
|
: this.path
|
||||||
var paths = path.includes('*')
|
var paths = path.includes('*')
|
||||||
// XXX ENERGETIC...
|
// XXX ENERGETIC...
|
||||||
&& !(this.energetic
|
&& !(await this.energetic
|
||||||
|
// XXX test if energetic action...
|
||||||
|| await this.store.isEnergetic(path)) ?
|
|| await this.store.isEnergetic(path)) ?
|
||||||
this.resolve(path)
|
this.resolve(path)
|
||||||
: path
|
: path
|
||||||
@ -1152,22 +1214,18 @@ object.Constructor('Page', BasePage, {
|
|||||||
//
|
//
|
||||||
// NOTE: these can not be overloaded.
|
// NOTE: these can not be overloaded.
|
||||||
// (XXX should this be so?)
|
// (XXX should this be so?)
|
||||||
|
// XXX should this be an object???
|
||||||
actions: new Set([
|
actions: new Set([
|
||||||
'location',
|
...module.BasePage.prototype.actions,
|
||||||
'referrer',
|
|
||||||
'path',
|
|
||||||
'name',
|
|
||||||
'dir',
|
|
||||||
'resolved',
|
|
||||||
'rootpath',
|
|
||||||
'renderer',
|
|
||||||
'length',
|
|
||||||
'type',
|
|
||||||
|
|
||||||
//'ctime',
|
'!',
|
||||||
//'mtime',
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
'!': Object.assign(
|
||||||
|
function(){
|
||||||
|
return this.get('.', {energetic: true}).raw },
|
||||||
|
{energetic: true}),
|
||||||
|
|
||||||
// events...
|
// events...
|
||||||
//
|
//
|
||||||
// NOTE: textUpdate event will not get triggered if text is updated
|
// NOTE: textUpdate event will not get triggered if text is updated
|
||||||
@ -1215,25 +1273,6 @@ object.Constructor('Page', BasePage, {
|
|||||||
//
|
//
|
||||||
// XXX revise how we handle .strict mode...
|
// XXX revise how we handle .strict mode...
|
||||||
get raw(){ return (async function(){
|
get raw(){ return (async function(){
|
||||||
// direct actions...
|
|
||||||
if(this.actions
|
|
||||||
&& this.actions.has(this.name)){
|
|
||||||
var name = this.name
|
|
||||||
var page = this.get('..')
|
|
||||||
var res = (this.isPattern
|
|
||||||
&& !this.energetic) ?
|
|
||||||
page
|
|
||||||
.each()
|
|
||||||
.map(function(page){
|
|
||||||
var res = page[name]
|
|
||||||
return typeof(res) == 'function' ?
|
|
||||||
res.call(page)
|
|
||||||
: res })
|
|
||||||
: page[this.name]
|
|
||||||
return typeof(res) == 'function' ?
|
|
||||||
res.call(page)
|
|
||||||
: res }
|
|
||||||
|
|
||||||
var data = await this.data
|
var data = await this.data
|
||||||
// no data...
|
// no data...
|
||||||
// NOTE: if we hit this it means that nothing was resolved,
|
// NOTE: if we hit this it means that nothing was resolved,
|
||||||
@ -1291,7 +1330,8 @@ object.Constructor('Page', BasePage, {
|
|||||||
path: typeof(args[0]) == 'string' ?
|
path: typeof(args[0]) == 'string' ?
|
||||||
args.shift()
|
args.shift()
|
||||||
: '.',
|
: '.',
|
||||||
strict: args.shift() ?? false,
|
strict: args.shift()
|
||||||
|
?? false,
|
||||||
}
|
}
|
||||||
|
|
||||||
var page = this.get(path, strict)
|
var page = this.get(path, strict)
|
||||||
@ -1807,26 +1847,6 @@ module.System = {
|
|||||||
// page actions...
|
// page actions...
|
||||||
//
|
//
|
||||||
|
|
||||||
// metadata...
|
|
||||||
//
|
|
||||||
ctime: async function(){
|
|
||||||
var date = (await this.get('..').data).ctime
|
|
||||||
return date ?
|
|
||||||
(new Date(date)).getTimeStamp()
|
|
||||||
: date },
|
|
||||||
mtime: async function(){
|
|
||||||
var date = (await this.get('..').data).mtime
|
|
||||||
return date ?
|
|
||||||
(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...
|
// XXX EXPERIMENTAL -- page types...
|
||||||
isAction: async function(){
|
isAction: async function(){
|
||||||
return await this.get('..').type == 'action' ?
|
return await this.get('..').type == 'action' ?
|
||||||
|
|||||||
@ -371,16 +371,15 @@ module.BaseStore = {
|
|||||||
// normalize trailing '/'...
|
// normalize trailing '/'...
|
||||||
path.at(-1) == ''
|
path.at(-1) == ''
|
||||||
&& path.pop()
|
&& path.pop()
|
||||||
// match basedir and addon basename to the result...
|
var p = path.slice()
|
||||||
var name = path.at(-1)
|
var tail = []
|
||||||
if(name
|
while(!p.at(-1).includes('*')){
|
||||||
&& name != ''
|
tail.unshift(p.pop()) }
|
||||||
&& !name.includes('*')){
|
tail = tail.join('/')
|
||||||
path.pop()
|
if(tail.length > 0){
|
||||||
//path.push('')
|
return (await this.match(p.join('/'), strict))
|
||||||
return (await this.match(path.join('/'), strict))
|
|
||||||
.map(function(p){
|
.map(function(p){
|
||||||
return pwpath.join(p, name) }) } }
|
return pwpath.join(p, tail) }) } }
|
||||||
// direct...
|
// direct...
|
||||||
return this.match(path, strict) },
|
return this.match(path, strict) },
|
||||||
//
|
//
|
||||||
@ -459,7 +458,8 @@ module.BaseStore = {
|
|||||||
path = await this.exists(path)
|
path = await this.exists(path)
|
||||||
return path
|
return path
|
||||||
&& (await this.__get__(path)
|
&& (await this.__get__(path)
|
||||||
?? await this.next.metadata(path))
|
?? (this.next
|
||||||
|
&& await this.next.metadata(path)))
|
||||||
|| undefined },
|
|| undefined },
|
||||||
|
|
||||||
// NOTE: deleting and updating only applies to explicit matching
|
// NOTE: deleting and updating only applies to explicit matching
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* XXX do we need something like /System/Actions/.. for fast actions called
|
||||||
|
* in the same way as direct page actions???
|
||||||
* XXX FEATURE tags and accompanying API...
|
* XXX FEATURE tags and accompanying API...
|
||||||
* - add tags to page -- macro/filter
|
* - add tags to page -- macro/filter
|
||||||
* - <page>.text -> <page>.tags (cached on .update(..))
|
* - <page>.text -> <page>.tags (cached on .update(..))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user