dhanji/sitebricks — pull request #29 by fuzzygroove (2012-05-02 02:06:04+00:00)
Title: Really Pluggable Templates

I pulled in the latest from trunk so I could make use of the new configurable template compiler support, 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);
}
}

Or, you can bind them anywhere in your modules by adding to the existing Guice MapBinder:

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 it wasn't very intuitive to know what was happening for the different cases (@Show() vs @Show(template) vs @Show(template.html), etc). I reworked it so that it short-circuits the deep search if a file extension is specified in the Show annotation (e.g. `@Show(template.html)`), and it looks for all possibilities in one resource path before moving on to the next.

I also 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.