cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2026-07-06 02:06:13 +03:00
parent 5f64d70fbb
commit 31b22be60b
2 changed files with 33 additions and 59 deletions

View File

@ -1308,12 +1308,11 @@ module.parser = {
recursive ??= '' recursive ??= ''
var base = page.basepath var base = page.basepath
// XXX we do this before or after we parse???
var src = page.resolvePathVars(args.src)
return Promise.awaitOrRun( return Promise.awaitOrRun(
this.parseNested(page, src, state), this.parseNested(page, args.src, state),
function(src){ function(src){
//src = page.resolvePathVars(src)
// XXX should this be a tree?? // XXX should this be a tree??
// ...need to at least split direct and // ...need to at least split direct and
// indirect dependencies... // indirect dependencies...
@ -1431,7 +1430,7 @@ module.parser = {
var that = this var that = this
return this.macros['include'].call(this, return this.macros['include'].call(this,
page, args, body, state, page, args, body, state,
function(page, src, text, state){ function(page, body, path, text, state){
return that.expand(page, text, state) }) }), return that.expand(page, text, state) }) }),
// Load macro and slot definitions but ignore the page text... // Load macro and slot definitions but ignore the page text...
@ -1442,7 +1441,8 @@ module.parser = {
function(page, args, body, state){ function(page, args, body, state){
var that = this var that = this
return Promise.awaitOrRun( return Promise.awaitOrRun(
this.macros['include'].call(this, page, args, body, state), this.macros['include'].call(this,
page, {src: args.src}, body, state),
function(){ function(){
return '' }) }), return '' }) }),
@ -1485,6 +1485,7 @@ module.parser = {
args.src args.src
&& this.parseNested(page, args.src, state), && this.parseNested(page, args.src, state),
function(src){ function(src){
//src = page.resolvePathVars(src)
var text = var text =
src ? src ?
page.get(src).raw page.get(src).raw
@ -1494,20 +1495,6 @@ module.parser = {
return Promise.awaitOrRun( return Promise.awaitOrRun(
text, text,
function(text){ function(text){
// XXX not sure I like that this has two "modes"...
text = src && body ?
// XXX do we need to account for generators???
(text instanceof Array ?
text
: [text])
.map(function(text){
return that.expand(
page,
that.ast(body.join(''), false, 'quote'),
state,
{ content: function(){
return text }, }) })
: text
return that.joinBlocks( return that.joinBlocks(
page, page,
that.filterBlocks( that.filterBlocks(
@ -1582,40 +1569,20 @@ module.parser = {
// get macro... // get macro...
} else if(name){ } else if(name){
body = (state.macros ?? {})[name] } body = (state.macros ?? {})[name] }
// else...
if(args.src
&& !page.get(args.src).exists()){
for(var elem of body){
if(elem.name == 'else'){
body = elem.body
return that.expand(page.get(args.src), elem.body, state) } } }
return args.src && body ? return args.src && body ?
// run macro... // run macro...
that.macros.include.call(that, page, args, body, state, that.macros.include.call(that, page, args, body, state,
function(page, body, path, text, state){ function(page, body, path, text, state){
var that = this return this.expand(page.get(path), body, state) })
var handle = function(page, text, state){
return args.isolated ?
that.resolve(
page,
text,
Object.assign(
args.isolated == 'partial' ?
serialize.partialDeepCopy(state)
: {},
{include_stack: state.include_stack ?? []}))
: that.expand(page, text, state) }
//var content_handled = false
return body ?
// handle body / <content/>...
Promise.awaitOrRun(
that.expand(page.get(path), body, state,
{ content: function(){
content_handled = true
return text = handle(page, text, state) } }),
function(text){
// if no <content/> present we still
// need to handle the included page...
//content_handled
// || handle.call(that, page, text, state)
return text })
// place as-is...
: handle(page, text, state) })
: '' }) })), : '' }) })),
// nesting rules... // nesting rules...

View File

@ -56,6 +56,9 @@ module.exports.P = {
get matched(){ get matched(){
var path_action_pattern = /\/path\/?/ var path_action_pattern = /\/path\/?/
var path = this.path.replace(path_action_pattern, '') var path = this.path.replace(path_action_pattern, '')
path = path == '' ?
'/'
: path
var path_action = path != this.path var path_action = path != this.path
if(path.includes('*')){ if(path.includes('*')){
@ -72,17 +75,27 @@ module.exports.P = {
: [] }) : [] })
.flat() } .flat() }
return [this.path] }, return [this.path] },
exists: function(path){
var that = this
return (path ?
this.get(path).matched
: this.matched)
.filter(function(p){
return p in that.__pages__ })
.length > 0 },
// * -> a promise or a list of promises??? // * -> a promise or a list of promises???
get raw(){ get raw(){
var res = [] var res = []
var path_action_pattern = /\/path\/?/ var path_action_pattern = /\/path\/?/
var path_action = this.path.match(path_action_pattern) var path_action = path_action_pattern.test(this.path)
for(var path of this.matched){ for(var path of this.matched){
res.push( res.push(
path_action ? path_action ?
path.replace(path_action_pattern, '') ((path = path.replace(path_action_pattern, '')) == '' ?
'/'
: path)
: this.__pages__[path]) } : this.__pages__[path]) }
return res.length == 1 ? return res.length == 1 ?
@ -315,13 +328,7 @@ test.Setups({
// quote... // quote...
// for inline quoting see: test.Modifiers.quote // for inline quoting see: test.Modifiers.quote
// XXX <quote src=.. /> // XXX
quote_content: function(assert, path='/isolated'){
return {
page: P,
code: [
'<quote "'+ path +'">[[ <content/> ]]</quote>',
'[[ '+ P.get(path).raw +' ]]', ], } },
// XXX macro... // XXX macro...
// XXX // XXX