mirror of
https://github.com/flynx/pWiki.git
synced 2025-11-01 03:20:08 +00:00
@quote(..) now a generator macro...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a3fa8985ec
commit
0fcfe08ce2
102
pwiki/page.js
102
pwiki/page.js
@ -689,7 +689,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
|
|
||||||
var first = true
|
var first = true
|
||||||
for await (var page of this.get(src).each()){
|
for await (var page of this.get(src).each()){
|
||||||
if(!first){
|
if(join && !first){
|
||||||
yield join }
|
yield join }
|
||||||
first = false
|
first = false
|
||||||
|
|
||||||
@ -759,13 +759,10 @@ object.Constructor('Page', BasePage, {
|
|||||||
// not expanded...
|
// not expanded...
|
||||||
// NOTE: the filter argument uses the same filters as @filter(..)
|
// NOTE: the filter argument uses the same filters as @filter(..)
|
||||||
//
|
//
|
||||||
// XXX GENERATOR make this a generator...
|
|
||||||
// XXX need to handle pattern paths (like include: join=...)
|
|
||||||
// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
|
// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
|
||||||
quote: Macro(
|
quote: Macro(
|
||||||
//['src', 'filter', 'text', 'join'],
|
['src', 'filter', 'text', 'join'],
|
||||||
['src', 'filter', 'text'],
|
async function*(args, body, state){
|
||||||
async function(args, body, state){
|
|
||||||
var src = args.src //|| args[0]
|
var src = args.src //|| args[0]
|
||||||
var base = this.get(this.path.split(/\*/).shift())
|
var base = this.get(this.path.split(/\*/).shift())
|
||||||
var text = args.text
|
var text = args.text
|
||||||
@ -775,43 +772,59 @@ object.Constructor('Page', BasePage, {
|
|||||||
src = src ?
|
src = src ?
|
||||||
await base.parse(src, state)
|
await base.parse(src, state)
|
||||||
: src
|
: src
|
||||||
text = src ?
|
|
||||||
// source page...
|
|
||||||
await this.get(src).raw
|
|
||||||
: text instanceof Array ?
|
|
||||||
text.join('')
|
|
||||||
: text
|
|
||||||
|
|
||||||
|
var pages = src ?
|
||||||
|
this.get(src).each()
|
||||||
|
: text instanceof Array ?
|
||||||
|
[text.join('')]
|
||||||
|
: typeof(text) == 'string' ?
|
||||||
|
[text]
|
||||||
|
: text
|
||||||
// empty...
|
// empty...
|
||||||
if(!text){
|
if(!pages){
|
||||||
return }
|
return }
|
||||||
|
|
||||||
var filters =
|
var join = args.join
|
||||||
args.filter
|
&& await base.parse(args.join, state)
|
||||||
&& args.filter
|
var first = true
|
||||||
.trim()
|
for await (var page of pages){
|
||||||
.split(/\s+/g)
|
if(join && !first){
|
||||||
|
yield join }
|
||||||
|
first = false
|
||||||
|
|
||||||
// NOTE: we are delaying .quote_filters handling here to
|
text = typeof(page) == 'string' ?
|
||||||
// make their semantics the same as general filters...
|
page
|
||||||
// ...and since we are internally calling .filter(..)
|
: await page.raw
|
||||||
// macro we need to dance around it's architecture too...
|
|
||||||
// NOTE: since the body of quote(..) only has filters applied
|
var filters =
|
||||||
// to it doing the first stage of .filter(..) as late
|
args.filter
|
||||||
// as the second stage here will have no ill effect...
|
&& args.filter
|
||||||
// NOTE: this uses the same filters as @filter(..)
|
.trim()
|
||||||
return async function(state){
|
.split(/\s+/g)
|
||||||
// add global quote-filters...
|
|
||||||
filters =
|
// NOTE: we are delaying .quote_filters handling here to
|
||||||
(state.quote_filters
|
// make their semantics the same as general filters...
|
||||||
&& !(filters ?? []).includes(this.ISOLATED_FILTERS)) ?
|
// ...and since we are internally calling .filter(..)
|
||||||
[...state.quote_filters, ...(filters ?? [])]
|
// macro we need to dance around it's architecture too...
|
||||||
: filters
|
// NOTE: since the body of quote(..) only has filters applied
|
||||||
return filters ?
|
// to it doing the first stage of .filter(..) as late
|
||||||
await this.__parser__.callMacro(
|
// as the second stage here will have no ill effect...
|
||||||
this, 'filter', filters, text, state, false)
|
// NOTE: this uses the same filters as @filter(..)
|
||||||
.call(this, state)
|
// NOTE: the function wrapper here isolates text in
|
||||||
: text } }),
|
// a closure per function...
|
||||||
|
yield (function(text){
|
||||||
|
return async function(state){
|
||||||
|
// add global quote-filters...
|
||||||
|
filters =
|
||||||
|
(state.quote_filters
|
||||||
|
&& !(filters ?? []).includes(this.ISOLATED_FILTERS)) ?
|
||||||
|
[...state.quote_filters, ...(filters ?? [])]
|
||||||
|
: filters
|
||||||
|
return filters ?
|
||||||
|
await this.__parser__.callMacro(
|
||||||
|
this, 'filter', filters, text, state, false)
|
||||||
|
.call(this, state)
|
||||||
|
: text } })(text) } }),
|
||||||
// very similar to @filter(..) but will affect @quote(..) filters...
|
// very similar to @filter(..) but will affect @quote(..) filters...
|
||||||
'quote-filter': function(args, body, state){
|
'quote-filter': function(args, body, state){
|
||||||
var filters = state.quote_filters =
|
var filters = state.quote_filters =
|
||||||
@ -1460,7 +1473,6 @@ module.System = {
|
|||||||
test_list: function(){
|
test_list: function(){
|
||||||
return 'abcdef'.split('') },
|
return 'abcdef'.split('') },
|
||||||
test_slots: {
|
test_slots: {
|
||||||
/* XXX
|
|
||||||
text: object.doc`
|
text: object.doc`
|
||||||
Sequential:
|
Sequential:
|
||||||
<slot name="sequential">unfilled</slot>
|
<slot name="sequential">unfilled</slot>
|
||||||
@ -1483,7 +1495,17 @@ module.System = {
|
|||||||
<slot name="slot-content"><content/> B</slot>
|
<slot name="slot-content"><content/> B</slot>
|
||||||
<slot name="slot-conten"><content/> C</slot>
|
<slot name="slot-conten"><content/> C</slot>
|
||||||
<br><br>
|
<br><br>
|
||||||
//*/
|
Nested content: A B C:
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
A
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
<content/> B
|
||||||
|
<slot name="nested-slot-content">
|
||||||
|
<content/> C
|
||||||
|
</slot>
|
||||||
|
</slot>
|
||||||
|
</slot> ` },
|
||||||
|
test_nested_slots: {
|
||||||
text: object.doc`
|
text: object.doc`
|
||||||
Nested content: A B C:
|
Nested content: A B C:
|
||||||
<slot name="nested-slot-content">
|
<slot name="nested-slot-content">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user