Module tf.advanced.render

Render

Rendering is the process of generating HTML for a node, taking into account display options (tf.advanced.options) and app settings (tf.advanced.settings).

It is organized as an unravel step (tf.advanced.unravel), that generates a tree of node fragments followed by an HTML generating step, that generates HTML for a tree in a recursive way.

The unravel step retrieves all relevant settings and options and stores them in the tree in such a way that the essential information for rendering a subtree is readily available at the top of that subtree.

Information shielding

The recursive render step does not have to consult the app object anymore, because all information it needs from the app object is stored in the tree, and all methods that need to be invoked on the app object are also accessible directly from an attribute in the tree.

Functions

def render(app, isPretty, n, _inTuple, _asString, explain, **options)
Expand source code Browse git
def render(app, isPretty, n, _inTuple, _asString, explain, **options):
    """Renders a node, in plain or pretty mode.

    We take care that when a node has graphics, and the node is split into several
    chunks / fragments, the graphics only occurs on the first fragment.
    """

    graphicsFetched = set()
    inNb = app.inNb
    display = app.display

    if not display.check("pretty" if isPretty else "plain", options):
        return ""

    _browse = app._browse

    dContext = display.distill(options)

    if isPretty:
        tupleFeatures = dContext.tupleFeatures
        extraFeatures = dContext.extraFeatures
        multiFeatures = dContext.multiFeatures
        queryFeatures = dContext.queryFeatures

        dContext.set(
            "features",
            sorted(
                flattenToSet(extraFeatures[0])
                | (flattenToSet(tupleFeatures) if queryFeatures else set())
            ),
        )
        dContext.set("featuresIndirect", extraFeatures[1])
        if multiFeatures:
            api = app.api
            Fall = api.Fall
            Eall = api.Eall
            dContext.set(
                "featuresAll", tuple(Fall(warp=False)) + tuple(Eall(warp=False))
            )

    tree = _unravel(app, isPretty, dContext, n, _inTuple=_inTuple, explain=explain)
    (chunk, info, subTrees) = tree
    settings = info.settings

    passage = _getPassage(isPretty, info, n)

    html = []

    for subTree in subTrees:
        _render(isPretty, subTree, True, True, 0, passage, html, graphicsFetched)

    rep = "".join(html)
    ltr = settings.ltr

    elem = "span" if _inTuple else "div"
    ubd = " ubd" if _inTuple else ""
    kindRep = "pr-mode" if isPretty else "pl-mode"
    result = (
        f"""{passage}<{elem} class="{ltr} children {kindRep}">{rep}</{elem}>"""
        if isPretty
        else f"""<{elem} class="{ltr}{ubd} {kindRep}">{passage}{rep}</{elem}>"""
    )

    if _browse or _asString:
        return result
    dh(result, inNb=inNb)

Renders a node, in plain or pretty mode.

We take care that when a node has graphics, and the node is split into several chunks / fragments, the graphics only occurs on the first fragment.