mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-19 17:41:38 +00:00
added isolated mode to @macro(..) + added @load(..), still experimental + investigating bugs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1ba6f843d2
commit
fc529da8dc
@ -1059,7 +1059,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
source: Macro(
|
source: Macro(
|
||||||
// XXX should this have the same args as include???
|
// XXX should this have the same args as include???
|
||||||
['src', 'recursive', 'join',
|
['src', 'recursive', 'join',
|
||||||
['s', 'strict', 'nonstrict', 'isolated']],
|
['s', 'strict', 'nonstrict']],
|
||||||
//['src'],
|
//['src'],
|
||||||
async function*(args, body, state){
|
async function*(args, body, state){
|
||||||
var that = this
|
var that = this
|
||||||
@ -1069,6 +1069,21 @@ object.Constructor('Page', BasePage, {
|
|||||||
async function(src, state){
|
async function(src, state){
|
||||||
//return that.parse(that.get(src).raw, state) }) }),
|
//return that.parse(that.get(src).raw, state) }) }),
|
||||||
return that.parse(this.raw, state) }) }),
|
return that.parse(this.raw, state) }) }),
|
||||||
|
|
||||||
|
// Load macro and slot definitions but ignore the page text...
|
||||||
|
//
|
||||||
|
// NOTE: this is essentially the same as @source(..) but returns ''.
|
||||||
|
// XXX revise name...
|
||||||
|
load: Macro(
|
||||||
|
['src', ['strict', 'nonstrict']],
|
||||||
|
async function*(args, body, state){
|
||||||
|
var that = this
|
||||||
|
yield* this.macros.include.call(this,
|
||||||
|
'load',
|
||||||
|
args, body, state, 'sources',
|
||||||
|
async function(src, state){
|
||||||
|
await that.parse(this.raw, state)
|
||||||
|
return '' }) }),
|
||||||
//
|
//
|
||||||
// @quote(<src>)
|
// @quote(<src>)
|
||||||
//
|
//
|
||||||
@ -1248,6 +1263,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
&& stack.push(slots[name])
|
&& stack.push(slots[name])
|
||||||
delete slots[name]
|
delete slots[name]
|
||||||
var slot = await this.__parser__.expand(this, text, state)
|
var slot = await this.__parser__.expand(this, text, state)
|
||||||
|
var original = slot
|
||||||
slots[name]
|
slots[name]
|
||||||
&& stack.unshift(slot)
|
&& stack.unshift(slot)
|
||||||
slot = slots[name] =
|
slot = slots[name] =
|
||||||
@ -1272,7 +1288,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
''
|
''
|
||||||
: Object.assign(
|
: Object.assign(
|
||||||
function(state){
|
function(state){
|
||||||
return state.slots[name] },
|
return (state.slots || {})[name] ?? original },
|
||||||
{slot: name}) }),
|
{slot: name}) }),
|
||||||
'content': ['slot'],
|
'content': ['slot'],
|
||||||
|
|
||||||
@ -1304,7 +1320,8 @@ object.Constructor('Page', BasePage, {
|
|||||||
// XXX SORT sorting not implemented yet....
|
// XXX SORT sorting not implemented yet....
|
||||||
macro: Macro(
|
macro: Macro(
|
||||||
['name', 'src', 'sort', 'text', 'join', 'else',
|
['name', 'src', 'sort', 'text', 'join', 'else',
|
||||||
['strict', 'nonstrict']],
|
['strict', 'nonstrict', 'isolated']],
|
||||||
|
//['strict', 'nonstrict', 'unisolated']],
|
||||||
async function*(args, body, state){
|
async function*(args, body, state){
|
||||||
var that = this
|
var that = this
|
||||||
var name = args.name //?? args[0]
|
var name = args.name //?? args[0]
|
||||||
@ -1323,6 +1340,8 @@ object.Constructor('Page', BasePage, {
|
|||||||
: text
|
: text
|
||||||
var strict = args.strict
|
var strict = args.strict
|
||||||
&& !args.nonstrict
|
&& !args.nonstrict
|
||||||
|
var isolated = args.isolated
|
||||||
|
//var isolated = !args.unisolated
|
||||||
var join
|
var join
|
||||||
|
|
||||||
var depends = state.depends =
|
var depends = state.depends =
|
||||||
@ -1392,7 +1411,18 @@ object.Constructor('Page', BasePage, {
|
|||||||
if(join && !first){
|
if(join && !first){
|
||||||
yield join }
|
yield join }
|
||||||
first = false
|
first = false
|
||||||
yield this.__parser__.expand(page, text, state) }
|
if(isolated){
|
||||||
|
var _state = {
|
||||||
|
seen: state.seen,
|
||||||
|
depends,
|
||||||
|
renderer: state.renderer,
|
||||||
|
}
|
||||||
|
// XXX this is ugly, can we avoid this???
|
||||||
|
yield this.__parser__.resolve(page,
|
||||||
|
this.__parser__.expand(page,
|
||||||
|
text, _state), _state)
|
||||||
|
} else {
|
||||||
|
yield this.__parser__.expand(page, text, state) } }
|
||||||
// else...
|
// else...
|
||||||
if(first
|
if(first
|
||||||
&& (text || args['else'])){
|
&& (text || args['else'])){
|
||||||
@ -2008,6 +2038,32 @@ module.System = {
|
|||||||
</macro>
|
</macro>
|
||||||
</slot>`},
|
</slot>`},
|
||||||
|
|
||||||
|
// XXX remove when bug (quote getting trash) fixed...
|
||||||
|
edit_isolated: {
|
||||||
|
// XXX not sure if we should use .title or .name here...
|
||||||
|
text: object.doc`
|
||||||
|
<slot pre>
|
||||||
|
<title>@source(../title) (edit)</title>
|
||||||
|
</slot>
|
||||||
|
|
||||||
|
<slot parent>../..</slot>
|
||||||
|
<slot location>@source(../location/!)</slot>
|
||||||
|
|
||||||
|
<slot content>
|
||||||
|
<macro src=".." join="@source(file-separator)" isolated>
|
||||||
|
<h1 class="title-editor"
|
||||||
|
contenteditable
|
||||||
|
oninput="saveContent(\'@source(s ./path)/title\', this.innerText)">
|
||||||
|
@source(./title)
|
||||||
|
</h1>
|
||||||
|
<pre class="editor"
|
||||||
|
wikiwords="no"
|
||||||
|
contenteditable
|
||||||
|
oninput="saveLiveContent(\'@source(s ./path)\', this.innerText)"
|
||||||
|
><quote filter="quote-tags" src="."/></pre>
|
||||||
|
</macro>
|
||||||
|
</slot>`},
|
||||||
|
|
||||||
// XXX debug...
|
// XXX debug...
|
||||||
_path: {text: '@source(./path/! join=" ")'},
|
_path: {text: '@source(./path/! join=" ")'},
|
||||||
_location: {text: '@source(./location/! join=" ")'},
|
_location: {text: '@source(./location/! join=" ")'},
|
||||||
|
|||||||
@ -244,7 +244,7 @@ require.config({
|
|||||||
var STYLE_UPDATED = false
|
var STYLE_UPDATED = false
|
||||||
var updateStyle = async function(){
|
var updateStyle = async function(){
|
||||||
document.querySelector('#style').innerHTML =
|
document.querySelector('#style').innerHTML =
|
||||||
await pwiki.get('/.config/Style/_raw').text }
|
await pwiki.get('/.config/Style/_text').text }
|
||||||
//*/
|
//*/
|
||||||
|
|
||||||
// XXX might be a good idea to make this a method of pwiki???
|
// XXX might be a good idea to make this a method of pwiki???
|
||||||
@ -253,7 +253,7 @@ var updateConfig = async function(){
|
|||||||
// XXX need to set this to something...
|
// XXX need to set this to something...
|
||||||
// XXX
|
// XXX
|
||||||
// XXX need to use a parser that supports comments and stuff...
|
// XXX need to use a parser that supports comments and stuff...
|
||||||
return JSON.parse(await pwiki.get('/.config/Config/_raw').text) }
|
return JSON.parse(await pwiki.get('/.config/Config/_text').text) }
|
||||||
|
|
||||||
|
|
||||||
// XXX versioning??
|
// XXX versioning??
|
||||||
|
|||||||
19
pwiki2.js
19
pwiki2.js
@ -18,7 +18,23 @@
|
|||||||
* - CLI -
|
* - CLI -
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX parser: might be a good idea to make slots local to macro by default...
|
* XXX BUG: in .system/edit if macro is isolated then @quote(..) will
|
||||||
|
* for some reason get odd stuff like '[object Object]'...
|
||||||
|
* these break:
|
||||||
|
* /QuoteTest/edit_isolated
|
||||||
|
* /MacroSlotTest/edit_isolated
|
||||||
|
* these work:
|
||||||
|
* /QuoteTest/edit
|
||||||
|
* /MacroSlotTest/edit
|
||||||
|
* ...can't produce a minimal example (/QuoteTest) other than
|
||||||
|
* editing .system/edit...
|
||||||
|
* ...seems that in isolated mode some macros get expanded before/in @quote(..)
|
||||||
|
* XXX remove .system/edit_isolated when done...
|
||||||
|
* XXX MACRO: should <macro>'s isolated be on by default???
|
||||||
|
* ...do we need to isolate named macros too???
|
||||||
|
* ...should this isolation be one-directional???
|
||||||
|
* ...i.e. iterations see/overload things defined above but
|
||||||
|
* can not affect the above context...
|
||||||
* XXX STYLE: should style loading be done via the event mechanics
|
* XXX STYLE: should style loading be done via the event mechanics
|
||||||
* (see: pwiki2.html) or via the base templates (see: pwiki/page.js:_view
|
* (see: pwiki2.html) or via the base templates (see: pwiki/page.js:_view
|
||||||
* template)???
|
* template)???
|
||||||
@ -396,6 +412,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX DOC:
|
* XXX DOC:
|
||||||
|
* - macro isolation in relation to slots...
|
||||||
* - paths in pWiki behave a bit differently than traditional
|
* - paths in pWiki behave a bit differently than traditional
|
||||||
* file-system paths, this is due to one key distinction:
|
* file-system paths, this is due to one key distinction:
|
||||||
* in pWiki there is no distinction between a file and a
|
* in pWiki there is no distinction between a file and a
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user