dhanji/sitebricks — pull request #28 by fuzzygroove (2012-05-01 02:46:39+00:00)
Title: Really Pluggable Templates

I started on pluggable templates months ago but never finished the last legs of work. I pulled in the latest from trunk so I could make use of the latest effort put in to support configurable template compilers, but there was a little more work that had to be done.

It was about 90% of the way there, but a few places had file extensions hard coded, and there was no easy way to add custom compilers from outside the Sitebricks codebase.

You can now add custom template compilers by overriding the `SiteBricks.configureTemplateCompilers` method:

public class MySitebricksModule extends SitebricksModule {
...
@Override
protected void configureTemplateCompilers(MapBinder compilers) {
compilers.addBinding("mustache").to(MustacheTemplateCompiler.class);
compilers.addBinding("mu").to(MustacheTemplateCompiler.class);
}
}

(You can also simply add them to the MapBinder directly with:

MapBinder templateCompilers = MapBinder.newMapBinder(binder(), String.class, TemplateCompiler.class);
templateCompilers.addBinding("mustache").to(MustacheTemplateCompiler.class);
templateCompilers.addBinding("mu").to(MustacheTemplateCompiler.class);

I also cleaned up the `TemplateLoader` class to be easier to follow, the original logic was a bit convoluted and tough to figure in terms of behavior when building project with Sitebricks. It also now short-circuits the deep search if a file extension is specified in the Show annotation (e.g. `@Show(template.html)`).

I updated the pom.atom files to use the lates 8.7-SNAPSHOT, which just looked like some housekeeping that got missed.

Let me know if there's anything in here you'd like me to update.