Skip to content

Extend 'LeafRenderer' so that it can render 'Encodable' contexts

Choose a tag to compare

@tanner0101 tanner0101 released this 02 Mar 01:16
9e86828
This patch was authored by @glbrntt and released by @0xTim.

Out of the box, the LeafRenderer offers a base API which can render
Leaf templates to a ByteBuffer. This requires the context to be provided
as a dictionary. With ViewRenderer conformance the LeafRenderer can
render View's using an Encodable context.

However, there's no middle ground: the LeafRenderer can't render
templates to a ByteBuffer using an Encodable context. Since
LeafEncoder is internal users can't make the extra hop from Encodable
context to dictionary to use the base API either. This functionality is helpful
when Leaf is used to render documents which aren't HTML.

As such this change adds an extension to LeafRenderer to render a
template to serialized bytes using an Encodable context.