diff --git a/index.html b/index.html
index 94abd52..ea38c87 100755
--- a/index.html
+++ b/index.html
@@ -16,6 +16,75 @@ var clear = () => {
delete localStorage['wiki-location']
}
+
+var macro = {
+ __macro__pattern__: null,
+
+ context: null,
+
+ filter: {
+ },
+ macro: {
+ filter: function(args, text, filters){
+ var filter = args[0] || args.name
+
+ filters.push(filter)
+
+ return ''
+ },
+ include: function(args){
+ var path = args[0] || args.src
+
+ var text = this.context.get(path).text
+
+ // XXX get new context???
+ return this.parse(text)
+ },
+ slot: function(args){
+ // XXX processing stages:
+ // - if we slot for first time return it as-is
+ // - if slot text available in slots us it to fill
+ // - slot seen again, save text to slots but return ''
+ },
+ },
+
+ parseArgs: function(args){
+ // XXX
+ },
+ parse: function(text){
+ var that = this
+ var filters = []
+ var slots = {}
+
+ // macro stage 1...
+ text = text.replace(this.__macro__pattern__, function(match, macro, args, text){
+ args = that.parseArgs(args)
+
+ return macro in that.macro ?
+ that.macro[macro].call(that, args, text, filters)
+ : match
+ })
+
+ // macro stage 2...
+ text = text.replace(this.__macro__pattern__, function(match, macro, args, text){
+ args = that.parseArgs(args)
+
+ return macro in that.macro ?
+ that.macro[macro].call(that, args, text, filters)
+ : match
+ })
+
+ // filter stage....
+ filters.forEach(function(k){
+ text = that.filter[k].call(that, text)
+ })
+
+ return text
+ },
+}
+
+
+
var reload = () => {
$('.dir').text('/' + Wiki.dir)
@@ -25,6 +94,7 @@ var reload = () => {
var text = Wiki.text
var editing = $('.text').prop('contenteditable') != 'true'
var filters = []
+ var slots = {}
// expand macros...
if(editing){
@@ -85,6 +155,18 @@ var reload = () => {
return w.text
}
+ // XXX need content...
+ // Procedure:
+ // - if new slot
+ // - add to list
+ // - fill
+ // - if slot exists
+ // - fill original
+ if(macro == 'slot' && args.name != null){
+ slots[args.name] = ''
+ return t
+ }
+
if(macro == 'attr'
&& args.name != null
&& ['title', 'path', 'location', 'dir'].indexOf(args.name) >= 0){
diff --git a/wiki.js b/wiki.js
index b804d0a..3171cc0 100755
--- a/wiki.js
+++ b/wiki.js
@@ -11,24 +11,24 @@
// XXX not sure about these...
var BaseData = {
- 'Templates/title': function(){
+ 'System/title': function(){
var o = Object.create(this)
o.location = o.dir
return o.title
},
- 'Templates/path': function(){
+ 'System/path': function(){
return this.dir },
- 'Templates/dir': function(){
+ 'System/dir': function(){
return normalizePath(path2lst(this.dir).slice(0, -1)) },
- 'Templates/location': function(){
+ 'System/location': function(){
return this.dir },
- 'Templates/resolved': function(){
+ 'System/resolved': function(){
var o = Object.create(this)
o.location = o.dir
return o.acquire(o.dir, o.title)
},
- 'Templates/list': function(){
+ 'System/list': function(){
var p = this.dir
return Object.keys(this.__wiki_data)
@@ -43,7 +43,7 @@ var BaseData = {
.map(e => '['+ e +']')
.join('
')
},
- 'Templates/tree': function(){
+ 'System/tree': function(){
var p = this.dir
return Object.keys(this.__wiki_data)
@@ -58,7 +58,7 @@ var BaseData = {
.map(e => '['+ e +']')
.join('
')
},
- 'Templates/links': function(){
+ 'System/links': function(){
var that = this
var p = this.dir
@@ -80,7 +80,7 @@ var BaseData = {
},
// XXX this needs a redirect...
- 'Templates/delete': function(){
+ 'System/delete': function(){
var p = this.dir
delete this.__wiki_data[p]
},
@@ -134,7 +134,11 @@ var Wiki = {
__home_page__: 'WikiHome',
__default_page__: 'EmptyPage',
- __templates__: 'Templates',
+ __acquesition_order__: [
+ 'Templates',
+ ],
+ // XXX should this be read only???
+ __system__: 'System',
//__redirect_template__: 'RedirectTemplate',
__wiki_link__: RegExp('('+[
@@ -312,8 +316,10 @@ var Wiki = {
//
// Test acquesition order:
// - explicit path
- // - .title in path
- // - .title in templates
+ // - for each level in path
+ // - .title explicitly in path
+ // - .title in templates
+ // - .title in system
// - aquire empty page (same order as above)
//
get text(){
@@ -356,12 +362,23 @@ var Wiki = {
},
+ // navigation...
+ get parent(){
+ return this.get(this.dir)
+ },
+ get: function(path){
+ var o = Object.create(this)
+ o.location = path
+ return o
+ },
+
+
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 acquire_from = this.__acquesition_order__
var data = this.__wiki_data
var that = this
@@ -379,18 +396,28 @@ var Wiki = {
return _res(p)
}
- // get title from templates in path...
- var p = path.concat([templates, title])
- if(this.exists(p)){
- return _res(p)
+ // get title from special paths in path...
+ for(var i=0; i < acquire_from.length; i++){
+ var p = path.concat([acquire_from[i], title])
+ if(this.exists(p)){
+ return _res(p)
+ }
}
if(path.length == 0){
- return
+ break
}
path.pop()
}
+
+ // system path...
+ if(this.__system__){
+ var p = [this.__system__, title]
+ if(this.exists(p)){
+ return _res(p)
+ }
+ }
},
acquire: function(path, title){
path = path && normalizePath(path) || this.path