davidsantiago/stencil — Issue #6: Supporting template files outside of the classpath
Author: mefesto
Created: 2012-03-09 21:41:09+00:00
State: open

I noticed that `stencil.core/render-file` only works with templates on the classpath. Is there a design decision why this is the case? If not, I'd like to request that this function load and cache any file whether or not they are on the classpath.

Currently, I can slurp the file and use `render-string` but then I lose out on the caching that `render-file` provides. This is really the only reason I'm bringing this up. It'd be cool if we could plug-in on the type of the templates and they can make use of the existing caching capability. A nice cache strategy for `File` would be if the modified timestamp of the file has changed since being cached.

Just a thought but perhaps `stencil.loader/find-file` could continue to treat `template-name` as a resource if it's a `String` but if its a `File` use the file's url instead.

```clojure
(require '[clojure.java.io :as io])

(defmulti find-file type)

(defmethod find-file String [template-name]
(if-let [file-url (resource (str template-name ".mustache"))]
file-url
(if-let [file-url (resource template-name)]
file-url)))

(defmethod find-file java.io.File [template-name]
(let [file (io/file (str template-name ".mustache"))]
(if (and (.exists file) (.isFile file))
(.. file toURI toURL)
(let [file (io/file template-name)]
(if (and (.exists file) (.isFile file))
(.. file toURI toURL))))))
```

If this or something like it is acceptable to you I'd be happy to put a patch together.

Thanks.