Description
Sorry for haven't checked this earlier, but after using the 1.5.0 version I noticed that the render
API might need one more simplification.
Background: I have a boolean variable that controls whether the output should be flat or indented.
Creating a String is as simple as this:
String text = minify ? html.render() : html.renderFormatted();
However, I want to render the HTML into a file without creating a String, and unless I missed something the new API requires doing this:
html.render(minify ? FlatHtml.into(out) : IndentedHtml.into(out));
and if there's also a Config
instance involved, it's even more verbose:
Config config = ...
html.render(minify ? FlatHtml.into(out, config) : IndentedHtml.into(out, config));
I wonder if we could introduce some kind of factory that would allow writing this:
html.render(minify ? flatHtml() : indentedHtml(), out, config);
The simplest version I can think of could be something like:
BiFunction<Appendable, Config, HtmlBuilder> flatHtml() {
return (out, config) -> FlatHtml.into(out, config);
}
and
void render(BiFunction<Appendable, Config, HtmlBuilder> factory, Appendable appendable, Config config) {
render(factory.apply(appendable, config));
}
but that's probably not very user/developer friendly, as this BiFunction
doesn't not provide any help what value to pass here. Perhaps an explicit HtmlBuilderFactory
would be clearer.
What do you think, @sembler ?