mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
added basic aquisition mechanics + started templates...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
0a583db1e4
commit
5ed51c559d
86
wiki.js
86
wiki.js
@ -22,11 +22,8 @@
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
var data = {
|
var data = {
|
||||||
'/': {
|
'TemplatePages/DefaultPage': {
|
||||||
text: 'base page...'
|
text: 'This page is empty.<br><br>WikiHome',
|
||||||
},
|
|
||||||
'dir/page': {
|
|
||||||
text: 'some text...'
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,9 +43,14 @@ var normalizePath = path =>
|
|||||||
var Wiki = {
|
var Wiki = {
|
||||||
__wiki_data: data,
|
__wiki_data: data,
|
||||||
|
|
||||||
|
__home_page__: 'WikiHome',
|
||||||
|
__default_page__: 'DefaultPage',
|
||||||
|
__templates__: 'TemplatePages',
|
||||||
|
|
||||||
|
|
||||||
// current location...
|
// current location...
|
||||||
get location(){
|
get location(){
|
||||||
return this.__location || '/' },
|
return this.__location || this.__home_page__ },
|
||||||
set location(value){
|
set location(value){
|
||||||
this.__location = normalizePath(value) },
|
this.__location = normalizePath(value) },
|
||||||
|
|
||||||
@ -89,8 +91,13 @@ var Wiki = {
|
|||||||
|
|
||||||
|
|
||||||
// page content...
|
// page content...
|
||||||
|
//
|
||||||
|
// NOTE: if this page has not text, this will get the DefaultPage...
|
||||||
|
// XXX should this get the DefaultPage or the EmptyPage???
|
||||||
get text(){
|
get text(){
|
||||||
return (this.__wiki_data[this.location] || {}).text || ''
|
return (this.__wiki_data[this.location] || {}).text
|
||||||
|
|| (this.acquire(this.__default_page__) || {}).text
|
||||||
|
|| ''
|
||||||
},
|
},
|
||||||
set text(value){
|
set text(value){
|
||||||
var l = this.location
|
var l = this.location
|
||||||
@ -112,21 +119,62 @@ var Wiki = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
exists: function(path){
|
||||||
|
return normalizePath(path) in this.__wiki_data },
|
||||||
|
// get title from dir and then go up the tree...
|
||||||
|
acquire: function(title){
|
||||||
|
title = title || this.__default_page__
|
||||||
|
var templates = this.__templates__
|
||||||
|
var data = this.__wiki_data
|
||||||
|
var that = this
|
||||||
|
|
||||||
// serialization...
|
var path = path2lst(this.dir)
|
||||||
get json(){
|
|
||||||
return {
|
var _res = function(p){
|
||||||
path: this.path,
|
return {
|
||||||
text: this.text,
|
dir: normalizePath(p.slice(0, -1)),
|
||||||
|
title: title,
|
||||||
|
text: that.__wiki_data[normalizePath(p)].text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
// get title from path...
|
||||||
|
var p = path.concat([title])
|
||||||
|
if(this.exists(p)){
|
||||||
|
return _res(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// get title from templates in path...
|
||||||
|
var p = path.concat([templates, title])
|
||||||
|
if(this.exists(p)){
|
||||||
|
return _res(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(path.length == 0){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
path.pop()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set json(value){
|
|
||||||
if(value.title){
|
|
||||||
this.title = value.title
|
// serialization...
|
||||||
}
|
json: function(path){
|
||||||
if(value.text){
|
return path == null ? JSON.parse(JSON.stringify(this.__wiki_data))
|
||||||
this.text = value.text
|
: path == '.' ? {
|
||||||
}
|
path: this.location,
|
||||||
|
text: this.text,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
path: path,
|
||||||
|
text: (this.__wiki_data[path] || {}).text,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// XXX should we inherit from the default???
|
||||||
|
load: function(json){
|
||||||
|
this.__wiki_data = json
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user