mirror of
https://github.com/flynx/pWiki.git
synced 2026-07-13 20:10:57 +00:00
testing + minor bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
85cf87813b
commit
5cabfd0754
@ -244,12 +244,7 @@ module.BaseParser = {
|
|||||||
body
|
body
|
||||||
?? args.body
|
?? args.body
|
||||||
?? args.text }
|
?? args.text }
|
||||||
return macro.call(page,
|
return macro.call(page, this, args, body, state, ...rest) },
|
||||||
this,
|
|
||||||
args,
|
|
||||||
body,
|
|
||||||
state,
|
|
||||||
...rest) },
|
|
||||||
|
|
||||||
|
|
||||||
// Strip comments...
|
// Strip comments...
|
||||||
@ -1343,6 +1338,7 @@ module.parser = {
|
|||||||
// overrides in nesteed slots...
|
// overrides in nesteed slots...
|
||||||
lazy(
|
lazy(
|
||||||
function(parser, args, body, state){
|
function(parser, args, body, state){
|
||||||
|
var that = this
|
||||||
var name = args.name
|
var name = args.name
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
@ -1369,7 +1365,7 @@ module.parser = {
|
|||||||
slot.splice(0, slot.length, placeholder)
|
slot.splice(0, slot.length, placeholder)
|
||||||
// expand body...
|
// expand body...
|
||||||
body = body ?
|
body = body ?
|
||||||
parser.expand(this, body ?? [], state)
|
parser.expand(that, body ?? [], state)
|
||||||
: body
|
: body
|
||||||
// if slot not overriden, write our value...
|
// if slot not overriden, write our value...
|
||||||
if(slot[0] === placeholder){
|
if(slot[0] === placeholder){
|
||||||
@ -1425,13 +1421,16 @@ module.parser = {
|
|||||||
// not 100% correct manner focusing on path depth and ignoring
|
// not 100% correct manner focusing on path depth and ignoring
|
||||||
// the context, this potentially can lead to false positives.
|
// the context, this potentially can lead to false positives.
|
||||||
//
|
//
|
||||||
|
// XXX add path recursion test to data -- fail if two paths resolve
|
||||||
|
// to the same context...
|
||||||
// XXX need a way to make encode option transparent...
|
// XXX need a way to make encode option transparent...
|
||||||
// XXX need a way to wrap the included page...
|
// XXX need a way to wrap the included page...
|
||||||
// - template page...
|
// - template page...
|
||||||
// - prefix/sufix...
|
// - prefix/sufix...
|
||||||
// XXX store a page cache in state...
|
// XXX store a page cache in state...
|
||||||
|
// XXX do we want to load a specific slot/block???
|
||||||
// XXX UPDATE...
|
// XXX UPDATE...
|
||||||
include2: Macro(
|
include: Macro(
|
||||||
['src', 'recursive', 'join',
|
['src', 'recursive', 'join',
|
||||||
['s', 'strict', 'isolated']],
|
['s', 'strict', 'isolated']],
|
||||||
// XXX thinking that reimplementing this is a bit less boring than
|
// XXX thinking that reimplementing this is a bit less boring than
|
||||||
@ -1443,6 +1442,7 @@ module.parser = {
|
|||||||
// .get(path)
|
// .get(path)
|
||||||
// is this a promise/value, iterable promise a generator
|
// is this a promise/value, iterable promise a generator
|
||||||
// an async generator, ... or a combination/stack of the above???
|
// an async generator, ... or a combination/stack of the above???
|
||||||
|
lazy(
|
||||||
function(parser, args, body, state, key='included', handler){
|
function(parser, args, body, state, key='included', handler){
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
@ -1453,6 +1453,7 @@ module.parser = {
|
|||||||
?? state.recursive
|
?? state.recursive
|
||||||
|
|
||||||
var base = this.basepath
|
var base = this.basepath
|
||||||
|
// XXX we do this before or after we parse???
|
||||||
var src = this.resolvePathVars(args.src)
|
var src = this.resolvePathVars(args.src)
|
||||||
|
|
||||||
return Promise.awaitOrRun(
|
return Promise.awaitOrRun(
|
||||||
@ -1494,24 +1495,24 @@ module.parser = {
|
|||||||
var pageHandler =
|
var pageHandler =
|
||||||
function(text, i, l){
|
function(text, i, l){
|
||||||
return [
|
return [
|
||||||
handler.call(that,
|
handler.call(that,
|
||||||
parser,
|
parser,
|
||||||
text,
|
text,
|
||||||
// isolated up -- will see all
|
// isolated up -- will see all
|
||||||
// the state but can have no
|
// the state but can have no
|
||||||
// side-effects...
|
// side-effects...
|
||||||
args.isolated == 'partial' ?
|
args.isolated == 'partial' ?
|
||||||
serialize.partialDeepCopy(state)
|
serialize.partialDeepCopy(state)
|
||||||
// fully isolated...
|
// fully isolated...
|
||||||
: args.isolated ?
|
: args.isolated ?
|
||||||
{}
|
{}
|
||||||
: state),
|
: state),
|
||||||
// join...
|
// join...
|
||||||
(args.join
|
(args.join
|
||||||
&& i < l.length - 1) ?
|
&& i < l.length - 1) ?
|
||||||
parser._parse(that, args.join, state)
|
parser._parse(that, args.join, state)
|
||||||
: []
|
: []
|
||||||
].flat() }
|
].flat() }
|
||||||
var resultHandler =
|
var resultHandler =
|
||||||
function(pages){
|
function(pages){
|
||||||
// XXX not sure if this can happen or why...
|
// XXX not sure if this can happen or why...
|
||||||
@ -1541,9 +1542,9 @@ module.parser = {
|
|||||||
.map( pageHandler ))
|
.map( pageHandler ))
|
||||||
.flat()
|
.flat()
|
||||||
.sync(),
|
.sync(),
|
||||||
resultHandler ) }) }) }),
|
resultHandler ) }) }) })),
|
||||||
|
|
||||||
include: Macro(
|
_include: Macro(
|
||||||
['src', 'recursive', 'join',
|
['src', 'recursive', 'join',
|
||||||
['s', 'strict', 'isolated']],
|
['s', 'strict', 'isolated']],
|
||||||
async function*(parser, args, body, state, key='included', handler){
|
async function*(parser, args, body, state, key='included', handler){
|
||||||
@ -2070,32 +2071,5 @@ module.parser = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// XXX for testing...
|
|
||||||
|
|
||||||
var P =
|
|
||||||
module.P = {
|
|
||||||
//* XXX
|
|
||||||
_content: [
|
|
||||||
'first page text',
|
|
||||||
'second page text',
|
|
||||||
],
|
|
||||||
/*/
|
|
||||||
_content: 'page text',
|
|
||||||
//*/
|
|
||||||
|
|
||||||
path: '/path/to/page',
|
|
||||||
basepath: '/path/to/',
|
|
||||||
|
|
||||||
get raw(){
|
|
||||||
return this._content ?? '' },
|
|
||||||
get: function(){
|
|
||||||
return this },
|
|
||||||
|
|
||||||
resolvePathVars: function(path){
|
|
||||||
return path },
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 nowrap : */ return module })
|
* vim:set ts=4 sw=4 nowrap : */ return module })
|
||||||
|
|||||||
@ -1,12 +1,52 @@
|
|||||||
#!/usr/bin/node
|
#!/usr/bin/node
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
var path = require('path')
|
||||||
|
|
||||||
var test = require('ig-test')
|
var test = require('ig-test')
|
||||||
var serialize = require('ig-serialize')
|
var serialize = require('ig-serialize')
|
||||||
|
|
||||||
var parser = require('../parser').parser
|
var parser = require('../parser').parser
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
var PAGES =
|
||||||
|
module.exports.PAGES = {
|
||||||
|
'/blank': '',
|
||||||
|
'/page': 'Page',
|
||||||
|
'/async/page': Promise.resolve('Page'),
|
||||||
|
'/includePage': '@include(/page)',
|
||||||
|
}
|
||||||
|
|
||||||
|
var P =
|
||||||
|
module.exports.P = {
|
||||||
|
__pages__: PAGES,
|
||||||
|
__parser__: parser,
|
||||||
|
|
||||||
|
path: '/',
|
||||||
|
|
||||||
|
get basepath(){
|
||||||
|
return path.dirname(this.path ?? '') },
|
||||||
|
|
||||||
|
get raw(){
|
||||||
|
return this.__pages__[this.path] ?? '' },
|
||||||
|
get text(){
|
||||||
|
return this.__parser__.parse(this, this.raw, {}) },
|
||||||
|
|
||||||
|
get: function(p){
|
||||||
|
return {
|
||||||
|
__proto__: P,
|
||||||
|
path: path.resolve(this.path, p),
|
||||||
|
} },
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
resolvePathVars: function(path){
|
||||||
|
return path },
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
test.Setups({
|
test.Setups({
|
||||||
@ -140,6 +180,28 @@ test.Setups({
|
|||||||
// XXX arg...
|
// XXX arg...
|
||||||
// XXX
|
// XXX
|
||||||
|
|
||||||
|
// include...
|
||||||
|
// XXX these do not play well with modifiers...
|
||||||
|
include: function(assert, path='/blank', expected){
|
||||||
|
return {
|
||||||
|
page: P,
|
||||||
|
code: [
|
||||||
|
`@include(${path})`,
|
||||||
|
// XXX for some reason this does not parse int a macro....
|
||||||
|
//'<include /blank />',
|
||||||
|
`<include "${path}" />`,
|
||||||
|
expected
|
||||||
|
?? P.get(path).raw,
|
||||||
|
],
|
||||||
|
}},
|
||||||
|
include_page: function(assert){
|
||||||
|
return this.include(assert, '/page') },
|
||||||
|
include_include_page: function(assert){
|
||||||
|
return this.include(assert, '/includePage', 'Page') },
|
||||||
|
/* XXX
|
||||||
|
include_async: function(assert){
|
||||||
|
return this.include(assert, '/async/page') },
|
||||||
|
//*/
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user