redding/sanford — pull request #135 by jcredding (2014-06-26 13:33:04+00:00)
Title: Add `render` to `TemplateSource`, decouple from `ServiceHandler`

This adjusts the template rendering behavior to decouple service
handlers and a template source. `TemplateSource` now provides a
`render` method which is all the service handler needs to call to
render a template. The `TemplateSource` takes care of finding the
templates and finding a matching configured engine and calling
`render` on it. This keeps service handlers from having to know
how to lookup engines and centralizes all the file extension
handling.

This also tweaks the template lookup slightly. Sources will now
reject templates for which they do not have a configured engine
for. This covers ensuring we do not select a `.rb` template
(since we don't allow engines to be configured for this extension)
and avoids a really minor issue with trying to render a template
when there are two or more files with the same name but different
extensions. If you try to render "template" and you have a
"template.erb" and a "template.json" file in your source path,
then the previous logic would always choose the erb file. If the
source was configured to work with json but not erb you can't
render your json template. Only selecting templates that are
configured helps to pick the correct template in this rare
situation.

@kellyredding - Ready for review. Ran into this while working on the unit tests for the service handler. I was trying to test its `render` method and I was having to do all the setup of creating a source and an engine and make sure everything lined up. I also ran into the issue of it not rendering my `template.json` because it would always choose `template.erb`. I started adding the logic to the service handler and thought it shouldn't have to know so much about the template source structure.