redding/deas-erubis — pull request #6 by kellyredding (2014-12-23 13:51:12+00:00)
Title: More options for template caching

This updates the source to provide more caching options. The goal
here is to provide options to be as efficient in rendering as possible.
With the previous implementation there were limitations:

* there was no way to turn off caching (`load_file` was always used)
* every render call not only looked up the cache file path but checked
to make sure its parent dir existed and created it if it did not.

Having that extra logic on each render call is really expensive. Maybe,
in a production setting, you are ok with the default `load_file` behavior
of caching templates alongside the source files but in dev mode you
want to cache to a root that isn't under version control (b/c you
don't want to check in cached templates). These changes can support
that workflow:

```ruby
Deas::TemplateSource.new(path.to_s).tap do |s|
s.engine('erb', Deas::Erubis::TemplateEngine, {
'cache' => production? ? true : root.join('/tmp/view_handlers')
})
end
```

Plus these changes can support a workflow that says "cache in production
but not in development":

```ruby
Deas::TemplateSource.new(path.to_s).tap do |s|
s.engine('erb', Deas::Erubis::TemplateEngine, {
'cache' => production?
})
end
```

Overall, this gives the user more options about caching so that they
can optimize the settings for their environment.

To accomplish this in the most efficient manner and to avoid doing
a bunch of conditional logic on each render call, the source defines
a not implemented `eruby` method that gets overridden per instance
on init. This is done by defining an `eruby` method on the metaclass
and doing the conditional logic once on init to determine what the
meta-method's logic will be.