mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-18 00:51: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(
|
||||
// XXX should this have the same args as include???
|
||||
['src', 'recursive', 'join',
|
||||
['s', 'strict', 'nonstrict', 'isolated']],
|
||||
['s', 'strict', 'nonstrict']],
|
||||
//['src'],
|
||||
async function*(args, body, state){
|
||||
var that = this
|
||||
@ -1069,6 +1069,21 @@ object.Constructor('Page', BasePage, {
|
||||
async function(src, state){
|
||||
//return that.parse(that.get(src).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>)
|
||||
//
|
||||
@ -1248,6 +1263,7 @@ object.Constructor('Page', BasePage, {
|
||||
&& stack.push(slots[name])
|
||||
delete slots[name]
|
||||
var slot = await this.__parser__.expand(this, text, state)
|
||||
var original = slot
|
||||
slots[name]
|
||||
&& stack.unshift(slot)
|
||||
slot = slots[name] =
|
||||
@ -1272,7 +1288,7 @@ object.Constructor('Page', BasePage, {
|
||||
''
|
||||
: Object.assign(
|
||||
function(state){
|
||||
return state.slots[name] },
|
||||
return (state.slots || {})[name] ?? original },
|
||||
{slot: name}) }),
|
||||
'content': ['slot'],
|
||||
|
||||
@ -1304,7 +1320,8 @@ object.Constructor('Page', BasePage, {
|
||||
// XXX SORT sorting not implemented yet....
|
||||
macro: Macro(
|
||||
['name', 'src', 'sort', 'text', 'join', 'else',
|
||||
['strict', 'nonstrict']],
|
||||
['strict', 'nonstrict', 'isolated']],
|
||||
//['strict', 'nonstrict', 'unisolated']],
|
||||
async function*(args, body, state){
|
||||
var that = this
|
||||
var name = args.name //?? args[0]
|
||||
@ -1323,6 +1340,8 @@ object.Constructor('Page', BasePage, {
|
||||
: text
|
||||
var strict = args.strict
|
||||
&& !args.nonstrict
|
||||
var isolated = args.isolated
|
||||
//var isolated = !args.unisolated
|
||||
var join
|
||||
|
||||
var depends = state.depends =
|
||||
@ -1392,7 +1411,18 @@ object.Constructor('Page', BasePage, {
|
||||
if(join && !first){
|
||||
yield join }
|
||||
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...
|
||||
if(first
|
||||
&& (text || args['else'])){
|
||||
@ -2008,6 +2038,32 @@ module.System = {
|
||||
</macro>
|
||||
</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...
|
||||
_path: {text: '@source(./path/! join=" ")'},
|
||||
_location: {text: '@source(./location/! join=" ")'},
|
||||
|
||||
@ -244,7 +244,7 @@ require.config({
|
||||
var STYLE_UPDATED = false
|
||||
var updateStyle = async function(){
|
||||
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???
|
||||
@ -253,7 +253,7 @@ var updateConfig = async function(){
|
||||
// XXX need to set this to something...
|
||||
// XXX
|
||||
// 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??
|
||||
|
||||
19
pwiki2.js
19
pwiki2.js
@ -18,7 +18,23 @@
|
||||
* - 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
|
||||
* (see: pwiki2.html) or via the base templates (see: pwiki/page.js:_view
|
||||
* template)???
|
||||
@ -396,6 +412,7 @@
|
||||
*
|
||||
*
|
||||
* XXX DOC:
|
||||
* - macro isolation in relation to slots...
|
||||
* - paths in pWiki behave a bit differently than traditional
|
||||
* file-system paths, this is due to one key distinction:
|
||||
* in pWiki there is no distinction between a file and a
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user