diff --git a/macro.js b/macro.js
index 9653ccf..b1d374e 100755
--- a/macro.js
+++ b/macro.js
@@ -113,7 +113,7 @@ module = {
var path = $(elem).attr('src')
return context.get(path)
- .map(function(page){ return page.raw })
+ .map(function(page){ return page.raw() })
.join('\n')
}),
@@ -127,8 +127,8 @@ module = {
.map(function(page){
return elem
.clone()
- .attr('src', page.path)
- .text(page.raw)[0]
+ .attr('src', page.path())
+ .text(page.raw())[0]
}))
}),
diff --git a/pwiki.js b/pwiki.js
index 43721ba..9b11c3a 100755
--- a/pwiki.js
+++ b/pwiki.js
@@ -99,6 +99,82 @@ pWikiFeatures.__actions__ =
+/*********************************************************************/
+
+var BaseData = {
+ // Macro acces to standard page attributes (paths)...
+ 'System/title': function(){ return { text: this.get('..').title() } },
+ 'System/path': function(){ return { text: this.base() } },
+ 'System/dir': function(){ return { text: this.get('..').base() } },
+ 'System/location': function(){ return { text: this.base() } },
+ 'System/resolved': function(){ return { text: this.get('..').acquire() } },
+
+ // page data...
+ //
+ // NOTE: special case: ./raw is treated a differently when getting .text
+ // i.e:
+ // .get('./raw').text
+ // is the same as:
+ // .get('.').raw
+ 'System/raw': function(){ return { text: this.get('..').raw() } },
+ 'System/text': function(){ return { text: this.get('..').text() } },
+
+ // XXX update these to the new format -- must return an object...
+ /*
+ // XXX move this to Wiki.children + rename...
+ 'System/list': function(){
+ var p = this.dir
+
+ return Object.keys(this.__wiki_data)
+ .map(function(k){
+ if(k.indexOf(p) == 0){
+ return path2lst(k.slice(p.length)).shift()
+ }
+ return null
+ })
+ .filter(function(e){ return e != null })
+ .sort()
+ .map(function(e){ return '['+ e +']' })
+ .join('
')
+ },
+ // list links to this page...
+ 'System/links': function(){
+ var that = this
+ var p = this.dir
+
+ var res = []
+
+ var wiki = this.__wiki_data
+ Object.keys(wiki).forEach(function(k){
+ (wiki[k].links || []).forEach(function(l){
+ (l == p || that.get(path2lst(l).slice(0, -1)).acquire('./'+path2lst(l).pop()) == p)
+ && res.push([l, k])
+ })
+ })
+
+ return res
+ //.map(function(e){ return '['+ e[0] +'] from page: ['+ e[1] +']' })
+ .map(function(e){ return '['+ e[1] +'] -> ['+ e[0] +']' })
+ .sort()
+ .join('
')
+ },
+ //*/
+
+ // Page modifiers/actions...
+ // XXX these needs redirecting...
+ //'System/sort': function(){ return this.get('..').sort() },
+ //'System/reverse': function(){ return this.get('..').reverse() },
+ /*
+ 'System/delete': function(){
+ var p = this.dir
+ delete this.__wiki_data[p]
+ return this.get('..')
+ },
+ //*/
+}
+
+
+
/*********************************************************************/
// XXX should this be art of the main API or a separate entity???
@@ -146,9 +222,15 @@ module.pWikiData = {
data: function(path, value){
// get the data...
if(value == null){
- return this.__data ?
- JSON.parse(JSON.stringify(this.__data[path] || {}))
- : null
+ if(this.__data == null){
+ return null
+ }
+
+ var data = this.__data[path]
+
+ return data == null ? null
+ : data instanceof Function ? data
+ : JSON.parse(JSON.stringify(data))
// set the data...
} else {
@@ -193,6 +275,7 @@ module.pWikiData = {
+
/*********************************************************************/
// Base pWiki page API...
@@ -223,38 +306,41 @@ module.pWikiBase = actions.Actions({
wiki: null,
- // XXX should this be loca/dump???
+ // XXX should this be local/dump???
json: ['', function(){ }],
get length(){
+ // special case -- non-pattern path that does not exist...
+ if(this.location().path.indexOf('*') < 0
+ && !this.exists()){
+ return 1
+ }
+
return this.wiki.match(this.location().path)
+ // skip special paths containing '*'...
.filter(function(p){ return p.indexOf('*') < 0 })
.length },
- // XXX BUG: 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',
function(path){
path = path || this.path()
// path variables...
// XXX make this more modular...
path = path
- .replace(/\$NOW|\$\{NOW\}/g, Date.now())
- .replace(/\$INDEX|\$\{INDEX\}/g, this.at())
- .replace(/\$TITLE|\$\{TITLE\}/g, this.title())
// NOTE: these are equivalent to '..' and '.' but not
// identical -- the variables are useful for things
// like moving a page to:
// "Trash/$PATH"
// ...to move the above page out of trash move it to:
// ">>/$PATH"
- .replace(/\$BASE|\$\{BASE\}/g, this.base())
.replace(/\$PATH|\$\{PATH\}/g, this.path())
+ .replace(/\$BASE|\$\{BASE\}/g, this.base())
+
+ .replace(/\$TITLE|\$\{TITLE\}/g, this.title())
+ .replace(/\$INDEX|\$\{INDEX\}/g, this.at())
+
+ .replace(/\$NOW|\$\{NOW\}/g, Date.now())
path = normalizePath(path)
@@ -290,7 +376,6 @@ module.pWikiBase = actions.Actions({
for(var i=0; i < lst.length; i++){
var p = normalizePath(path.concat([lst[i], title]))
if(that.exists(p)){
- p = normalizePath(p)
return that.wiki.data(p) && p
}
}
@@ -427,8 +512,9 @@ module.pWikiBase = actions.Actions({
// 'order': [