seethrough 0.1: sub-templates, and cache-ready
Posted February 13th, 2007 by bard
Uh oh. Beware when you take an evening’s hack and put it online, as someone who knows what he’s doing might come along and turn it into something useful.
That happened to seethrough, with a patch courtesy of Joel, who added two major features:
- sub-template inclusion, via the
<e:include/>tag; - parse/render stage split.
The latter means that the (possibly expensive) parse and preparation stage only needs to be performed once. The resulting intermediate form can be cached, and rendered many times within different environments. For example:
%% Parsing
{XMLTree, _Misc} = xmerl_scan:file(File),
Intermediate = seethrough:visit(XMLTree),
%% Rendering intermediate form within Env1
Render1 = seethrough:render(Intermediate, Env1),
xmerl:export_simple(lists:flatten([Render1]), xmerl_xml,
[#xmlAttribute{name = prolog, value = ""}]).
%% More rendering, but within Env2
Render2 = seethrough:render(Intermediate, Env2),
xmerl:export_simple(lists:flatten([Render2]), xmerl_xml,
[#xmlAttribute{name = prolog, value = ""}]).
%% Yet more rendering, within Env3
Render3 = seethrough:render(Intermediate, Env3),
xmerl:export_simple(lists:flatten([Render3]), xmerl_xml,
[#xmlAttribute{name = prolog, value = ""}]).
Kudos to Joel!
Post new comment