From 8965ff212402b8c9326b410ef59054decfa597ff Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 13 Aug 2016 01:37:30 +0300 Subject: [PATCH] fixed recursive include + macro overloading + templates tweaking... Signed-off-by: Alex A. Naanou --- wiki.js | 287 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 150 insertions(+), 137 deletions(-) diff --git a/wiki.js b/wiki.js index dc7e926..2286a46 100755 --- a/wiki.js +++ b/wiki.js @@ -139,15 +139,8 @@ var macro = { // NOTE: this will render the page in the caller's context. // NOTE: included pages are rendered completely independently // from the including page. - // - // XXX do we need to control the rendering of nested pages??? - // ...currently I do not think so... - // ...if required this can be done via global and local - // filters... (now filters are only local) - // XXX do we need to render just one slot??? (slot arg) - // e.g. include PageX SlotY include: Macro('Include page', - ['src'], + ['src', 'text'], function(context, elem, state){ var path = $(elem).attr('src') @@ -234,7 +227,9 @@ var macro = { return elem }), - macro: Macro('Define/fill slot', + // XXX revise macro definition rules -- see inside... + // XXX do we need macro namespaces or context isolation (for inculdes)??? + macro: Macro('Define/fill macro', ['name', 'src'], function(context, elem, state, parse){ elem = $(elem) @@ -245,7 +240,14 @@ var macro = { if(name){ - if(elem.html().trim() != ''){ + // XXX not sure which definition rules to use for macros... + // - first define -- implemented now + // - last define -- as in slots + // - first contenr -- original + //if(elem.html().trim() != ''){ + if(elem.html().trim() != '' + // do not redefine... + && state.templates[name] == null){ state.templates[name] = elem.clone() } else if(name in state.templates) { @@ -402,6 +404,13 @@ var macro = { // // XXX support quoted text... // XXX need to quote regexp chars of .__include_marker__... + // XXX include recursion is detected but path recursion is not at + // this point... + // e.g. the folowing paths resolve to the same page: + // /SomePage + // /SomePage/SomePage + // or any path matching: + // /\/(SomePage\/)+/ parse: function(context, text, state, skip_post, pattern){ var that = this @@ -409,6 +418,7 @@ var macro = { state.filters = state.filters || [] state.slots = state.slots || {} state.include = state.include || [] + state.seen = state.seen || [] //pattern = pattern || RegExp('@([a-zA-Z-_]+)\\(([^)]*)\\)', 'mg') pattern = pattern || RegExp.apply(null, this.__macro__pattern__) @@ -542,6 +552,12 @@ var macro = { var elem = $(page.shift()) page = page.pop() + var seen = state.seen.slice() + if(seen.indexOf(page.path) >= 0){ + return elem.html() + } + seen.push(page.path) + return page.map(function(page){ return $('
') .append(elem @@ -550,7 +566,11 @@ var macro = { .append(that .parse(page, page.raw, - { slots: state.slots }, + { + slots: state.slots, + templates: state.templates, + seen: seen, + }, true))) .html() }).join('\n') @@ -770,48 +790,120 @@ var data = { +'', }, - 'Templates/pages': { - //text: ' [@source(./path)]
\n' - text: '' - +'' - +'
' - +'[@source(./path)]' - +'\n' - +'×' - +'
' - +'
\n' - }, - 'Templates/all_pages': { - //text: ' [@source(./path)]
\n' - text: '' - +'' - +'
' - +'[@source(./path)]' - +'\n' - +'×' - +'
' - +'
\n' - }, + // XXX might be a good idea to use this for outline... 'Templates/tree': { //text: ' [@source(./path)]
\n' text: '' - +'
' - +'' - +'
' + +'
\n' + +'\n' + +'
\n' +' \n' - +'@source(./title)' + +'@source(./title)\n' +'\n' - +'×' - +'
' - +'
' + +'×\n' + +'
\n' + +'
\n' +'' - +'
' + +'/>\n' + +'
\n' +'\n' - +'
' + +'
\n' }, + 'Templates/pages': { + //text: ' [@source(./path)]
\n' + text: '' + +'\n' + +'
\n' + +'[@source(./path)]\n' + +'\n' + +'×\n' + +'
\n' + +'
\n' + }, + // XXX this is essentially identical to pages, except for the path... + 'Templates/all_pages': { + //text: ' [@source(./path)]
\n' + text: '' + +'\n' + +'
\n' + +'[@source(./path)]\n' + +'\n' + +'×\n' + +'
\n' + +'
\n' + }, + // XXX experimental... + // XXX need sorting... + 'Templates/outline': { + text: '' + +'\n' + +'\n' + +'\n' + +'\n' + +'\n' + +'\n' + +'\n' + +'×\n' + +'\n' + +'\n' + +'\n' + //* + +'
\n' + // XXX select all on focus... + +'\n' + +'+\n' + +'\n' + +'
\n' + //+'
\n' + //*/ + +'
\n' + +'\n' + +'
\n' + +'
\n' + +'\n' + +'\n' + +'\n' + +'\n' + +'\n' + +'
\n' + +'
\n' + +'\n' + +'
\n' + +'
\n' + /*// XXX do we need this or should we just use CSS??? + +'\n' + +'No items yet...\n' + +'\n' + //*/ + +'
\n' + +'
\n' + +'\n', + }, + // XXX see inside... + 'Templates/todo': { + text: '' + // XXX this feels wrong... + // ...and this will not wirk well with macro override rules... + +'\n' + +' \n' + +'\n' + +'\n' + +'\n' + }, + + // Views... 'Templates/_raw': { text: '@source(..)', }, @@ -878,23 +970,7 @@ var data = { +'' +'', }, - // XXX experimental... - 'Templates/_todo': { - text: '' - +'\n' - +'\n' - // XXX temporary until I figure out how to deal with the saveto=".." - // in implicit vs. explicit _view - +'' - +'@source(../title)' - +'\n' - +'\n' - +'\n' - +'@include(../todo)' - +'' - +'\n', - }, 'Templates/_outline': { text: '' +'\n' @@ -910,85 +986,22 @@ var data = { +'' +'\n', }, + 'Templates/_todo': { + text: '' + +'\n' + +'\n' + // XXX temporary until I figure out how to deal with the saveto=".." + // in implicit vs. explicit _view + +'' + +'@source(../title)' + +'\n' + +'\n' + +'\n' + +'@include(../todo)' + +'' + +'\n' + }, - // XXX experimental... - // XXX need sorting... - 'Templates/todo': { - text: '' - +'
' - //+'' - // XXX select all on focus... - +'' - +'+' - +'' - +'
' - +'
' - +'
' - +'' - +'
' - +'
' - +' \n' - +'' - +'' - +'\n' - +'×' - +'
' - +'
' - +'' - +'
' - +'
' - +'
' - +'
' - +'\n', - }, - 'Templates/outline': { - text: '' - //* - +'
' - // XXX select all on focus... - +'' - +'+' - +'' - +'
' - //+'
' - //*/ - +'
' - +'' - +'
' - +'
' - +' \n' - +'' - +'' - +'×' - +'
' - +'
' - +'' - +'
' - +'
' - +'
' - +'
' - +'\n', - }, } data.__proto__ = BaseData