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,59 +3110,91 @@ 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...
;(e instanceof BaseBrowser || e.children instanceof BaseBrowser)
&& children(false)
// do not go down child browsers -- use their mechanics for rendering... return (
;(e instanceof BaseBrowser || e.children instanceof BaseBrowser) // inlined...
&& children(false) e instanceof BaseBrowser ?
renderer.inline(e.render2(options, renderer))
: e instanceof Array ?
renderer.inline(children(true))
return ( // nested...
// inlined... : e.children instanceof BaseBrowser ?
e instanceof BaseBrowser ? renderer.nest(e,
inline(e.render2(options, renderer, context)) // NOTE: we handle .collapsed here as the nested
: e instanceof Array ? // browser is one level down and knows nothing
inline(children(true)) // of it...
(options.iterateCollapsed || !e.collapsed)
&& e.children.render2(options, renderer))
: e.children instanceof Array ?
renderer.nest(e, children(true))
// nested... // normal item...
: e.children instanceof BaseBrowser ? : renderer.elem(e) )
nest(elem(e), }, options)
// NOTE: we handle .collapsed here as the nested .run(function(){
// browser is one level down and knows nothing return renderer.root === that ?
// of it... // finalize render...
(options.iterateCollapsed || !e.collapsed) renderer.finalize(this)
&& e.children.render2(options, renderer, context)) : this }) },
: e.children instanceof Array ?
nest(elem(e), children(true))
// normal item...
: elem(e) )
}, options)
},
// Events... // Events...