experimenting with rendering...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-09-02 17:44:05 +03:00
parent f9379618ca
commit 4c44cf7e8b

View File

@ -3110,32 +3110,61 @@ var BaseBrowserPrototype = {
// nested context -> return item list... // nested context -> return item list...
: items } }, : items } },
// XXX .walk(..): shoulc calling. next(..) return the list to the // XXX EXPERIMENTAL....
// user and let them handle it??? // XXX move this out???
// ...currently the user will get the list and each item will // ...should there be a placeholder renderer???
// be added to the stream to the list by .walk(..) this __renderer__: {
// preventing the user from actually modifying the output... // placeholders...
render2: function(options, renderer, context){ root: null,
options: null,
// XXX args... // renderers...
options = { elem: function(e){
includeInlinedBlocks: true, return e.id || e },
iterateNonIterable: true, inline: function(lst){
} return lst },
nest: function(header, lst){
// XXX rendering... header = this.elem(header)
var inline = function(lst){
return lst }
var nest = function(header, lst){
return [ return [
header, header,
...(lst || []).map(function(e){ ...(lst || []).map(function(e){
return header +'/'+ e })]} return header +'/'+ e }) ] },
var elem = function(e){
return e.id || e } // render life-cycle...
start: function(root, options){
return Object.assign(
Object.create(this),
{
root,
options,
}) },
finalize: function(lst){
return lst.join('\n') },
},
// XXX need:
// - section rendering...
// - from/to/around/count support...
// - ability to render separate items/sub-trees or lists of items...
render2: function(options, renderer){
var that = this
// XXX args...
renderer = renderer || this.__renderer__
renderer = renderer.root == null ?
renderer.start(
this,
Object.assign(
Object.create(this.options || {}),
{
iterateNonIterable: true,
includeInlinedBlocks: true,
},
options || {}))
: renderer
options = renderer.options
return this.walk(function(e, i, p, children){ return this.walk(function(e, i, p, children){
// do not go down child browsers -- use their mechanics for rendering... // do not go down child browsers -- use their mechanics for rendering...
;(e instanceof BaseBrowser || e.children instanceof BaseBrowser) ;(e instanceof BaseBrowser || e.children instanceof BaseBrowser)
&& children(false) && children(false)
@ -3143,26 +3172,29 @@ var BaseBrowserPrototype = {
return ( return (
// inlined... // inlined...
e instanceof BaseBrowser ? e instanceof BaseBrowser ?
inline(e.render2(options, renderer, context)) renderer.inline(e.render2(options, renderer))
: e instanceof Array ? : e instanceof Array ?
inline(children(true)) renderer.inline(children(true))
// nested... // nested...
: e.children instanceof BaseBrowser ? : e.children instanceof BaseBrowser ?
nest(elem(e), renderer.nest(e,
// NOTE: we handle .collapsed here as the nested // NOTE: we handle .collapsed here as the nested
// browser is one level down and knows nothing // browser is one level down and knows nothing
// of it... // of it...
(options.iterateCollapsed || !e.collapsed) (options.iterateCollapsed || !e.collapsed)
&& e.children.render2(options, renderer, context)) && e.children.render2(options, renderer))
: e.children instanceof Array ? : e.children instanceof Array ?
nest(elem(e), children(true)) renderer.nest(e, children(true))
// normal item... // normal item...
: elem(e) ) : renderer.elem(e) )
}, options) }, options)
}, .run(function(){
return renderer.root === that ?
// finalize render...
renderer.finalize(this)
: this }) },
// Events... // Events...