mirror of
https://github.com/flynx/pWiki.git
synced 2025-11-04 13:00:10 +00:00
refactoring + filters broken....
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
23b44ecd52
commit
ca62396ef0
70
pwiki2.js
70
pwiki2.js
@ -750,21 +750,20 @@ module.parser = {
|
|||||||
: ast
|
: ast
|
||||||
|
|
||||||
return [...ast]
|
return [...ast]
|
||||||
// post macros...
|
// post handlers...
|
||||||
.map(function(section){
|
.map(function(section){
|
||||||
return (typeof(section) != 'string'
|
return section instanceof Function ?
|
||||||
&& section.type in page.macros_finalize) ?
|
section.call(page, state)
|
||||||
page.macros_finalize[section.type].call(page, section, state)
|
|
||||||
: section })
|
: section })
|
||||||
.flat()
|
.flat()
|
||||||
// filters...
|
// filters...
|
||||||
.map(function(section){
|
.map(function(section){
|
||||||
// expand section...
|
return (
|
||||||
if(typeof(section) != 'string'){
|
// expand section...
|
||||||
return section.data
|
typeof(section) != 'string' ?
|
||||||
// global filters...
|
section.data
|
||||||
} else {
|
// global filters...
|
||||||
return state.filters ?
|
: state.filters ?
|
||||||
that.normalizeFilters(state.filters)
|
that.normalizeFilters(state.filters)
|
||||||
.reduce(function(res, filter){
|
.reduce(function(res, filter){
|
||||||
if(page.filters[filter] == null){
|
if(page.filters[filter] == null){
|
||||||
@ -772,7 +771,8 @@ module.parser = {
|
|||||||
'.parse(..): unsupported filter: '+ filter) }
|
'.parse(..): unsupported filter: '+ filter) }
|
||||||
return page.filters[filter].call(page, res)
|
return page.filters[filter].call(page, res)
|
||||||
?? res }, section)
|
?? res }, section)
|
||||||
: section } })
|
// no global filters...
|
||||||
|
: section ) })
|
||||||
.flat()
|
.flat()
|
||||||
.join('') },
|
.join('') },
|
||||||
}
|
}
|
||||||
@ -841,6 +841,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
// | -<filter> <filter-spec>
|
// | -<filter> <filter-spec>
|
||||||
//
|
//
|
||||||
// XXX support .NO_FILTERS ...
|
// XXX support .NO_FILTERS ...
|
||||||
|
// XXX not working on the test page...
|
||||||
filter: function*(args, body, state){
|
filter: function*(args, body, state){
|
||||||
var filters = state.filters =
|
var filters = state.filters =
|
||||||
state.filters
|
state.filters
|
||||||
@ -869,15 +870,22 @@ object.Constructor('Page', BasePage, {
|
|||||||
state.filters.includes(this.ISOLATED_FILTERS)
|
state.filters.includes(this.ISOLATED_FILTERS)
|
||||||
&& state.filters[0] instanceof Array
|
&& state.filters[0] instanceof Array
|
||||||
&& state.filters.shift()
|
&& state.filters.shift()
|
||||||
|
|
||||||
// serialize the block for later processing...
|
// serialize the block for later processing...
|
||||||
var res = {
|
var data = [...this.__parser__.expand(this, body, state)]
|
||||||
type: 'filter',
|
filters = state.filters
|
||||||
filters: state.filters,
|
|
||||||
data: [...this.__parser__.expand(this, body, state)],
|
|
||||||
}
|
|
||||||
// restore global filters...
|
// restore global filters...
|
||||||
state.filters = parent_filters
|
state.filters = parent_filters
|
||||||
yield res }
|
|
||||||
|
// post handler...
|
||||||
|
yield function(state){
|
||||||
|
state.filters = this.__parser__.normalizeFilters(filters)
|
||||||
|
var res = [...this.__parser__.parse(this, data, state)]
|
||||||
|
.flat()
|
||||||
|
.join('')
|
||||||
|
state.filters = filters
|
||||||
|
return { data: res } } }
|
||||||
return },
|
return },
|
||||||
//
|
//
|
||||||
// @include(<path>)
|
// @include(<path>)
|
||||||
@ -959,36 +967,20 @@ object.Constructor('Page', BasePage, {
|
|||||||
?? {}
|
?? {}
|
||||||
// NOTE: we only place text in slots that are defined first,
|
// NOTE: we only place text in slots that are defined first,
|
||||||
// all other instances will be omitted...
|
// all other instances will be omitted...
|
||||||
var res =
|
var blank = name in slots
|
||||||
name in slots ?
|
|
||||||
''
|
|
||||||
: {
|
|
||||||
type: 'slot',
|
|
||||||
name,
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX should this use .parse(..) or .expand(..) ???
|
// XXX should this use .parse(..) or .expand(..) ???
|
||||||
slots[name] = [...this.__parser__.expand(this, text, state)]
|
slots[name] = [...this.__parser__.expand(this, text, state)]
|
||||||
|
|
||||||
return res },
|
return blank ?
|
||||||
|
''
|
||||||
|
: function(state){
|
||||||
|
return state.slots[name] } },
|
||||||
macro: function(){},
|
macro: function(){},
|
||||||
|
|
||||||
// nesting rules...
|
// nesting rules...
|
||||||
'else': ['macro'],
|
'else': ['macro'],
|
||||||
},
|
},
|
||||||
// second stage macros...
|
|
||||||
macros_finalize: {
|
|
||||||
filter: function(section, state){
|
|
||||||
var filters = state.filters
|
|
||||||
state.filters = this.__parser__.normalizeFilters(section.filters)
|
|
||||||
var res = [...this.__parser__.parse(this, section.data, state)]
|
|
||||||
.flat()
|
|
||||||
.join('')
|
|
||||||
state.filters = filters
|
|
||||||
return { data: res } },
|
|
||||||
slot: function(section, state){
|
|
||||||
return state.slots[section.name] },
|
|
||||||
},
|
|
||||||
|
|
||||||
// page parser...
|
// page parser...
|
||||||
//
|
//
|
||||||
@ -1077,6 +1069,8 @@ pwiki
|
|||||||
+'\n'
|
+'\n'
|
||||||
+'<filter -test>...unfiltered test text</filter>\n'
|
+'<filter -test>...unfiltered test text</filter>\n'
|
||||||
+'\n'
|
+'\n'
|
||||||
|
//+'<filter test>locally filtered test text</filter>\n'
|
||||||
|
+'\n'
|
||||||
+'@slot(name=a text="non-filled slot")\n'
|
+'@slot(name=a text="non-filled slot")\n'
|
||||||
+'\n'
|
+'\n'
|
||||||
+'@slot(name=b text="non-filled slot")\n'
|
+'@slot(name=b text="non-filled slot")\n'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user