mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
working on marco parsing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
0310427010
commit
b3d5c857c8
67
index.html
67
index.html
@ -18,73 +18,6 @@ var clear = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 = () => {
|
var reload = () => {
|
||||||
$('.path').text('/' + Wiki.path)
|
$('.path').text('/' + Wiki.path)
|
||||||
|
|||||||
106
wiki.js
106
wiki.js
@ -349,15 +349,6 @@ var Wiki = {
|
|||||||
|
|
||||||
|
|
||||||
// page content...
|
// page content...
|
||||||
//
|
|
||||||
// Test acquesition order:
|
|
||||||
// - explicit path
|
|
||||||
// - for each level in path
|
|
||||||
// - .title explicitly in path
|
|
||||||
// - .title in templates
|
|
||||||
// - .title in system
|
|
||||||
// - aquire empty page (same order as above)
|
|
||||||
//
|
|
||||||
get raw(){
|
get raw(){
|
||||||
var data = this.data
|
var data = this.data
|
||||||
return data instanceof Function ? data.call(this, this)
|
return data instanceof Function ? data.call(this, this)
|
||||||
@ -381,10 +372,8 @@ var Wiki = {
|
|||||||
this.__wiki_data[l].links = this.links
|
this.__wiki_data[l].links = this.links
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX
|
// XXX take .raw, parse macros and apply filters...
|
||||||
get text(){
|
get text(){ return this.raw },
|
||||||
return this.raw
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: this is set by setting .text
|
// NOTE: this is set by setting .text
|
||||||
@ -505,5 +494,96 @@ var Wiki = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
var macro = {
|
||||||
|
__macro__pattern__: null,
|
||||||
|
__filters__: [
|
||||||
|
],
|
||||||
|
|
||||||
|
context: null,
|
||||||
|
|
||||||
|
filter: {
|
||||||
|
},
|
||||||
|
macro: {
|
||||||
|
// select filter to post-process text...
|
||||||
|
filter_args: ['name'],
|
||||||
|
filter: function(args, text, _, filters){
|
||||||
|
var filter = args[0] || args.name
|
||||||
|
|
||||||
|
filters.push(filter)
|
||||||
|
|
||||||
|
return ''
|
||||||
|
},
|
||||||
|
|
||||||
|
// include page/slot...
|
||||||
|
include_args: ['src', 'slot'],
|
||||||
|
include: function(args){
|
||||||
|
var path = args.src
|
||||||
|
|
||||||
|
var text = this.context.get(path).text
|
||||||
|
|
||||||
|
return this.parse(text)
|
||||||
|
},
|
||||||
|
|
||||||
|
// fill/define slot (stage 1)...
|
||||||
|
// XXX
|
||||||
|
slot_args: ['name'],
|
||||||
|
slot: function(args, text, slots){
|
||||||
|
var name = args.name
|
||||||
|
|
||||||
|
if(slots[name] == null){
|
||||||
|
slots[name] = text
|
||||||
|
// XXX return a slot macro parsable by stage 2...
|
||||||
|
return text
|
||||||
|
|
||||||
|
} else if(name in slots){
|
||||||
|
slots[name] = text
|
||||||
|
// XXX on stage 2 need to return text
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
parseArgs: function(macro, args){
|
||||||
|
// XXX parse args and populate the dict via .*_args attr...
|
||||||
|
// 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(macro, args)
|
||||||
|
|
||||||
|
return macro in that.macro ?
|
||||||
|
that.macro[macro].call(that, args, text, slots, filters)
|
||||||
|
: match
|
||||||
|
})
|
||||||
|
|
||||||
|
// macro stage 2...
|
||||||
|
text = text.replace(this.__macro__pattern__, function(match, macro, args, text){
|
||||||
|
args = that.parseArgs(macro, args)
|
||||||
|
|
||||||
|
return macro in that.macro ?
|
||||||
|
that.macro[macro].call(that, args, text, slots, filters)
|
||||||
|
: match
|
||||||
|
})
|
||||||
|
|
||||||
|
// filter stage....
|
||||||
|
filters.forEach(function(k){
|
||||||
|
text = that.filter[k].call(that, text)
|
||||||
|
})
|
||||||
|
|
||||||
|
return text
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user