mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
pushed @defmacro(..) to the rear of the todo/ideas stack -- requires to much rework...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
bb04752e7a
commit
cedd1bbb79
@ -1460,6 +1460,30 @@ object.Constructor('Page', BasePage, {
|
||||
if(else_block){
|
||||
yield this.__parser__.expand(this, else_block, state) } } } }),
|
||||
|
||||
/* XXX this is not possible with the current parser as we statically
|
||||
// define the macro name list (regexp) for the lexer...
|
||||
// ...so to make this happen we'd need to:
|
||||
// - update the patterns for parser.lex(..)
|
||||
// - tweak parser.group(..)
|
||||
// Like @macro(..) but requires the name argument and will define
|
||||
// the macros in state.usermacros instead of state.macros...
|
||||
defmacro: Macro(
|
||||
['name', 'src', 'sort', 'text', 'join', 'else',
|
||||
['strict', 'isolated', 'inheritmacros' ]],
|
||||
async function*(args, body, state){
|
||||
var name = args.name
|
||||
if(!name){
|
||||
// XXX throw err???
|
||||
return '' }
|
||||
state.usermacros = state.usermacros ?? {}
|
||||
var s = {}
|
||||
var res = await this.macros.macro.call(this, args, body, s)
|
||||
Object.assign(
|
||||
state.usermacros,
|
||||
s.macros)
|
||||
return res }),
|
||||
//*/
|
||||
|
||||
// nesting rules...
|
||||
'else': ['macro'],
|
||||
'join': ['macro'],
|
||||
|
||||
@ -201,9 +201,10 @@ module.BaseParser = {
|
||||
return res },
|
||||
// XXX should this be here or on page???
|
||||
callMacro: function(page, name, args, body, state, ...rest){
|
||||
return page.macros[name].call(page,
|
||||
var macro = page.macros[name]
|
||||
return macro.call(page,
|
||||
this.parseArgs(
|
||||
page.macros[name].arg_spec
|
||||
macro.arg_spec
|
||||
?? [],
|
||||
args),
|
||||
body,
|
||||
|
||||
12
pwiki2.js
12
pwiki2.js
@ -18,8 +18,6 @@
|
||||
* - CLI -
|
||||
*
|
||||
*
|
||||
* XXX macros: add @defmacro(<name> ..) to be exactly as @macro(<name> ..)
|
||||
* but defines a @<name>(..) macro...
|
||||
* XXX BUG: parser:
|
||||
* This will break:
|
||||
* await pwiki.parse('<macro src=../tags join=", ">@source(.)</macro>')
|
||||
@ -242,6 +240,16 @@
|
||||
* or render as any other page???
|
||||
* ...currently they are rendered in the context of the page and
|
||||
* not in their own context...
|
||||
* XXX macros: add @defmacro(<name> ..) to be exactly as @macro(<name> ..)
|
||||
* but defines a @<name>(..) macro...
|
||||
* ...this would be useful for things like:
|
||||
* <pw:delete src="."/>
|
||||
* or:
|
||||
* <pw:info src="."/>
|
||||
* generating delete and info buttons...
|
||||
* ...this is not possible because:
|
||||
* - we statically set the macro name list (regexp) parser.lex(..)
|
||||
* - we need this list to parser.group(..)
|
||||
* XXX EXPERIMENTAL DOC INHERIT_ARGS added a special-case...
|
||||
* as basename will get appended :$ARGS if no args are given...
|
||||
* ...this only applies to paths referring to the current context
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user