mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
refactred the acquisition api...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b0e5230e94
commit
541c573e53
97
wiki.js
97
wiki.js
@ -25,7 +25,7 @@ var BaseData = {
|
|||||||
'System/resolved': function(){
|
'System/resolved': function(){
|
||||||
var o = Object.create(this)
|
var o = Object.create(this)
|
||||||
o.location = o.dir
|
o.location = o.dir
|
||||||
return o.acquire(o.dir, o.title)
|
return o.get(o.dir).acquire(o.title)
|
||||||
},
|
},
|
||||||
|
|
||||||
'System/list': function(){
|
'System/list': function(){
|
||||||
@ -67,7 +67,7 @@ var BaseData = {
|
|||||||
var wiki = this.__wiki_data
|
var wiki = this.__wiki_data
|
||||||
Object.keys(wiki).forEach(function(k){
|
Object.keys(wiki).forEach(function(k){
|
||||||
(wiki[k].links || []).forEach(function(l){
|
(wiki[k].links || []).forEach(function(l){
|
||||||
(l == p || that.acquire(path2lst(l).slice(0, -1), path2lst(l).pop()) == p)
|
(l == p || that.get(path2lst(l).slice(0, -1)).acquire(path2lst(l).pop()) == p)
|
||||||
&& res.push([l, k])
|
&& res.push([l, k])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -134,9 +134,12 @@ var Wiki = {
|
|||||||
|
|
||||||
__home_page__: 'WikiHome',
|
__home_page__: 'WikiHome',
|
||||||
__default_page__: 'EmptyPage',
|
__default_page__: 'EmptyPage',
|
||||||
|
// Special sub-paths to look in on each level...
|
||||||
__acquesition_order__: [
|
__acquesition_order__: [
|
||||||
'Templates',
|
'Templates',
|
||||||
],
|
],
|
||||||
|
__post_acquesition_order__: [
|
||||||
|
],
|
||||||
// XXX should this be read only???
|
// XXX should this be read only???
|
||||||
__system__: 'System',
|
__system__: 'System',
|
||||||
//__redirect_template__: 'RedirectTemplate',
|
//__redirect_template__: 'RedirectTemplate',
|
||||||
@ -222,7 +225,7 @@ var Wiki = {
|
|||||||
var t = p.pop()
|
var t = p.pop()
|
||||||
p = normalizePath(p)
|
p = normalizePath(p)
|
||||||
|
|
||||||
var target = page.acquire(p, t)
|
var target = page.get(p).acquire(t)
|
||||||
// page target changed...
|
// page target changed...
|
||||||
// NOTE: this can happen either when a link was an orphan
|
// NOTE: this can happen either when a link was an orphan
|
||||||
// or if the new page path shadowed the original
|
// or if the new page path shadowed the original
|
||||||
@ -233,7 +236,7 @@ var Wiki = {
|
|||||||
return lnk
|
return lnk
|
||||||
|
|
||||||
// skip links that do not resolve to target...
|
// skip links that do not resolve to target...
|
||||||
} else if(page.acquire(p, t) != l){
|
} else if(page.get(p).acquire(t) != l){
|
||||||
return lnk
|
return lnk
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,9 +253,9 @@ var Wiki = {
|
|||||||
} else if(ndir == odir){
|
} else if(ndir == odir){
|
||||||
// conflict: the new link will not resolve to the
|
// conflict: the new link will not resolve to the
|
||||||
// target page...
|
// target page...
|
||||||
if(page.acquire(p, ntitle) != value){
|
if(page.get(p).acquire(ntitle) != value){
|
||||||
console.log('ERR:', lnk, '->', to,
|
console.log('ERR:', lnk, '->', to,
|
||||||
'is shadowed by:', page.acquire(p, ntitle))
|
'is shadowed by:', page.get(p).acquire(ntitle))
|
||||||
// XXX should we add a note to the link???
|
// XXX should we add a note to the link???
|
||||||
redirect = true
|
redirect = true
|
||||||
|
|
||||||
@ -323,7 +326,7 @@ var Wiki = {
|
|||||||
// - aquire empty page (same order as above)
|
// - aquire empty page (same order as above)
|
||||||
//
|
//
|
||||||
get text(){
|
get text(){
|
||||||
var data = this.acquireData()
|
var data = this.data
|
||||||
return data instanceof Function ? data.call(this, this)
|
return data instanceof Function ? data.call(this, this)
|
||||||
: typeof(data) == typeof('str') ? data
|
: typeof(data) == typeof('str') ? data
|
||||||
: data != null ? data.text
|
: data != null ? data.text
|
||||||
@ -333,7 +336,7 @@ var Wiki = {
|
|||||||
var l = this.location
|
var l = this.location
|
||||||
|
|
||||||
// prevent overwriting actions...
|
// prevent overwriting actions...
|
||||||
if(this.acquireData(l) instanceof Function){
|
if(this.data instanceof Function){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +350,7 @@ var Wiki = {
|
|||||||
|
|
||||||
// NOTE: this is set by setting .text
|
// NOTE: this is set by setting .text
|
||||||
get links(){
|
get links(){
|
||||||
var data = this.acquireData() || {}
|
var data = this.data || {}
|
||||||
var links = data.links = data.links
|
var links = data.links = data.links
|
||||||
|| (this.text.match(this.__wiki_link__) || [])
|
|| (this.text.match(this.__wiki_link__) || [])
|
||||||
// unwrap explicit links...
|
// unwrap explicit links...
|
||||||
@ -368,7 +371,7 @@ var Wiki = {
|
|||||||
},
|
},
|
||||||
get: function(path){
|
get: function(path){
|
||||||
var o = Object.create(this)
|
var o = Object.create(this)
|
||||||
o.location = path
|
o.location = path || this.path
|
||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -376,32 +379,36 @@ var Wiki = {
|
|||||||
exists: function(path){
|
exists: function(path){
|
||||||
return normalizePath(path) in this.__wiki_data },
|
return normalizePath(path) in this.__wiki_data },
|
||||||
// get title from dir and then go up the tree...
|
// get title from dir and then go up the tree...
|
||||||
_acquire: function(title){
|
acquire: function(title, no_default){
|
||||||
title = title || this.__default_page__
|
title = title || this.title
|
||||||
var acquire_from = this.__acquesition_order__
|
|
||||||
var data = this.__wiki_data
|
|
||||||
var that = this
|
|
||||||
|
|
||||||
|
var that = this
|
||||||
|
var acquire_from = this.__acquesition_order__ || []
|
||||||
|
var post_acquire_from = this.__post_acquesition_order__ || []
|
||||||
|
var data = this.__wiki_data
|
||||||
|
|
||||||
|
// XXX should this be .dir or .path???
|
||||||
var path = path2lst(this.dir)
|
var path = path2lst(this.dir)
|
||||||
|
|
||||||
var _res = function(p){
|
var _get = function(path, title, lst){
|
||||||
p = normalizePath(p)
|
lst = (lst == null || lst.length == 0) ? [''] : lst
|
||||||
return that.__wiki_data[p] && p
|
for(var i=0; i < lst.length; i++){
|
||||||
|
var p = path.concat([lst[i], title])
|
||||||
|
if(that.exists(p)){
|
||||||
|
p = normalizePath(p)
|
||||||
|
return that.__wiki_data[p] && p
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
// get title from path...
|
// get title from path...
|
||||||
var p = path.concat([title])
|
var p = _get(path, title)
|
||||||
if(this.exists(p)){
|
// get title from special paths in path...
|
||||||
return _res(p)
|
|| _get(path, title, acquire_from)
|
||||||
}
|
|
||||||
|
|
||||||
// get title from special paths in path...
|
if(p != null){
|
||||||
for(var i=0; i < acquire_from.length; i++){
|
return p
|
||||||
var p = path.concat([acquire_from[i], title])
|
|
||||||
if(this.exists(p)){
|
|
||||||
return _res(p)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(path.length == 0){
|
if(path.length == 0){
|
||||||
@ -411,33 +418,19 @@ var Wiki = {
|
|||||||
path.pop()
|
path.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// system path...
|
// default paths...
|
||||||
if(this.__system__){
|
var p = _get(path, title, post_acquire_from)
|
||||||
var p = [this.__system__, title]
|
// system path...
|
||||||
if(this.exists(p)){
|
|| this.__system__
|
||||||
return _res(p)
|
&& _get([this.__system__], title)
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
acquire: function(path, title){
|
|
||||||
path = path && normalizePath(path) || this.path
|
|
||||||
title = title || this.title
|
|
||||||
var wiki = this.__wiki_data
|
|
||||||
|
|
||||||
// get the page directly...
|
// NOTE: this may be null...
|
||||||
return (this.exists(path +'/'+ title) && path +'/'+ title)
|
return p
|
||||||
// acquire the page from path...
|
|| (!no_default ? this.acquire(this.__default_page__) : null)
|
||||||
|| this._acquire(title)
|
|
||||||
// acquire the default page...
|
|
||||||
|| this._acquire(this.__default_page__)
|
|
||||||
// nothing found...
|
|
||||||
|| null
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// shorthand...
|
get data(){
|
||||||
acquireData: function(path, title){
|
return this.__wiki_data[this.acquire()]
|
||||||
var page = this.acquire(path, title)
|
|
||||||
return page ? this.__wiki_data[page] : null
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user