added optional include isolation...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-08-15 21:55:20 +03:00
parent 6ad5cf4d1d
commit f796ddf256
3 changed files with 31 additions and 6 deletions

2
bootstrap.js vendored

File diff suppressed because one or more lines are too long

View File

@ -88,7 +88,7 @@ Example:
- `[./_edit]` -- see the macro at the end of the page.
### include (src text)
### include (src isolated text)
Include a page. The included page is rendered independently from current
page and is inserted as-is in macro body.
@ -99,6 +99,7 @@ but an html element body.
Arguments:
- `src` -- path to source page.
- `isolated` -- prevent slots from included page from affecting the including page.
- `text` -- is used when recursive include is detected and ignored otherwise.
### source (src) / quote (src)

32
wiki.js
View File

@ -140,7 +140,7 @@ var macro = {
// NOTE: included pages are rendered completely independently
// from the including page.
include: Macro('Include page',
['src', 'text'],
['src', 'isolated', 'text'],
function(context, elem, state){
var path = $(elem).attr('src')
@ -425,7 +425,7 @@ var macro = {
state = state || {}
state.filters = state.filters || []
state.slots = state.slots || {}
//state.slots = state.slots || {}
state.include = state.include || []
state.seen = state.seen || []
@ -570,6 +570,7 @@ var macro = {
var page = state.include.shift()
var elem = $(page.shift())
page = page.pop()
var isolated = elem.attr('isolated') == 'true'
var seen = state.seen.slice()
if(seen.indexOf(page.path) >= 0){
@ -586,15 +587,22 @@ var macro = {
.parse(page,
page.raw,
{
slots: state.slots,
//slots: !isolated ? state.slots : {},
templates: state.templates,
seen: seen,
},
true)))
!isolated)))
//true)))
.html()
}).join('\n')
}))
console.log('>>>>',
context.path,
skip_post,
parsed.find(':not([isolated="true"]) slot').length,
parsed.find('[isolated="true"] slot').length)
// post processing...
if(!skip_post){
// fill slots...
@ -605,6 +613,14 @@ var macro = {
parsed.find('slot')
.each(function(i, e){
e = $(e)
// XXX not sure about this...
// ...check if it prevents correct slot parsing
// within an isolated include...
if(e.parents('[isolated="true"]').length > 0){
return
}
var n = e.attr('name')
n in slots && e.detach()
@ -615,6 +631,14 @@ var macro = {
parsed.find('slot')
.each(function(i, e){
e = $(e)
// XXX not sure about this...
// ...check if it prevents correct slot parsing
// within an isolated include...
if(e.parents('[isolated="true"]').length > 0){
return
}
var n = e.attr('name')
e.replaceWith(slots[n])