mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-27 05:01:57 +00:00
added path match caching...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
48c2d3d41c
commit
edafae8605
70
pwiki.js
70
pwiki.js
@ -328,17 +328,37 @@ module.pWikiBase = actions.Actions({
|
|||||||
json: ['', function(){ }],
|
json: ['', function(){ }],
|
||||||
|
|
||||||
|
|
||||||
|
// Refresh path cache...
|
||||||
|
//
|
||||||
|
refresh: ['',
|
||||||
|
function(force){
|
||||||
|
// get/set location and base fields...
|
||||||
|
var location = this.__location = this.__location || {}
|
||||||
|
var path = location.path = location.path
|
||||||
|
|| this.config['home-path']
|
||||||
|
|| 'WikiHome'
|
||||||
|
var at = location.at || 0
|
||||||
|
|
||||||
|
// get location cache...
|
||||||
|
var match = location.match
|
||||||
|
|
||||||
|
// refresh the cache...
|
||||||
|
if(match == null || force){
|
||||||
|
location.match = this.order()
|
||||||
|
location.at = at
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
|
||||||
|
|
||||||
get length(){
|
get length(){
|
||||||
// special case -- non-pattern path that does not exist...
|
// special case -- non-pattern path...
|
||||||
if(this.location().path.indexOf('*') < 0
|
if(this.location().path.indexOf('*') < 0){
|
||||||
&& !this.exists()){
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.wiki.match(this.location().path)
|
this.refresh()
|
||||||
// skip special paths containing '*'...
|
|
||||||
.filter(function(p){ return p.indexOf('*') < 0 })
|
return this.location().match.length
|
||||||
.length
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -459,42 +479,43 @@ module.pWikiBase = actions.Actions({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX should we set/return a default empty value here???
|
var location = this.__location || this.refresh().location()
|
||||||
this.__location = this.__location || {}
|
|
||||||
|
|
||||||
// get location...
|
// get location...
|
||||||
if(arguments.length == 0){
|
if(arguments.length == 0){
|
||||||
return this.__location || this.config['home-page']
|
return location
|
||||||
}
|
}
|
||||||
|
|
||||||
// set location index...
|
// set location index...
|
||||||
if(typeof(value) == typeof(123)){
|
if(typeof(value) == typeof(123)){
|
||||||
this.__location.at = value
|
location.at = value
|
||||||
|
|
||||||
// set location path...
|
// set location path...
|
||||||
} else if(typeof(value) == typeof('str')){
|
} else if(typeof(value) == typeof('str')){
|
||||||
this.__location.path = this.resolve(value)
|
location.path = this.resolve(value)
|
||||||
this.__location.at = 0
|
location.at = 0
|
||||||
|
|
||||||
// object...
|
// object...
|
||||||
} else {
|
} else {
|
||||||
this.__location = value
|
this.__location = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.refresh(true)
|
||||||
}],
|
}],
|
||||||
// XXX pattern does not match anything needs to be handled correctly...
|
// XXX pattern does not match anything needs to be handled correctly...
|
||||||
|
// XXX do we need to normalize 'at'???
|
||||||
path: ['Page/Get or set path',
|
path: ['Page/Get or set path',
|
||||||
function(value){
|
function(value){
|
||||||
// get explcit path from location (acounting for 'at')...
|
// get explcit path from location (acounting for 'at')...
|
||||||
if(arguments.length == 0){
|
if(arguments.length == 0){
|
||||||
return this.order(true)[this.at()]
|
var location = this.location()
|
||||||
// nothing matched the pattern...
|
return location.match[location.at]
|
||||||
|| this.config['no-match-page']
|
|| this.config['no-match-page']
|
||||||
|| ''
|
|| ''
|
||||||
|
|
||||||
// move page to path...
|
// move page to path...
|
||||||
} else if(value != null) {
|
} else if(value != null) {
|
||||||
this.wiki.move(this.path(), this.resolve(value))
|
this.wiki.move(this.path(), this.resolve(value))
|
||||||
// XXX
|
|
||||||
this.location(value)
|
this.location(value)
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
@ -519,15 +540,16 @@ module.pWikiBase = actions.Actions({
|
|||||||
|
|
||||||
exists: ['Page/Check if path explicitly exists.',
|
exists: ['Page/Check if path explicitly exists.',
|
||||||
function(path){
|
function(path){
|
||||||
|
var at = path ? 0 : this.at()
|
||||||
path = path || this.path()
|
path = path || this.path()
|
||||||
return this.wiki.match(this.get(path).location().path)[this.at()] !== undefined
|
|
||||||
|
return this.wiki.match(this.get(path).location().path)[at] !== undefined
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// NOTE: a clone references the same data and .config, no copying
|
// NOTE: a clone references the same data and .config, no copying
|
||||||
// is done.
|
// is done.
|
||||||
clone: ['Page/Get page clone (new reference)',
|
clone: ['Page/Get page clone (new reference)',
|
||||||
function(){
|
function(){
|
||||||
//var o = (new this.constructor())
|
|
||||||
var o = Object.create(this)
|
var o = Object.create(this)
|
||||||
.location(JSON.parse(JSON.stringify(this.location())))
|
.location(JSON.parse(JSON.stringify(this.location())))
|
||||||
|
|
||||||
@ -632,11 +654,6 @@ module.pWikiBase = actions.Actions({
|
|||||||
//
|
//
|
||||||
// Get order (title)...
|
// Get order (title)...
|
||||||
// .order()
|
// .order()
|
||||||
// .order(false)
|
|
||||||
// -> order
|
|
||||||
//
|
|
||||||
// Get order (full paths)...
|
|
||||||
// .order(true)
|
|
||||||
// -> order
|
// -> order
|
||||||
//
|
//
|
||||||
// Save local order (.__order)...
|
// Save local order (.__order)...
|
||||||
@ -679,14 +696,9 @@ module.pWikiBase = actions.Actions({
|
|||||||
// XXX should we check if this returns a function???
|
// XXX should we check if this returns a function???
|
||||||
var parent = this.wiki.data(path) || {}
|
var parent = this.wiki.data(path) || {}
|
||||||
|
|
||||||
// get full paths...
|
|
||||||
if(order === true || order === false){
|
|
||||||
full_paths = order
|
|
||||||
order = null
|
|
||||||
|
|
||||||
// save local order...
|
// save local order...
|
||||||
// XXX this is wrong!!!
|
// XXX this is wrong!!!
|
||||||
} else if(order == 'local'){
|
if(order == 'local'){
|
||||||
order = this.__order
|
order = this.__order
|
||||||
|
|
||||||
// save current order...
|
// save current order...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user