mirror of
https://github.com/flynx/pWiki.git
synced 2026-10-03 12:51:40 +00:00
Compare commits
No commits in common. "e4dc2d04711c0a9b92ae49e372523ca83275ad28" and "49ee54539f5968e91e2efcd859060d73a00aadd1" have entirely different histories.
e4dc2d0471
...
49ee54539f
7
v3/package-lock.json
generated
7
v3/package-lock.json
generated
@ -13,7 +13,6 @@
|
||||
"ig-actions": "*",
|
||||
"ig-features": "*",
|
||||
"ig-object": "*",
|
||||
"ig-serialize": "*",
|
||||
"ig-types": "*",
|
||||
"requirejs": "*",
|
||||
"uuid": "*"
|
||||
@ -142,12 +141,6 @@
|
||||
"ig-stoppable": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ig-serialize": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/ig-serialize/-/ig-serialize-1.3.4.tgz",
|
||||
"integrity": "sha512-aIrZ7ljyXVRUsyvcWfF2JSz/4hWtDrJcTpHJ2y4QD48YXF/0eIwwzDbB6dCmoK2EO5fHfxa82WrVBncb+kDqvg==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/ig-stoppable": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/ig-stoppable/-/ig-stoppable-2.0.4.tgz",
|
||||
|
||||
@ -11,8 +11,7 @@
|
||||
"ig-actions": "*",
|
||||
"ig-features": "*",
|
||||
"ig-object": "*",
|
||||
"ig-types": "*",
|
||||
"ig-serialize": "*"
|
||||
"ig-types": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ig-test": "*"
|
||||
|
||||
@ -1280,13 +1280,14 @@ module.parser = {
|
||||
// all other slots with <name> will replace its content, unless
|
||||
// explicit shown/hidden arguments are given.
|
||||
// NOTE: hidden has precedence over shown if both are given.
|
||||
// XXX revise...
|
||||
// NOTE: slots are handled in order of occurrence of opening tags
|
||||
// in text and not by hierarchy, i.e. the later slot overrides
|
||||
// the former and the most nested overrides the parent.
|
||||
// This also works for cases where slots override slots they
|
||||
// are contained in, this will not lead to recursion.
|
||||
//
|
||||
// XXX revise the use of hidden/shown use mechanic and if it's
|
||||
// needed...
|
||||
// XXX do we need to guard from recursion???
|
||||
// ...do not think it's possible -- everything is resolved
|
||||
// once and just inseerted as-is (revise)
|
||||
slot: Macro(
|
||||
['name', 'text', ['shown', 'hidden']],
|
||||
function(parser, args, body, state){
|
||||
@ -1351,79 +1352,13 @@ module.parser = {
|
||||
// At the moment nested recursion is checked in a fast but
|
||||
// not 100% correct manner focusing on path depth and ignoring
|
||||
// the context, this potentially can lead to false positives.
|
||||
//
|
||||
// XXX need a way to make encode option transparent...
|
||||
// XXX need a way to wrap the included page...
|
||||
// - template page...
|
||||
// - prefix/sufix...
|
||||
// XXX store a page cache in state...
|
||||
// XXX UPDATE...
|
||||
include2: Macro(
|
||||
['src', 'recursive', 'join',
|
||||
['s', 'strict', 'isolated']],
|
||||
// XXX thinking that reimplementing this is a bit less boring than
|
||||
// refactoring, and should be cleaner...
|
||||
// XXX if the src is empty return nothing...
|
||||
// XXX this needs to be reusable...
|
||||
// XXX need a wrapper protocol -- is this the level for it???
|
||||
// XXX page API used:
|
||||
// .basepath
|
||||
// .resolvePathVars(path)
|
||||
// .get(path)
|
||||
// is this a promise/value, iterable promise a generator
|
||||
// an async generator, ... or a combination/stack of the above???
|
||||
function(parser, args, body, state, key='included', handler){
|
||||
|
||||
var base = this.basepath
|
||||
// XXX
|
||||
//var src = parser.parse(this.resolvePathVars(args.src))
|
||||
var src = args.src
|
||||
|
||||
return Promise.awaitOrRun(
|
||||
parser.parse(this, src, state),
|
||||
function(src){
|
||||
var cache = state.cache ??= {}
|
||||
if(cache[src]){
|
||||
return cache[src] }
|
||||
|
||||
// XXX should this be a tree??
|
||||
// ...need to at least split direct and
|
||||
// indirect dependencies...
|
||||
var depends = ((state.depends ??= {})[base] ??= {})
|
||||
|
||||
handler ??=
|
||||
function(parser, page, state){
|
||||
// XXX get page text
|
||||
// XXX setup state
|
||||
return parser.parse(this, page, state) }
|
||||
var pageHandler =
|
||||
function(page){
|
||||
// XXX cache...
|
||||
return handler.call(this, parser, page, state) }
|
||||
|
||||
// XXX can we do:
|
||||
// return this.get(...)
|
||||
// .iter()
|
||||
// .map(...)
|
||||
// .sync()
|
||||
return Promise.awaitOrRun(
|
||||
this.get(src),
|
||||
function(pages){
|
||||
return Promise.awaitOrRun(
|
||||
// handle pages...
|
||||
Promise
|
||||
.iter(
|
||||
pages
|
||||
.map(pageHandler))
|
||||
.sync(),
|
||||
// cache the final result...
|
||||
function(pages){
|
||||
return (cache[src] = pages) }) }) }) }),
|
||||
|
||||
include: Macro(
|
||||
['src', 'recursive', 'join',
|
||||
['s', 'strict', 'isolated']],
|
||||
async function*(parser, args, body, state, key='included', handler){
|
||||
async function*(args, body, state, key='included', handler){
|
||||
var macro = 'include'
|
||||
if(typeof(args) == 'string'){
|
||||
var [macro, args, body, state, key, handler] = arguments
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
var test = require('ig-test')
|
||||
var serialize = require('ig-serialize')
|
||||
|
||||
var parser = require('../parser').parser
|
||||
|
||||
@ -11,11 +10,10 @@ var parser = require('../parser').parser
|
||||
|
||||
test.Setups({
|
||||
empty: function(assert){
|
||||
return { code: [ '', '' ] }},
|
||||
return [ '', '' ] },
|
||||
|
||||
// slot...
|
||||
slot_empty: function(assert){
|
||||
return {code: [
|
||||
return [
|
||||
'@slot(slot)',
|
||||
'@slot("slot")',
|
||||
'@slot(\'slot\')',
|
||||
@ -28,120 +26,95 @@ test.Setups({
|
||||
'<slot name=slot/>',
|
||||
'<slot name="slot"/>',
|
||||
'<slot name=\'slot\'/>',
|
||||
'' ]} },
|
||||
'' ] },
|
||||
slot_value: function(assert){
|
||||
return {code: [
|
||||
return [
|
||||
'<slot slot value/>',
|
||||
'<slot slot text=value/>',
|
||||
'@slot(slot value)',
|
||||
'@slot(slot text=value)',
|
||||
'value' ]} },
|
||||
'value' ] },
|
||||
slot_fill: function(assert){
|
||||
var ins = this.slot_value(assert).code.slice(0, -1)
|
||||
return {code: [
|
||||
var ins = this.slot_value(assert).slice(0, -1)
|
||||
return [
|
||||
...ins.map(function(e){
|
||||
return e + '@slot(slot other)' }),
|
||||
...ins.map(function(e){
|
||||
return e + '<slot slot other/>' }),
|
||||
...ins.map(function(e){
|
||||
return e + '<slot slot>other</slot>' }),
|
||||
'other' ]} },
|
||||
'other' ] },
|
||||
slot_fill_fill: function(assert){
|
||||
var ins = this.slot_fill(assert).code.slice(0, -1)
|
||||
return {code: [
|
||||
var ins = this.slot_fill(assert).slice(0, -1)
|
||||
return [
|
||||
...ins.map(function(e){
|
||||
return e + '@slot(slot third)' }),
|
||||
...ins.map(function(e){
|
||||
return e + '<slot slot third/>' }),
|
||||
...ins.map(function(e){
|
||||
return e + '<slot slot>third</slot>' }),
|
||||
'third' ]} },
|
||||
/* XXX not sure how...
|
||||
slot_recursion: function(assert){
|
||||
return {code: [
|
||||
'<slot slot> <slot slot.inner/> </slot> <slot slot.inner "@slot"/>',
|
||||
'', ]} },
|
||||
//*/
|
||||
'third' ] },
|
||||
|
||||
// XXX these are an alternative to <content/>...
|
||||
slot_nested: function(assert){
|
||||
return {code: [
|
||||
return [
|
||||
'<slot slot>[[ <slot slot.content/> ]]</slot>@slot(slot.content value)',
|
||||
'[[ value ]]' ]} },
|
||||
'[[ value ]]' ] },
|
||||
slot_nested_overwrite: function(assert){
|
||||
return {code: [
|
||||
return [
|
||||
'<slot slot>[[ <slot slot.content/> ]]</slot>@slot(slot value)',
|
||||
'value' ]} },
|
||||
'value' ] },
|
||||
|
||||
/* XXX SHOWN_HIDDEN
|
||||
// XXX these need to be revised...
|
||||
// ...do we actually need hidden/shown???
|
||||
//
|
||||
slot_shown: function(assert){
|
||||
var ins = this.slot_value(assert).code
|
||||
var ins = this.slot_value(assert)
|
||||
var expect = ins.pop()
|
||||
return {code: [
|
||||
return [
|
||||
...ins.map(function(i){
|
||||
return i +' @slot(slot that shown)' }),
|
||||
'that that' ]} },
|
||||
'that that' ] },
|
||||
slot_hidden: function(assert){
|
||||
return {code: [
|
||||
return [
|
||||
'<slot slot value hidden/>',
|
||||
'@slot(slot value hidden)',
|
||||
'' ]} },
|
||||
'' ] },
|
||||
slot_hidden_value: function(assert){
|
||||
var ins = this.slot_hidden(assert).code
|
||||
var ins = this.slot_hidden(assert)
|
||||
var expect = ins.pop()
|
||||
return {code: [
|
||||
return [
|
||||
...ins.map(function(i){
|
||||
return i +'@slot(slot other)' }),
|
||||
'' ]} },
|
||||
'' ] },
|
||||
slot_hidden_shown: function(assert){
|
||||
var ins = this.slot_hidden(assert).code
|
||||
var ins = this.slot_hidden(assert)
|
||||
var expect = ins.pop()
|
||||
return {code: [
|
||||
return [
|
||||
...ins.map(function(i){
|
||||
return i +'@slot(slot shown)' }),
|
||||
'' ]} },
|
||||
'' ] },
|
||||
//*/
|
||||
|
||||
// XXX var...
|
||||
// XXX
|
||||
|
||||
// XXX arg...
|
||||
// XXX
|
||||
|
||||
})
|
||||
|
||||
|
||||
test.Modifiers({
|
||||
args: function(assert, state){
|
||||
;(state.state = (state.state ?? {})).args = {
|
||||
number: 1,
|
||||
string: 'string',
|
||||
}
|
||||
return state },
|
||||
})
|
||||
|
||||
|
||||
test.Tests({
|
||||
parse: function(assert, state){
|
||||
var {page, code, st} = state
|
||||
page ??= {}
|
||||
st ??= {}
|
||||
|
||||
var res
|
||||
var inputs = code.slice(0, -1)
|
||||
var expect = code.at(-1)
|
||||
var inputs = state.slice(0, -1)
|
||||
var expect = state.at(-1)
|
||||
var i = 0
|
||||
for(var input of inputs){
|
||||
var p = serialize.partialDeepCopy(page)
|
||||
var s = serialize.partialDeepCopy(st)
|
||||
for(var input of inputs){
|
||||
assert(
|
||||
(res = parser.parse(
|
||||
p,
|
||||
{},
|
||||
input,
|
||||
s))
|
||||
{}))
|
||||
=== expect,
|
||||
'Parsing:',
|
||||
'\n\t in: "'+ input +'"',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user