mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-27 05:01:57 +00:00
cleaning legacy...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b7276fd174
commit
daf2114508
11
Makefile
11
Makefile
@ -2,6 +2,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
bootstrap.js: scripts/bootstrap.js
|
||||
node $<
|
||||
|
||||
@ -11,6 +12,16 @@ bootstrap.js: scripts/bootstrap.js
|
||||
bootstrap: bootstrap.js
|
||||
|
||||
|
||||
node_modules:
|
||||
npm install
|
||||
|
||||
|
||||
dev: node_modules
|
||||
cp $</ig-object/object.js lib/
|
||||
cp $</ig-actions/actions.js lib/
|
||||
cp $</ig-features/features.js lib/
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
rm -f bootstrap.js
|
||||
|
||||
635
lib/actions.js
635
lib/actions.js
File diff suppressed because it is too large
Load Diff
291
lib/features.js
291
lib/features.js
@ -11,21 +11,19 @@ var object = require('ig-object')
|
||||
var actions = module.actions = require('ig-actions')
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
var FeatureLinearizationError =
|
||||
// XXX use object.Error as base when ready...
|
||||
var FeatureLinearizationError
|
||||
module.FeatureLinearizationError =
|
||||
function(data){
|
||||
this.data = data
|
||||
this.message = 'Failed to linearise.'
|
||||
this.toString = function(){
|
||||
return this.message
|
||||
}
|
||||
}
|
||||
FeatureLinearizationError.prototype = Object.create(new Error)
|
||||
FeatureLinearizationError.prototype.constructor = FeatureLinearizationError
|
||||
|
||||
object.Constructor('FeatureLinearizationError', Error, {
|
||||
get name(){
|
||||
return this.constructor.name },
|
||||
toString: function(){
|
||||
return 'Failed to linearise' },
|
||||
__init__: function(data){
|
||||
this.data = data },
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -113,6 +111,13 @@ object.Constructor('Feature', {
|
||||
//__featureset__: Features,
|
||||
__featureset__: null,
|
||||
|
||||
__verbose: null,
|
||||
get __verbose__(){
|
||||
return this.__verbose == null
|
||||
&& (this.__featureset__ || {}).__verbose__ },
|
||||
set __verbose__(value){
|
||||
this.__verbose = value },
|
||||
|
||||
// Attributes...
|
||||
tag: null,
|
||||
|
||||
@ -145,26 +150,36 @@ object.Constructor('Feature', {
|
||||
: res)
|
||||
: res },
|
||||
|
||||
// XXX this could install the handlers in two locations:
|
||||
// XXX HANDLERS this could install the handlers in two locations:
|
||||
// - the actions object...
|
||||
// - mixin if available...
|
||||
// - base object (currently implemented)
|
||||
// should the first be done?
|
||||
// ...the handlers should theoreticly be stored neither in the
|
||||
// instance nor in the mixin but rather in the action-set itself
|
||||
// on feature creation... (???)
|
||||
// ...feels like user handlers and feature handlers should be
|
||||
// isolated...
|
||||
// XXX setting handlers on the .__proto__ breaks...
|
||||
setup: function(actions){
|
||||
var that = this
|
||||
|
||||
// mixin actions...
|
||||
// NOTE: this will only mixin functions and actions...
|
||||
if(this.actions != null){
|
||||
this.tag ?
|
||||
actions.mixin(this.actions, {source_tag: this.tag})
|
||||
: actions.mixin(this.actions)
|
||||
}
|
||||
// XXX HANDLERS
|
||||
actions.mixin(this.actions, {source_tag: this.tag, action_handlers: true})
|
||||
: actions.mixin(this.actions, {action_handlers: true}) }
|
||||
//actions.mixin(this.actions, {source_tag: this.tag})
|
||||
//: actions.mixin(this.actions) }
|
||||
|
||||
/*/ XXX HANDLERS this is not needed if handlers are local to actions...
|
||||
// install handlers...
|
||||
if(this.handlers != null){
|
||||
this.handlers.forEach(function(h){
|
||||
actions.on(h[0], that.tag, h[1])
|
||||
})
|
||||
}
|
||||
this.handlers.forEach(function([a, h]){
|
||||
//actions.__proto__.on(a, that.tag, h) }) }
|
||||
actions.on(a, that.tag, h) }) }
|
||||
//*/
|
||||
|
||||
// merge config...
|
||||
// NOTE: this will merge the actual config in .config.__proto__
|
||||
@ -173,32 +188,30 @@ object.Constructor('Feature', {
|
||||
|| (this.actions != null
|
||||
&& this.actions.config != null)){
|
||||
// sanity check -- warn of config shadowing...
|
||||
if(this.config && this.actions && this.actions.config){
|
||||
// XXX do we need this???
|
||||
if(this.__verbose__
|
||||
&& this.config && (this.actions || {}).config){
|
||||
console.warn('Feature config shadowed: '
|
||||
+'both .config (used) and .actions.config (ignored) are defined for:',
|
||||
this.tag,
|
||||
this)
|
||||
}
|
||||
this) }
|
||||
|
||||
var config = this.config = this.config || this.actions.config
|
||||
|
||||
if(actions.config == null){
|
||||
actions.config = Object.create({})
|
||||
}
|
||||
Object.keys(config).forEach(function(n){
|
||||
// NOTE: this will overwrite existing values...
|
||||
actions.config.__proto__[n] = config[n]
|
||||
})
|
||||
}
|
||||
actions.config = Object.create({}) }
|
||||
Object.keys(config)
|
||||
.forEach(function(n){
|
||||
// NOTE: this will overwrite existing values...
|
||||
actions.config.__proto__[n] = config[n] }) }
|
||||
|
||||
// custom setup...
|
||||
// XXX is this the correct way???
|
||||
if(this.hasOwnProperty('setup') && this.setup !== Feature.prototype.setup){
|
||||
this.setup(actions)
|
||||
}
|
||||
this.hasOwnProperty('setup')
|
||||
&& this.setup !== Feature.prototype.setup
|
||||
&& this.setup(actions)
|
||||
|
||||
return this
|
||||
},
|
||||
return this },
|
||||
|
||||
// XXX need to revise this...
|
||||
// - .mixout(..) is available directly from the object while
|
||||
@ -206,25 +219,20 @@ object.Constructor('Feature', {
|
||||
// - might be a good idea to add a specific lifecycle actions to
|
||||
// enable feautures to handle their removal correctly...
|
||||
remove: function(actions){
|
||||
if(this.actions != null){
|
||||
actions.mixout(this.tag || this.actions)
|
||||
}
|
||||
this.actions != null
|
||||
&& actions.mixout(this.tag || this.actions)
|
||||
|
||||
if(this.handlers != null){
|
||||
actions.off('*', this.tag)
|
||||
}
|
||||
/*/ XXX HANDLERS do we need this if .handlers if local to action...
|
||||
this.handlers != null
|
||||
&& actions.off('*', this.tag)
|
||||
//*/
|
||||
|
||||
// XXX
|
||||
if(this.hasOwnProperty('remove') && this.setup !== Feature.prototype.remove){
|
||||
this.remove(actions)
|
||||
}
|
||||
// XXX revise naming...
|
||||
this.hasOwnProperty('remove')
|
||||
&& this.setup !== Feature.prototype.remove
|
||||
&& this.remove(actions)
|
||||
|
||||
// remove feature DOM elements...
|
||||
// XXX
|
||||
actions.ribbons.viewer.find('.' + this.tag).remove()
|
||||
|
||||
return this
|
||||
},
|
||||
return this },
|
||||
|
||||
|
||||
// XXX EXPERIMENTAL: if called from a feature-set this will add self
|
||||
@ -246,8 +254,7 @@ object.Constructor('Feature', {
|
||||
// Feature(<feature-set>, <obj>)
|
||||
} else {
|
||||
obj = tag
|
||||
tag = null
|
||||
}
|
||||
tag = null }
|
||||
|
||||
// Feature(<obj>)
|
||||
// NOTE: we need to account for context here -- inc length...
|
||||
@ -257,41 +264,45 @@ object.Constructor('Feature', {
|
||||
// XXX EXPERIMENTAL...
|
||||
feature_set = context instanceof FeatureSet ?
|
||||
context
|
||||
: (this.__featureset__ || Features)
|
||||
}
|
||||
: (this.__featureset__ || Features) }
|
||||
|
||||
if(tag != null && obj.tag != null && obj.tag != tag){
|
||||
throw 'Error: tag and obj.tag mismatch, either use one or both must match.' }
|
||||
throw new Error('tag and obj.tag mismatch, either use one or both must match.') }
|
||||
|
||||
// action...
|
||||
// actions...
|
||||
if(obj instanceof actions.Action){
|
||||
if(tag == null){
|
||||
throw 'Error: need a tag to make a feature out of an action' }
|
||||
var f = {
|
||||
throw new Error('need a tag to make a feature out of an action') }
|
||||
obj = {
|
||||
tag: tag,
|
||||
actions: obj,
|
||||
}
|
||||
obj = f
|
||||
|
||||
// meta-feature...
|
||||
} else if(obj.constructor === Array){
|
||||
if(tag == null){
|
||||
throw 'Error: need a tag to make a meta-feature'
|
||||
}
|
||||
var f = {
|
||||
throw new Error('need a tag to make a meta-feature') }
|
||||
obj = {
|
||||
tag: tag,
|
||||
suggested: obj,
|
||||
}
|
||||
obj = f
|
||||
}
|
||||
} }
|
||||
|
||||
// XXX HANDLERS setup .handlers...
|
||||
if(obj.handlers){
|
||||
obj.actions = obj.actions || {}
|
||||
// NOTE: obj.actions does not have to be an action so w cheat \
|
||||
// a bit here, then copy the mindings...
|
||||
var tmp = Object.create(actions.MetaActions)
|
||||
obj.handlers
|
||||
.forEach(function([a, h]){
|
||||
tmp.on(a, obj.tag, h) })
|
||||
Object.assign(obj.actions, tmp) }
|
||||
|
||||
// feature-set...
|
||||
if(feature_set){
|
||||
feature_set[obj.tag] = obj
|
||||
}
|
||||
feature_set[obj.tag] = obj }
|
||||
|
||||
return obj
|
||||
},
|
||||
return obj },
|
||||
})
|
||||
|
||||
|
||||
@ -369,8 +380,7 @@ object.Constructor('FeatureSet', {
|
||||
}
|
||||
exclusive[e] = (exclusive[e] || []).concat([k])
|
||||
rev_exclusive[k] = (rev_exclusive[k] || []).concat([e]) }) })
|
||||
return exclusive
|
||||
},
|
||||
return exclusive },
|
||||
|
||||
// Build list of features in load order...
|
||||
//
|
||||
@ -491,8 +501,12 @@ object.Constructor('FeatureSet', {
|
||||
// when needed...
|
||||
buildFeatureList: function(lst, isDisabled){
|
||||
var all = this.features
|
||||
lst = (lst == null || lst == '*') ? all : lst
|
||||
lst = lst.constructor !== Array ? [lst] : lst
|
||||
lst = (lst == null || lst == '*') ?
|
||||
all
|
||||
: lst
|
||||
lst = lst instanceof Array ?
|
||||
lst
|
||||
: [lst]
|
||||
|
||||
//isDisabled = isDisabled || function(){ return false }
|
||||
|
||||
@ -519,8 +533,7 @@ object.Constructor('FeatureSet', {
|
||||
// NOTE: Infinity - Infinity is NaN, so we need
|
||||
// to guard against it...
|
||||
return i - j || 0 })
|
||||
.map(function(e){ return e[0] }) })
|
||||
}
|
||||
.map(function(e){ return e[0] }) }) }
|
||||
|
||||
// Expand feature references (recursive)...
|
||||
//
|
||||
@ -546,22 +559,17 @@ object.Constructor('FeatureSet', {
|
||||
console.warn(`Disable loop detected at "${n}" in chain: ${_seen}`)
|
||||
var loop = _seen.slice(_seen.indexOf(n)).concat([n])
|
||||
data.disable_loops = (data.disable_loops || []).push(loop)
|
||||
return false
|
||||
}
|
||||
return false }
|
||||
// XXX STUB -- need to resolve actual loops and
|
||||
// make the disable global...
|
||||
if(n in store){
|
||||
console.warn('Disabling a feature after it is loaded:', n, _seen)
|
||||
}
|
||||
console.warn('Disabling a feature after it is loaded:', n, _seen) }
|
||||
data.disabled.push(n)
|
||||
return false
|
||||
}
|
||||
return false }
|
||||
// skip already disabled features...
|
||||
if(data.disabled.indexOf(n) >= 0){
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
return false }
|
||||
return true })
|
||||
: lst
|
||||
|
||||
// traverse the tree...
|
||||
@ -572,19 +580,15 @@ object.Constructor('FeatureSet', {
|
||||
// exclusive tags...
|
||||
if(f == null && data.exclusive && n in data.exclusive){
|
||||
store[n] = null
|
||||
return false
|
||||
}
|
||||
return false }
|
||||
// feature not defined or is not a feature...
|
||||
if(f == null){
|
||||
data.missing
|
||||
&& data.missing.indexOf(n) < 0
|
||||
&& data.missing.push(n)
|
||||
return false
|
||||
}
|
||||
return n
|
||||
})
|
||||
return false }
|
||||
return n })
|
||||
.filter(function(e){ return e })
|
||||
|
||||
// traverse down...
|
||||
.forEach(function(f){
|
||||
// dependency loop detection...
|
||||
@ -592,13 +596,11 @@ object.Constructor('FeatureSet', {
|
||||
var loop = _seen.slice(_seen.indexOf(f)).concat([f])
|
||||
data.loops
|
||||
&& data.loops.push(loop)
|
||||
return
|
||||
}
|
||||
return }
|
||||
|
||||
// skip already done features...
|
||||
if(f in store){
|
||||
return
|
||||
}
|
||||
return }
|
||||
|
||||
//var feature = store[f] = that[f]
|
||||
var feature = that[f]
|
||||
@ -613,12 +615,9 @@ object.Constructor('FeatureSet', {
|
||||
store[f] = _lst
|
||||
|
||||
// traverse down...
|
||||
expand(target, _lst, store, data, _seen.concat([f]))
|
||||
}
|
||||
})
|
||||
expand(target, _lst, store, data, _seen.concat([f])) } })
|
||||
|
||||
return store
|
||||
}
|
||||
return store }
|
||||
|
||||
// Expand feature dependencies and suggestions recursively...
|
||||
//
|
||||
@ -692,14 +691,11 @@ object.Constructor('FeatureSet', {
|
||||
// mix suggested into features...
|
||||
} else {
|
||||
features[f] = s[f]
|
||||
suggested[f] = (s[f] || []).slice()
|
||||
}
|
||||
})
|
||||
suggested[f] = (s[f] || []).slice() } })
|
||||
|
||||
sortExclusive(features)
|
||||
|
||||
return features
|
||||
}
|
||||
return features }
|
||||
|
||||
|
||||
//--------------------- Globals: filtering / exclusive tags ---
|
||||
@ -748,8 +744,7 @@ object.Constructor('FeatureSet', {
|
||||
|
||||
// link alias to existing feature...
|
||||
} else {
|
||||
var target = candidates[0]
|
||||
}
|
||||
var target = candidates[0] }
|
||||
|
||||
// remove the alias...
|
||||
// NOTE: exclusive tag can match a feature tag, thus
|
||||
@ -766,8 +761,7 @@ object.Constructor('FeatureSet', {
|
||||
&& features[e].splice(i, 1, target)
|
||||
})
|
||||
f = target
|
||||
done.push(f)
|
||||
}
|
||||
done.push(f) }
|
||||
|
||||
// exclusive feature...
|
||||
if(f in rev_exclusive){
|
||||
@ -777,10 +771,7 @@ object.Constructor('FeatureSet', {
|
||||
.filter(function(c){ return c in features })
|
||||
|
||||
if(!(group in conflicts) && candidates.length > 1){
|
||||
conflicts[group] = candidates
|
||||
}
|
||||
}
|
||||
})
|
||||
conflicts[group] = candidates } } })
|
||||
// cleanup...
|
||||
to_remove.forEach(function(f){ delete features[f] })
|
||||
// resolve any exclusivity conflicts found...
|
||||
@ -818,9 +809,7 @@ object.Constructor('FeatureSet', {
|
||||
&& features[f].indexOf(d) >= 0
|
||||
&& disabled.indexOf(f) < 0){
|
||||
expanded_disabled = true
|
||||
disabled.push(f)
|
||||
}
|
||||
})
|
||||
disabled.push(f) } })
|
||||
|
||||
// delete the feature itself...
|
||||
var s = suggests[d] || []
|
||||
@ -838,10 +827,7 @@ object.Constructor('FeatureSet', {
|
||||
.filter(n => n.indexOf(f) >= 0)
|
||||
.length == 0){
|
||||
expanded_disabled = true
|
||||
disabled.push(f)
|
||||
}
|
||||
})
|
||||
})
|
||||
disabled.push(f) } }) })
|
||||
} while(expanded_disabled)
|
||||
|
||||
// remove orphaned features...
|
||||
@ -858,8 +844,7 @@ object.Constructor('FeatureSet', {
|
||||
.forEach(function(f){
|
||||
console.log('ORPHANED:', f)
|
||||
disabled.push(f)
|
||||
delete features[f]
|
||||
})
|
||||
delete features[f] })
|
||||
|
||||
|
||||
//---------------------------------- Stage 2: sort features ---
|
||||
@ -872,8 +857,7 @@ object.Constructor('FeatureSet', {
|
||||
var expanddeps = function(lst, cur, seen){
|
||||
seen = seen || []
|
||||
if(features[cur] == null){
|
||||
return
|
||||
}
|
||||
return }
|
||||
// expand the dep list recursively...
|
||||
// NOTE: this will expand features[cur] in-place while
|
||||
// iterating over it...
|
||||
@ -886,11 +870,7 @@ object.Constructor('FeatureSet', {
|
||||
|
||||
features[cur].forEach(function(e){
|
||||
lst.indexOf(e) < 0
|
||||
&& lst.push(e)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
&& lst.push(e) }) } } }
|
||||
// do the actual expansion...
|
||||
var list = Object.keys(features)
|
||||
list.forEach(function(f){ expanddeps(list, f) })
|
||||
@ -921,8 +901,7 @@ object.Constructor('FeatureSet', {
|
||||
do {
|
||||
var moves = 0
|
||||
if(list.length == 0){
|
||||
break
|
||||
}
|
||||
break }
|
||||
list
|
||||
.slice()
|
||||
.forEach(function(e){
|
||||
@ -941,9 +920,7 @@ object.Constructor('FeatureSet', {
|
||||
// place after last dependency...
|
||||
list.splice(to[1]+1, 0, e)
|
||||
list.splice(from, 1)
|
||||
moves++
|
||||
}
|
||||
})
|
||||
moves++ } })
|
||||
loop_limit--
|
||||
} while(moves > 0 && loop_limit > 0)
|
||||
|
||||
@ -1033,8 +1010,7 @@ object.Constructor('FeatureSet', {
|
||||
// no explicit object is given...
|
||||
if(lst == null){
|
||||
lst = obj
|
||||
obj = null
|
||||
}
|
||||
obj = null }
|
||||
obj = obj || (this.__actions__ || actions.Actions)()
|
||||
lst = lst instanceof Array ? lst : [lst]
|
||||
|
||||
@ -1043,16 +1019,13 @@ object.Constructor('FeatureSet', {
|
||||
(function(n){
|
||||
// if we already tested unapplicable, no need to test again...
|
||||
if(unapplicable.indexOf(n) >= 0){
|
||||
return true
|
||||
}
|
||||
return true }
|
||||
var f = this[n]
|
||||
// check applicability if possible...
|
||||
if(f && f.isApplicable && !f.isApplicable.call(this, obj)){
|
||||
unapplicable.push(n)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}).bind(this))
|
||||
return true }
|
||||
return false }).bind(this))
|
||||
features.unapplicable = unapplicable
|
||||
// cleanup disabled -- filter out unapplicable and excluded features...
|
||||
// NOTE: this is done mainly for cleaner and simpler reporting
|
||||
@ -1081,8 +1054,7 @@ object.Constructor('FeatureSet', {
|
||||
console.error('Exclusive "'+ group +'" conflict at:', error.conflicts[group]) })
|
||||
// report loop limit...
|
||||
error.sort_loop_overflow
|
||||
&& console.error('Hit loop limit while sorting dependencies!')
|
||||
}
|
||||
&& console.error('Hit loop limit while sorting dependencies!') }
|
||||
|
||||
features.FeatureSet = this
|
||||
|
||||
@ -1090,8 +1062,13 @@ object.Constructor('FeatureSet', {
|
||||
|
||||
// fatal error -- can't load...
|
||||
if(fatal){
|
||||
throw new FeatureLinearizationError(features)
|
||||
}
|
||||
throw new FeatureLinearizationError(features) }
|
||||
|
||||
// mixout everything...
|
||||
this.remove(obj,
|
||||
obj.mro('tag')
|
||||
.filter(function(e){
|
||||
return !!e }))
|
||||
|
||||
// do the setup...
|
||||
var that = this
|
||||
@ -1099,13 +1076,11 @@ object.Constructor('FeatureSet', {
|
||||
features.features.forEach(function(n){
|
||||
// setup...
|
||||
if(that[n] != null){
|
||||
this.__verbose__ && console.log('Setting up feature:', n)
|
||||
setup.call(that[n], obj)
|
||||
}
|
||||
})
|
||||
this.__verbose__
|
||||
&& console.log('Setting up feature:', n)
|
||||
setup.call(that[n], obj) } })
|
||||
|
||||
return obj
|
||||
},
|
||||
return obj },
|
||||
|
||||
// XXX revise...
|
||||
// ...the main problem here is that .mixout(..) is accesible
|
||||
@ -1118,7 +1093,8 @@ object.Constructor('FeatureSet', {
|
||||
var that = this
|
||||
lst.forEach(function(n){
|
||||
if(that[n] != null){
|
||||
console.log('Removing feature:', n)
|
||||
this.__verbose__
|
||||
&& console.log('Removing feature:', n)
|
||||
that[n].remove(obj) } }) },
|
||||
|
||||
|
||||
@ -1143,8 +1119,7 @@ object.Constructor('FeatureSet', {
|
||||
})
|
||||
graph += '}'
|
||||
|
||||
return graph
|
||||
},
|
||||
return graph },
|
||||
})
|
||||
|
||||
|
||||
|
||||
2006
lib/object.js
2006
lib/object.js
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@ -4,20 +4,22 @@
|
||||
"author": "Alex A. Naanou <alex.nanou@gmail.com>",
|
||||
"license": "BSD",
|
||||
"dependencies": {
|
||||
"glob": "^7.1.4",
|
||||
"ig-actions": "^1.9.0",
|
||||
"ig-features": "^2.2.6",
|
||||
"ig-object": "^2.0.0",
|
||||
"jszip": "^2.6.1",
|
||||
"peer": "^0.2.10",
|
||||
"pouch-replicate-webrtc": "0.0.9",
|
||||
"pouchdb": "^7.1.1",
|
||||
"requirejs": "^2.3.6",
|
||||
"showdown": "^1.9.0",
|
||||
"xss": "^0.2.13"
|
||||
"glob": "*",
|
||||
"ig-actions": "*",
|
||||
"ig-features": "*",
|
||||
"ig-object": "*",
|
||||
"jszip": "*",
|
||||
"requirejs": "*"
|
||||
},
|
||||
"disabled-dependencies": {
|
||||
"peer": "*",
|
||||
"pouch-replicate-webrtc": "*",
|
||||
"pouchdb": "*",
|
||||
"showdown": "*",
|
||||
"xss": "*"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"bootstrap": "node make_bootstrap.js"
|
||||
"bootstrap": "node scripts/bootstrap.js"
|
||||
}
|
||||
}
|
||||
|
||||
11
pwiki.js
11
pwiki.js
@ -14,7 +14,6 @@ var features = require('lib/features')
|
||||
var macro = require('macro')
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
// Split path into a list and handle special path elements...
|
||||
@ -42,12 +41,15 @@ var macro = require('macro')
|
||||
// NOTE: '>>' has no effect when at last position (XXX ???)
|
||||
var path2list =
|
||||
module.path2list = function(path){
|
||||
return (path instanceof Array ? path : path.split(/[\\\/]+/g))
|
||||
return (path instanceof Array ?
|
||||
path
|
||||
: path.split(/[\\\/]+/g))
|
||||
// handle '..' (lookahead) and trim path elements...
|
||||
// NOTE: this will not touch the leading '.' or '..'
|
||||
.map(function(p, i, l){
|
||||
// remove '..' and '.' out at positions > 0...
|
||||
return (i > 0 && (p.trim() == '..' || p.trim() == '.')
|
||||
return (i > 0
|
||||
&& (p.trim() == '..' || p.trim() == '.')
|
||||
// remove items followed by '..'...
|
||||
|| (l[i+1] || '').trim() == '..'
|
||||
// remove items preceded by '>>'...
|
||||
@ -64,7 +66,8 @@ module.path2list = function(path){
|
||||
//
|
||||
// This is the same as path2list(..) but also joins the path with '/'
|
||||
var normalizePath =
|
||||
module.normalizePath = function(path){ return path2list(path).join('/') }
|
||||
module.normalizePath = function(path){
|
||||
return path2list(path).join('/') }
|
||||
|
||||
|
||||
var path2re =
|
||||
|
||||
10
wiki.js
10
wiki.js
@ -16,17 +16,21 @@ RegExp.quoteRegExp =
|
||||
.replace(/([\.\\\/\(\)\[\]\$\*\+\-\{\}\@\^\&\?\<\>])/g, '\\$1') }
|
||||
|
||||
var path2lst = function(path){
|
||||
return (path instanceof Array ? path : path.split(/[\\\/]+/g))
|
||||
return (path instanceof Array ?
|
||||
path
|
||||
: path.split(/[\\\/]+/g))
|
||||
// handle '..' (lookahead) and trim path elements...
|
||||
// NOTE: this will not touch the leading '.' or '..'
|
||||
.map(function(p, i, l){
|
||||
return (i > 0 && (p.trim() == '..' || p.trim() == '.')
|
||||
return (i > 0
|
||||
&& (p.trim() == '..' || p.trim() == '.')
|
||||
|| (l[i+1] || '').trim() == '..') ?
|
||||
null
|
||||
: p.trim() })
|
||||
// cleanup and clear '.'...
|
||||
.filter(function(p){
|
||||
return p != null && p != '' })}
|
||||
return p != null
|
||||
&& p != '' })}
|
||||
|
||||
var normalizePath = function(path){
|
||||
return path2lst(path).join('/') }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user