Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-04-19 00:43:41 +03:00
parent f7002e20cd
commit 1057768821

View File

@ -301,6 +301,39 @@ module.page = {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var object = require('ig-object')
var Page = object.Constructor('Page', {
store: undefined,
path: undefined,
referrer: undefined,
// store api...
// XXX
exists: relProxy('exists'),
match: relProxy('match'),
// XXX should this return page objects???
get: relProxy('get'),
update: function(path='.', data, mode){
if(arguments.length == 1){
data = path
path = '.' }
return this.store.update(module.path.relative(this.path, path), data, mode) },
delete: relProxy('delete'),
// render api...
// XXX
__init__: function(path, referrer){
this.path = path
this.referrer = referrer },
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
@ -452,7 +485,7 @@ function*(str){
// type: 'inline' // type: 'inline'
// | 'element' // | 'element'
// | 'block', // | 'block',
// block: [ // body: [
// <item>, // <item>,
// ... // ...
// ], // ],
@ -508,24 +541,33 @@ function*(str){
yield* group(lex(str)) } yield* group(lex(str)) }
// XXX need context -- page/store...
// XXX blocks are not handled correctly...
// XXX closure: macros // XXX closure: macros
var expand = var expand =
module.expand = module.expand =
function(str){ function*(ast){
var parser = parse(str) // XXX
var page
while(true){ while(true){
var {elem, done} = parse.next() var {value, done} = ast.next()
if(done){ if(done){
return } return }
// text block... // text block...
if(typeof(elem) == 'string'){ if(typeof(value) == 'string'){
yield elem } yield value
continue }
// macro... // macro...
var {name, args, block} = elem var {name, args, body, match} = value
// XXX need context... var res =
yield* macros[name](args, block) macros[name](page, args, body, match)
} ?? ''
} // XXX test if iterable...
if(res instanceof Array){
// XXX recursively expand this...
yield* res
} else {
yield res } } }
// XXX // XXX
@ -552,7 +594,14 @@ var WIKIWORD_PATTERN =
var filters = { var filters = {
} }
var macros = { var macros = {
now: function(){}, // XXX remove this...
test: function(page, args, block, match){
console.log('test:', ...arguments)
return 'TEST' },
// XXX STUB
now: function(){
return [''+ Date.now()] },
filter: function(){}, filter: function(){},
include: function(){}, include: function(){},
source: function(){}, source: function(){},