mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 16:41:39 +00:00
working on pages...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6f3a0c75a6
commit
cd5171848f
12
Makefile
12
Makefile
@ -1,10 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOTSTRAP_FILES := \
|
BOOTSTRAP_FILES := \
|
||||||
$(wildcard bootstrap/*) \
|
$(wildcard bootstrap/*) \
|
||||||
$(wildcard bootstrap/*/*) \
|
$(wildcard bootstrap/*/*) \
|
||||||
README.md
|
README.md
|
||||||
|
|
||||||
|
LOCAL_MODULES := \
|
||||||
|
node_modules/ig-object/object.js \
|
||||||
|
node_modules/ig-actions/actions.js \
|
||||||
|
node_modules/ig-features/features.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -21,11 +26,8 @@ node_modules:
|
|||||||
npm install
|
npm install
|
||||||
|
|
||||||
|
|
||||||
dev: node_modules
|
dev: node_modules $(LOCAL_MODULES)
|
||||||
cp $</ig-object/object.js lib/
|
cp $(LOCAL_MODULES) lib/
|
||||||
cp $</ig-actions/actions.js lib/
|
|
||||||
cp $</ig-features/features.js lib/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
93
pwiki2.js
93
pwiki2.js
@ -20,6 +20,10 @@
|
|||||||
(function(require){ var module={} // make module AMD/node compatible...
|
(function(require){ var module={} // make module AMD/node compatible...
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
//var object = require('lib/object')
|
||||||
|
var object = require('ig-object')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
@ -138,7 +142,11 @@ module.path = {
|
|||||||
var store =
|
var store =
|
||||||
module.store = {
|
module.store = {
|
||||||
exists: function(path){
|
exists: function(path){
|
||||||
return module.path.normalize(path, 'string') in this },
|
path = module.path.normalize(path, 'string')
|
||||||
|
return path in this
|
||||||
|
|| (path[0] == '/' ?
|
||||||
|
path.slice(1) in this
|
||||||
|
: ('/'+ path) in this) },
|
||||||
|
|
||||||
paths: function(){
|
paths: function(){
|
||||||
return Object.keys(this) },
|
return Object.keys(this) },
|
||||||
@ -268,7 +276,7 @@ module.actions = {
|
|||||||
__proto__: store,
|
__proto__: store,
|
||||||
|
|
||||||
// base actions (virtual pages)...
|
// base actions (virtual pages)...
|
||||||
'/System/raw': function(page, path){
|
'System/raw': function(page, path){
|
||||||
return { text: this.get(path +'/..') } },
|
return { text: this.get(path +'/..') } },
|
||||||
// XXX ...
|
// XXX ...
|
||||||
}
|
}
|
||||||
@ -284,31 +292,66 @@ function(name){
|
|||||||
...args) } }
|
...args) } }
|
||||||
|
|
||||||
// page interface...
|
// page interface...
|
||||||
var page =
|
var BasePage =
|
||||||
module.page = {
|
module.BasePage =
|
||||||
|
object.Constructor('BasePage', {
|
||||||
store: undefined,
|
store: undefined,
|
||||||
|
|
||||||
path: undefined,
|
path: undefined,
|
||||||
referrer: undefined,
|
referrer: undefined,
|
||||||
|
|
||||||
text: undefined,
|
get data(){
|
||||||
|
return this.store.get(this.path) },
|
||||||
|
// XXX need to support pattern pages...
|
||||||
|
set data(value){
|
||||||
|
this.store.update(this.path, value) },
|
||||||
|
// shorthands...
|
||||||
|
// XXX need to support pattern pages...
|
||||||
|
get text(){
|
||||||
|
return this.data.text },
|
||||||
|
// XXX need to support pattern pages...
|
||||||
|
set text(value){
|
||||||
|
this.store.update(this.path, {text: value}) },
|
||||||
|
|
||||||
// relative proxies to store...
|
// relative proxies to store...
|
||||||
exists: relProxy('exists'),
|
exists: relProxy('exists'),
|
||||||
match: relProxy('match'),
|
match: relProxy('match'),
|
||||||
// XXX should this return page objects???
|
|
||||||
get: relProxy('get'),
|
|
||||||
update: function(path='.', data, mode){
|
|
||||||
if(arguments.length == 1){
|
|
||||||
data = path
|
|
||||||
path = '.' }
|
|
||||||
return this.store.update(module.path.relative(this.path, path), data, mode) },
|
|
||||||
delete: relProxy('delete'),
|
delete: relProxy('delete'),
|
||||||
|
|
||||||
// XXX
|
get: function(path, referrer){
|
||||||
clear: function(){
|
return this.constructor(
|
||||||
},
|
this.store,
|
||||||
}
|
module.path.relative(
|
||||||
|
this.path,
|
||||||
|
path
|
||||||
|
?? this.path),
|
||||||
|
referrer
|
||||||
|
?? this.path) },
|
||||||
|
|
||||||
|
// XXX should this be an iterator???
|
||||||
|
each: function(path){
|
||||||
|
var that = this
|
||||||
|
var paths = this.match(path)
|
||||||
|
paths = paths instanceof Array ?
|
||||||
|
paths
|
||||||
|
: [paths]
|
||||||
|
return paths
|
||||||
|
.map(function(path){
|
||||||
|
return that.get(path) }) },
|
||||||
|
|
||||||
|
map: function(func){
|
||||||
|
return this.each().map(func) },
|
||||||
|
filter: function(func){
|
||||||
|
return this.each().filter(func) },
|
||||||
|
reduce: function(func, dfl){
|
||||||
|
return this.each().reduce(func, dfl) },
|
||||||
|
|
||||||
|
__init__: function(store, path, referrer){
|
||||||
|
this.store = store
|
||||||
|
this.path = path
|
||||||
|
this.referrer = referrer },
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
@ -524,9 +567,7 @@ function*(str){
|
|||||||
// XXX closure: macros
|
// XXX closure: macros
|
||||||
var expand =
|
var expand =
|
||||||
module.expand =
|
module.expand =
|
||||||
function*(ast, state={}){
|
function*(page, ast, state={}){
|
||||||
// XXX PAGE...
|
|
||||||
var page
|
|
||||||
while(true){
|
while(true){
|
||||||
var {value, done} = ast.next()
|
var {value, done} = ast.next()
|
||||||
if(done){
|
if(done){
|
||||||
@ -542,7 +583,7 @@ function*(ast, state={}){
|
|||||||
// XXX need to hav eaccess to expand(..) in the macro to be
|
// XXX need to hav eaccess to expand(..) in the macro to be
|
||||||
// able to uniformly parse the body...
|
// able to uniformly parse the body...
|
||||||
macros[name].call(page, args, body, state)
|
macros[name].call(page, args, body, state)
|
||||||
?? ''
|
?? ''
|
||||||
// XXX test if iterable...
|
// XXX test if iterable...
|
||||||
if(res instanceof Array){
|
if(res instanceof Array){
|
||||||
// XXX recursively expand this...
|
// XXX recursively expand this...
|
||||||
@ -551,11 +592,13 @@ function*(ast, state={}){
|
|||||||
yield res } } }
|
yield res } } }
|
||||||
|
|
||||||
|
|
||||||
// XXX
|
var Page =
|
||||||
var expandPage =
|
module.Page =
|
||||||
module.expandPage =
|
object.Constructor('Page', BasePage, {
|
||||||
function(page){
|
expand: function(state={}){
|
||||||
}
|
return expand(this, parse(this.text), state)
|
||||||
|
.join('') },
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user