2016-07-04 19:51:37 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
|
|
//var DEBUG = DEBUG != null ? DEBUG : true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// data store...
|
|
|
|
|
// Format:
|
|
|
|
|
// {
|
|
|
|
|
// <path>: {
|
|
|
|
|
// text: <text>,
|
|
|
|
|
//
|
|
|
|
|
// links: [
|
|
|
|
|
// <offset>: <link>,
|
|
|
|
|
// ],
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
var data = {
|
2016-07-05 03:14:00 +03:00
|
|
|
'/': {
|
|
|
|
|
text: 'base page...'
|
|
|
|
|
},
|
2016-07-04 20:42:46 +03:00
|
|
|
'dir/page': {
|
|
|
|
|
text: 'some text...'
|
|
|
|
|
},
|
2016-07-04 19:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 20:42:46 +03:00
|
|
|
var path2lst = path =>
|
|
|
|
|
(path instanceof Array ?
|
|
|
|
|
path
|
|
|
|
|
: path.split(/[\\\/]+/g))
|
|
|
|
|
.map(p => p.trim())
|
|
|
|
|
.filter(p =>
|
|
|
|
|
p != '' && p != '.')
|
|
|
|
|
|
|
|
|
|
var normalizePath = path =>
|
|
|
|
|
path2lst(path).join('/')
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 19:51:37 +03:00
|
|
|
var Wiki = {
|
2016-07-04 20:42:46 +03:00
|
|
|
__wiki_data: data,
|
2016-07-04 19:51:37 +03:00
|
|
|
|
2016-07-04 20:42:46 +03:00
|
|
|
// current location...
|
2016-07-04 19:51:37 +03:00
|
|
|
get location(){
|
2016-07-04 20:42:46 +03:00
|
|
|
return this.__location || '/' },
|
2016-07-04 19:51:37 +03:00
|
|
|
set location(value){
|
2016-07-04 20:42:46 +03:00
|
|
|
this.__location = normalizePath(value) },
|
2016-07-04 19:51:37 +03:00
|
|
|
|
2016-07-04 20:42:46 +03:00
|
|
|
// page path...
|
|
|
|
|
//
|
|
|
|
|
// Format:
|
|
|
|
|
// <dir>/<title>
|
|
|
|
|
//
|
|
|
|
|
// NOTE: changing this will move the page to the new path and change
|
|
|
|
|
// .location acordingly...
|
|
|
|
|
// NOTE: same applies to path parts below...
|
|
|
|
|
get path(){
|
|
|
|
|
return this.location },
|
2016-07-04 19:51:37 +03:00
|
|
|
set path(value){
|
2016-07-04 20:42:46 +03:00
|
|
|
var l = this.location
|
|
|
|
|
value = normalizePath(value)
|
|
|
|
|
|
|
|
|
|
this.__wiki_data[value] = this.__wiki_data[l] || {}
|
|
|
|
|
this.location = value
|
|
|
|
|
delete this.__wiki_data[l]
|
2016-07-04 19:51:37 +03:00
|
|
|
},
|
|
|
|
|
|
2016-07-04 20:42:46 +03:00
|
|
|
// path parts: directory...
|
|
|
|
|
//
|
|
|
|
|
// NOTE: see .path for details...
|
|
|
|
|
get dir(){
|
|
|
|
|
return path2lst(this.location).slice(0, -1).join('/') },
|
|
|
|
|
set dir(value){
|
|
|
|
|
this.path = value +'/'+ this.title },
|
|
|
|
|
|
|
|
|
|
// path parts: title...
|
|
|
|
|
//
|
|
|
|
|
// NOTE: see .path for details...
|
|
|
|
|
get title(){
|
|
|
|
|
return path2lst(this.location).pop() },
|
|
|
|
|
set title(value){
|
|
|
|
|
this.path = this.dir +'/'+ value },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// page content...
|
2016-07-04 19:51:37 +03:00
|
|
|
get text(){
|
2016-07-04 20:42:46 +03:00
|
|
|
return (this.__wiki_data[this.location] || {}).text || ''
|
2016-07-04 19:51:37 +03:00
|
|
|
},
|
|
|
|
|
set text(value){
|
2016-07-04 20:42:46 +03:00
|
|
|
var l = this.location
|
|
|
|
|
this.__wiki_data[l] = this.__wiki_data[l] || {}
|
|
|
|
|
this.__wiki_data[l].text = value
|
2016-07-04 19:51:37 +03:00
|
|
|
},
|
|
|
|
|
|
2016-07-04 20:42:46 +03:00
|
|
|
// XXX
|
|
|
|
|
get links(){
|
2016-07-04 19:51:37 +03:00
|
|
|
},
|
2016-07-04 20:42:46 +03:00
|
|
|
set links(value){
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// XXX
|
|
|
|
|
get list(){
|
|
|
|
|
},
|
|
|
|
|
set list(value){
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// serialization...
|
|
|
|
|
get json(){
|
|
|
|
|
return {
|
|
|
|
|
path: this.path,
|
|
|
|
|
text: this.text,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
set json(value){
|
|
|
|
|
if(value.title){
|
|
|
|
|
this.title = value.title
|
|
|
|
|
}
|
|
|
|
|
if(value.text){
|
|
|
|
|
this.text = value.text
|
|
|
|
|
}
|
2016-07-04 19:51:37 +03:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* vim:set ts=4 sw=4 : */
|