mirror of
https://github.com/flynx/pWiki.git
synced 2026-10-03 04:41:39 +00:00
Compare commits
4 Commits
31b22be60b
...
d8f8d5cc1e
| Author | SHA1 | Date | |
|---|---|---|---|
| d8f8d5cc1e | |||
| 5d7bc6ec3d | |||
| 677a639047 | |||
| 26073fb713 |
@ -137,6 +137,8 @@ bot from within pWiki as well as outside.
|
||||
|
||||
### now ()
|
||||
|
||||
XXX
|
||||
|
||||
```
|
||||
\@now()
|
||||
```
|
||||
@ -295,8 +297,6 @@ Will render to: `original [ ]`
|
||||
|
||||
<source <src>>
|
||||
...
|
||||
<content/>
|
||||
...
|
||||
</source>
|
||||
```
|
||||
|
||||
@ -331,6 +331,53 @@ Arguments:
|
||||
]]-->
|
||||
|
||||
|
||||
### macro (_name_ _src_ _join_ _else_) / else
|
||||
|
||||
Define and/or apply a macro.
|
||||
|
||||
```
|
||||
@macro(name=".." src=".." text=".." else="..")
|
||||
|
||||
<macro name=".." src="..">
|
||||
...
|
||||
<else>
|
||||
...
|
||||
</else>
|
||||
</macro>
|
||||
```
|
||||
|
||||
|
||||
If `name` is given a _named macro_ is defined. This macro can be later
|
||||
referenced (used) by name. A named macro can be redefined/overridden.
|
||||
|
||||
If `src` is given then expand the macro in applied to (i.e. expanded
|
||||
in the context of) a page or range of pages and the result is included
|
||||
in the current page.
|
||||
|
||||
This differs frome `@include(..)` in that it does not load the rource
|
||||
page, it only executes macros in it's context.
|
||||
|
||||
Both `name` and `src` are optional.
|
||||
|
||||
For a macro to be useful it must have a body (or a `text`/`body` attribute),
|
||||
either defined as a named macro or in the current macro.
|
||||
|
||||
The `<else>` macro (or `else` attribute) is used if the `src` does not match
|
||||
any pages.
|
||||
|
||||
**Example:**
|
||||
|
||||
<pwiki-comment>
|
||||
- [bootstrap pages](/bootstrap/Templates/pages.html)
|
||||
</pwiki-comment>
|
||||
|
||||
<!--[pWiki[
|
||||
[Templates/pages] / [bootstrap pages](bootstrap/Templates/pages.html):
|
||||
```
|
||||
@source(Templates/pages)
|
||||
```
|
||||
]]-->
|
||||
|
||||
|
||||
---
|
||||
|
||||
@ -363,45 +410,6 @@ macro at the end of the page._
|
||||
|
||||
|
||||
|
||||
### macro (name src sort) / else ()
|
||||
|
||||
Apply macro to source page and include the result.
|
||||
|
||||
This is similar to include but does not require a separate page.
|
||||
|
||||
Both `name` and `src` are optional.
|
||||
|
||||
If `name` is given a _named macro_ is defined. This macro can be later
|
||||
referenced (used) by name. A named macro can be redefined/overridden.
|
||||
|
||||
If `src` is given a macro is applied to a specific page or range of pages
|
||||
(see: WikiPath).
|
||||
|
||||
For a macro to be useful it must have a body (`text`), either defined as
|
||||
a named macro or in the current macro.
|
||||
|
||||
Arguments:
|
||||
- `name` -- macro name (optional).
|
||||
- `src` -- path to source page (optional).
|
||||
- `sort` -- space separated list of methods to use for item sorting
|
||||
|
||||
|
||||
`else` macro is applicable inside `macro`. it is used when the `src` path
|
||||
of `macro` matches no pages.
|
||||
|
||||
**Example:**
|
||||
|
||||
<pwiki-comment>
|
||||
- [bootstrap pages](/bootstrap/Templates/pages.html)
|
||||
</pwiki-comment>
|
||||
|
||||
<!--[pWiki[
|
||||
[Templates/pages] / [bootstrap pages](bootstrap/Templates/pages.html):
|
||||
```
|
||||
@source(Templates/pages)
|
||||
```
|
||||
]]-->
|
||||
|
||||
|
||||
<!-- @filter(markdown) -->
|
||||
<!-- vim:set ts=4 sw=4 ft=markdown : -->
|
||||
|
||||
@ -1244,6 +1244,8 @@ module.parser = {
|
||||
function(st){
|
||||
return ((st ?? state).slots ?? {})[name] },
|
||||
{slot: name}) }) })),
|
||||
// XXX do not like this name...
|
||||
content: ['slot'],
|
||||
|
||||
|
||||
//
|
||||
@ -1546,16 +1548,13 @@ module.parser = {
|
||||
// that <store>.match(..) can not know about...
|
||||
// XXX should we do the same for offset???
|
||||
//
|
||||
// XXX BUG: strict does not seem to work:
|
||||
// @macro(src="./resolved-page" else="no" text="yes" strict)
|
||||
// -> yes
|
||||
// should be "no"
|
||||
// ...this seems to effect non-pattern pages...
|
||||
// XXX macro variables...
|
||||
// XXX should macro:index be 0 or 1 (current) based???
|
||||
// XXX SORT sorting not implemented yet...
|
||||
// XXX sorting...
|
||||
// XXX check macro recursion...
|
||||
macro: Macro(
|
||||
['name', 'src', 'sort', 'text', 'join', 'else',
|
||||
//['name', 'src', 'sort', 'text', 'join', 'else',
|
||||
['name', 'src', 'join', 'else',
|
||||
['strict', 'isolated', 'inheritmacros', 'inheritvars']],
|
||||
lazy(
|
||||
function(page, args, body, state){
|
||||
@ -1566,6 +1565,7 @@ module.parser = {
|
||||
// set macro...
|
||||
if(name && body){
|
||||
;(state.macros ??= {})[name] = body
|
||||
|
||||
// get macro...
|
||||
} else if(name){
|
||||
body = (state.macros ?? {})[name] }
|
||||
@ -1573,10 +1573,18 @@ module.parser = {
|
||||
// else...
|
||||
if(args.src
|
||||
&& !page.get(args.src).exists()){
|
||||
// <else> .. </else>
|
||||
for(var elem of body){
|
||||
if(elem.name == 'else'){
|
||||
body = elem.body
|
||||
return that.expand(page.get(args.src), elem.body, state) } } }
|
||||
return that.expand(page.get(args.src), body, state) } }
|
||||
// args.else...
|
||||
return args['else'] ?
|
||||
that.expand(page.get(args.src), args['else'], state)
|
||||
: [] }
|
||||
|
||||
// join macro???
|
||||
// XXX
|
||||
|
||||
return args.src && body ?
|
||||
// run macro...
|
||||
@ -1584,12 +1592,9 @@ module.parser = {
|
||||
function(page, body, path, text, state){
|
||||
return this.expand(page.get(path), body, state) })
|
||||
: '' }) })),
|
||||
|
||||
// nesting rules...
|
||||
'else': ['macro'],
|
||||
join: ['macro'],
|
||||
// XXX do not like this name...
|
||||
content: ['slot', 'include', 'quote', 'macro'],
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@ -53,6 +53,7 @@ module.exports.P = {
|
||||
get basepath(){
|
||||
return path.dirname(this.path ?? '') },
|
||||
|
||||
// XXX should this return current path if it does not exixt???
|
||||
get matched(){
|
||||
var path_action_pattern = /\/path\/?/
|
||||
var path = this.path.replace(path_action_pattern, '')
|
||||
@ -74,6 +75,7 @@ module.exports.P = {
|
||||
:p]
|
||||
: [] })
|
||||
.flat() }
|
||||
// XXX should this return current path if it does not exixt???
|
||||
return [this.path] },
|
||||
exists: function(path){
|
||||
var that = this
|
||||
@ -287,24 +289,12 @@ test.Setups({
|
||||
'original overloaded',
|
||||
],
|
||||
} },
|
||||
/* XXX
|
||||
include_partial_isolated: function(assert){
|
||||
return {
|
||||
page: P,
|
||||
code:[
|
||||
'@include(isolated="partial" /isolated) @slot(slot overloaded)',
|
||||
'original overloaded',
|
||||
],
|
||||
} },
|
||||
//*/
|
||||
/*/ XXX content...
|
||||
include_content: function(assert, path='/page'){
|
||||
return {
|
||||
page: P,
|
||||
code: [
|
||||
'<include "'+ path +'">[[ <content/> ]]</include>',
|
||||
'[[ '+ P.get(path).raw +' ]]', ], } },
|
||||
//*/
|
||||
'original overloaded', ], } },
|
||||
// XXX
|
||||
|
||||
// recursion...
|
||||
@ -330,8 +320,21 @@ test.Setups({
|
||||
// for inline quoting see: test.Modifiers.quote
|
||||
// XXX
|
||||
|
||||
// XXX macro...
|
||||
// XXX
|
||||
// macro...
|
||||
macro: function(assert, path='/page', res){
|
||||
return {
|
||||
page: P,
|
||||
code: [
|
||||
'<macro src="'+ path +'">[[ @source(./path) ]]</macro>',
|
||||
res ?? ('[[ '+ path +' ]]'), ], } },
|
||||
macro_404: function(assert){
|
||||
return this.macro(assert, '/not_found', '') },
|
||||
macro_else: function(assert){
|
||||
return {
|
||||
page: P,
|
||||
code: [
|
||||
'<macro src="/not_found">[[ @source(./path) ]]<else>ERR</else></macro>',
|
||||
'ERR', ], } },
|
||||
|
||||
// XXX var...
|
||||
// XXX
|
||||
@ -339,6 +342,9 @@ test.Setups({
|
||||
// XXX arg...
|
||||
// XXX
|
||||
|
||||
// XXX filter...
|
||||
// XXX
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user