mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 16:41:39 +00:00
started cleanup of gen2...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
78311eb5b9
commit
4e1d04bc12
@ -31,6 +31,8 @@
|
|||||||
<script src="ext-lib/pouchdb.min.js"></script>
|
<script src="ext-lib/pouchdb.min.js"></script>
|
||||||
<script src="ext-lib/peer.min.js"></script>
|
<script src="ext-lib/peer.min.js"></script>
|
||||||
|
|
||||||
|
<script data-main="ui" src="ext-lib/require.js"></script>
|
||||||
|
|
||||||
<script src="bootstrap.js"></script>
|
<script src="bootstrap.js"></script>
|
||||||
<script src="wiki.js"></script>
|
<script src="wiki.js"></script>
|
||||||
|
|
||||||
|
|||||||
106
pwiki.js
106
pwiki.js
@ -35,10 +35,12 @@ var normalizePath = function(path){ return path2list(path).join('/') }
|
|||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
// base pWiki object...
|
// base pWiki object...
|
||||||
var pWiki = object.makeConstructor('pWiki', actions.MetaActions)
|
var pWiki =
|
||||||
|
module.pWiki = object.makeConstructor('pWiki', actions.MetaActions)
|
||||||
|
|
||||||
// pWiki featureset...
|
// pWiki featureset...
|
||||||
var pWikiFeatures = new features.FeatureSet()
|
var pWikiFeatures =
|
||||||
|
module.pWikiFeatures = new features.FeatureSet()
|
||||||
|
|
||||||
// base instance constructor...
|
// base instance constructor...
|
||||||
pWikiFeatures.__actions__ =
|
pWikiFeatures.__actions__ =
|
||||||
@ -52,17 +54,29 @@ pWikiFeatures.__actions__ =
|
|||||||
// XXX should we combine page and wiki api???
|
// XXX should we combine page and wiki api???
|
||||||
// - pWikiData is wiki api
|
// - pWikiData is wiki api
|
||||||
// - pWiki is page api
|
// - pWiki is page api
|
||||||
var pWikiData = {
|
var pWikiData =
|
||||||
|
module.pWikiData = {
|
||||||
__data: null,
|
__data: null,
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
search: function(query){
|
||||||
|
},
|
||||||
|
|
||||||
// get a list of matching paths...
|
// get a list of matching paths...
|
||||||
// XXX sort API???
|
// XXX sort API???
|
||||||
// ...results shoulde be sorted via the saved order if available...
|
// ...results shoulde be sorted via the saved order if available...
|
||||||
// .....or should this be done at a later stage as in gen1???
|
// .....or should this be done at a later stage as in gen1???
|
||||||
|
// XXX BUG: '**' does not list all the pages while '/**' does...
|
||||||
match: function(path){
|
match: function(path){
|
||||||
// path patterns -- "*"
|
var data = this.__data || {}
|
||||||
if(path.indexOf('*') >= 0){
|
|
||||||
return [ path ]
|
if(path == null){
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
// strict path...
|
||||||
|
if(path.indexOf('*') <= 0){
|
||||||
|
return path in data ? [ path ] : []
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the tail...
|
// get the tail...
|
||||||
@ -79,7 +93,6 @@ var pWikiData = {
|
|||||||
.replace(/^\*|([^.])\*/g, '$1[^\\/]*')
|
.replace(/^\*|([^.])\*/g, '$1[^\\/]*')
|
||||||
+'$')
|
+'$')
|
||||||
|
|
||||||
var data = this.__data || {}
|
|
||||||
return Object.keys(data)
|
return Object.keys(data)
|
||||||
// XXX is this correct???
|
// XXX is this correct???
|
||||||
.concat(Object.keys(data.__proto__)
|
.concat(Object.keys(data.__proto__)
|
||||||
@ -129,6 +142,12 @@ var pWikiData = {
|
|||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
json: function(data){
|
json: function(data){
|
||||||
|
if(arguments.length == 0){
|
||||||
|
return JSON.parse(JSON.stringify(this.__data))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.__data = data
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +156,8 @@ var pWikiData = {
|
|||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
// XXX need a startup sequence...
|
// XXX need a startup sequence...
|
||||||
var pWikiPageActions = actions.Actions({
|
var pWikiPageActions =
|
||||||
|
module.pWikiPageActions = actions.Actions({
|
||||||
config: {
|
config: {
|
||||||
'home-page': 'WikiHome',
|
'home-page': 'WikiHome',
|
||||||
'default-page': 'EmptyPage',
|
'default-page': 'EmptyPage',
|
||||||
@ -163,27 +183,33 @@ var pWikiPageActions = actions.Actions({
|
|||||||
get length(){
|
get length(){
|
||||||
return this.wiki.match(this.location().path).length },
|
return this.wiki.match(this.location().path).length },
|
||||||
|
|
||||||
|
// XXX avoid recursive calls to things like .base(), .title(), ...
|
||||||
|
// resolve relative paths (with pattern location)
|
||||||
|
// -> current path
|
||||||
|
// -> order list (+ index)
|
||||||
|
// -> parent (relative path)
|
||||||
|
// (recur)
|
||||||
resolve: ['Path/Resolve relative path and expand path variables',
|
resolve: ['Path/Resolve relative path and expand path variables',
|
||||||
function(path){
|
function(path){
|
||||||
path = normalizePath(path)
|
path = normalizePath(path)
|
||||||
|
|
||||||
// path variables...
|
// path variables...
|
||||||
// XXX make this more modular...
|
// XXX make this more modular...
|
||||||
path
|
path = path
|
||||||
.replace(/\$NOW|\$\{NOW\}/g, Date.now())
|
.replace(/\$NOW|\$\{NOW\}/g, Date.now())
|
||||||
.replace(/\$TITLE|\$\{TITLE\}/g, this.title())
|
|
||||||
.replace(/\$BASE|\$\{BASE\}/g, this.base())
|
|
||||||
.replace(/\$INDEX|\$\{INDEX\}/g, this.at())
|
.replace(/\$INDEX|\$\{INDEX\}/g, this.at())
|
||||||
|
//.replace(/\$TITLE|\$\{TITLE\}/g, this.title())
|
||||||
|
//.replace(/\$BASE|\$\{BASE\}/g, this.base())
|
||||||
|
|
||||||
// relative paths -- "." and ".."
|
// relative paths -- "." and ".."
|
||||||
if(path.indexOf('.') >= 0){
|
if(path.indexOf('.') >= 0){
|
||||||
path =
|
path =
|
||||||
// '.' or './*'
|
// '.' or './*'
|
||||||
path == '.' || /^\.\//.test(path) ?
|
path == '.' || /^\.\//.test(path) ?
|
||||||
path.replace(/^\./, this.base)
|
normalizePath(path.replace(/^\./, this.path()))
|
||||||
// '..' or '../*'
|
// '..' or '../*'
|
||||||
: path == '..' || /^\.\.\//.test(path) ?
|
: path == '..' || /^\.\.\//.test(path) ?
|
||||||
path.replace(/^\.\./, this.base)
|
normalizePath(path.replace(/^\.\./, this.base()))
|
||||||
: path
|
: path
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +221,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
// handle paths and relative paths...
|
// handle paths and relative paths...
|
||||||
var p = this.get(path)
|
var p = this.get(path || this.path())
|
||||||
var title = p.title()
|
var title = p.title()
|
||||||
path = path2list(p.base())
|
path = path2list(p.base())
|
||||||
|
|
||||||
@ -205,7 +231,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
var _get = function(path, title, lst){
|
var _get = function(path, title, lst){
|
||||||
lst = (lst == null || lst.length == 0) ? [''] : lst
|
lst = (lst == null || lst.length == 0) ? [''] : lst
|
||||||
for(var i=0; i < lst.length; i++){
|
for(var i=0; i < lst.length; i++){
|
||||||
var p = path.concat([lst[i], title])
|
var p = normalizePath(path.concat([lst[i], title]))
|
||||||
if(that.exists(p)){
|
if(that.exists(p)){
|
||||||
p = normalizePath(p)
|
p = normalizePath(p)
|
||||||
return that.wiki.data(p) && p
|
return that.wiki.data(p) && p
|
||||||
@ -245,7 +271,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
|
|
||||||
location: ['Page/Get or set location',
|
location: ['Page/Get or set location',
|
||||||
function(value){
|
function(value){
|
||||||
if(value == null){
|
if(value === null){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,24 +301,24 @@ var pWikiPageActions = actions.Actions({
|
|||||||
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){
|
||||||
var location = this.location()
|
return this.order(true)[this.at()]
|
||||||
return this.order(true)[location.at]
|
|
||||||
//return this.wiki.match(location.path)[location.at]
|
|
||||||
|
|
||||||
// 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)
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
title: ['Page/Get or set title',
|
title: ['Page/Get or set title',
|
||||||
function(value){
|
function(value){
|
||||||
if(arguments.length == 0){
|
if(arguments.length == 0){
|
||||||
return path2list(this.path()).pop()
|
return path2list(this.path()).pop() || ''
|
||||||
|
|
||||||
} else if(value != null){
|
} else if(value != null){
|
||||||
this.path(this.base() +'/'+ value)
|
this.path(this.base() +'/'+ value)
|
||||||
}
|
}
|
||||||
}]
|
}],
|
||||||
base: ['Page/Get or set directory',
|
base: ['Page/Get or set directory',
|
||||||
function(base){
|
function(base){
|
||||||
if(arguments.length == 0){
|
if(arguments.length == 0){
|
||||||
@ -301,7 +327,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
} else if(base != null){
|
} else if(base != null){
|
||||||
this.path(base +'/'+ this.title())
|
this.path(base +'/'+ this.title())
|
||||||
}
|
}
|
||||||
}]
|
}],
|
||||||
|
|
||||||
attr: ['Page/Get or set attribute',
|
attr: ['Page/Get or set attribute',
|
||||||
function(name, value){
|
function(name, value){
|
||||||
@ -328,8 +354,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
exists: ['Page/Check if path explicitly exists.',
|
exists: ['Page/Check if path explicitly exists.',
|
||||||
function(path){
|
function(path){
|
||||||
path = path || this.path()
|
path = path || this.path()
|
||||||
var location = this.location()
|
return this.wiki.match(this.get(path).location().path)[this.at()] !== undefined
|
||||||
return this.wiki.match(location.path)[location.at] !== undefined
|
|
||||||
}],
|
}],
|
||||||
// Format:
|
// Format:
|
||||||
// {
|
// {
|
||||||
@ -346,11 +371,11 @@ var pWikiPageActions = actions.Actions({
|
|||||||
function(value){
|
function(value){
|
||||||
// get -> acquire page and get it's data...
|
// get -> acquire page and get it's data...
|
||||||
if(arguments.length == 0){
|
if(arguments.length == 0){
|
||||||
return this.wiki.data(this.acquire())
|
return this.wiki.data(this.acquire()) || {}
|
||||||
|
|
||||||
// set -> get explicit path and set data to it...
|
// set -> get explicit path and set data to it...
|
||||||
} else if(value != null) {
|
} else if(value != null) {
|
||||||
this.wiki.data(this.path(), value || '')
|
this.wiki.data(this.path(), value || {})
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
clear: ['Page/Clear page',
|
clear: ['Page/Clear page',
|
||||||
@ -361,7 +386,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
function(){
|
function(){
|
||||||
//var o = (new this.constructor())
|
//var o = (new this.constructor())
|
||||||
var o = Object.create(this)
|
var o = Object.create(this)
|
||||||
.location(this.location())
|
.location(JSON.parse(JSON.stringify(this.location())))
|
||||||
|
|
||||||
o.__parent_context = this
|
o.__parent_context = this
|
||||||
if(this.__order){
|
if(this.__order){
|
||||||
@ -476,10 +501,19 @@ var pWikiPageActions = actions.Actions({
|
|||||||
// XXX test...
|
// XXX test...
|
||||||
order: ['Page/Get or set sibling pages order',
|
order: ['Page/Get or set sibling pages order',
|
||||||
function(order){
|
function(order){
|
||||||
var parent = this.get('..')
|
var path = this.location().path || ''
|
||||||
var path = this.location().path
|
|
||||||
var full_paths = false
|
var full_paths = false
|
||||||
|
|
||||||
|
// no patterns in path -> no ordering...
|
||||||
|
if(path.indexOf('*') < 0){
|
||||||
|
return [ path ]
|
||||||
|
}
|
||||||
|
|
||||||
|
// store order in a pecific path pattern...
|
||||||
|
// NOTE: each path pattern may have a different order...
|
||||||
|
// XXX
|
||||||
|
var parent = this.get(path)
|
||||||
|
|
||||||
// get full paths...
|
// get full paths...
|
||||||
if(order === true || order === false){
|
if(order === true || order === false){
|
||||||
full_paths = order
|
full_paths = order
|
||||||
@ -534,7 +568,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
// get pages not in order...
|
// get pages not in order...
|
||||||
pages = pages
|
pages = pages
|
||||||
.filter(function(p){
|
.filter(function(p){
|
||||||
return order.indexOf(p) < 0 }))
|
return order.indexOf(p) < 0 })
|
||||||
// build the list...
|
// build the list...
|
||||||
return unsorted_first ?
|
return unsorted_first ?
|
||||||
pages.concat(order)
|
pages.concat(order)
|
||||||
@ -545,7 +579,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
return pages
|
return pages
|
||||||
}
|
}
|
||||||
|
|
||||||
// set global manual order...
|
// set persistent manual order...
|
||||||
// XXX ugly -- revise...
|
// XXX ugly -- revise...
|
||||||
// check if we have a pattern...
|
// check if we have a pattern...
|
||||||
} else if(path2list(path).pop().indexOf('*') >= 0
|
} else if(path2list(path).pop().indexOf('*') >= 0
|
||||||
@ -725,7 +759,7 @@ var pWikiPageActions = actions.Actions({
|
|||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
var pWikiPage = pWikiFeatures.Featre({
|
var pWikiPage = pWikiFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
tag: 'page',
|
tag: 'page',
|
||||||
|
|
||||||
@ -736,7 +770,7 @@ var pWikiPage = pWikiFeatures.Featre({
|
|||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
var pWikiLocalStorage = pWikiFeatures.Featre({
|
var pWikiLocalStorage = pWikiFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
tag: 'localstorage-store',
|
tag: 'localstorage-store',
|
||||||
|
|
||||||
@ -772,14 +806,14 @@ var pWikiLocalStorage = pWikiFeatures.Featre({
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var pWikiPouchDBStore = pWikiFeatures.Featre({
|
var pWikiPouchDBStore = pWikiFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
tag: 'pouchdb-store',
|
tag: 'pouchdb-store',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var pWikiPeerJSSync = pWikiFeatures.Featre({
|
var pWikiPeerJSSync = pWikiFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
tag: 'peerjs-sync',
|
tag: 'peerjs-sync',
|
||||||
})
|
})
|
||||||
@ -814,7 +848,7 @@ var pWikiUIActions = actions.Actions({
|
|||||||
toggleEdit: ['', function(){}],
|
toggleEdit: ['', function(){}],
|
||||||
})
|
})
|
||||||
|
|
||||||
var pWikiUI = pWikiFeatures.Featre({
|
var pWikiUI = pWikiFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
tag: 'ui',
|
tag: 'ui',
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user