I was hoping that Enlive Issue #6: Auto-reloading of templates was solved in early December 2013 in version 1.1.5 by this commit. But, in my testing, I cannot confirm that it is a fix. I might be doing something wrong.
A note: the example you cite, I think, dates from the pre-0.2.0 tooling changes for Pedestal. I could be wrong, but I think you'd be better off following the current documentation, not that sample file.
Pedestal's 'hello world' service app's key suggestions (which may change) are:
Use ns-tracker to figure out which namespaces to reload.
add :resource-paths ["config", "resources"]
to project.clj
so that Enlive can find your static HTML resources.
These steps are not enough to cause a change to a resource to trigger a reload, because ns-tracker will not pay attention to :resource-paths
. Here are the details:
- ns-tracker relies on clojure.tools.namespace.find/find-clojure-sources-in-dir.
- clojure.tools.namespace.find/find-clojure-sources-in-dir
When you think about it, you can see why ns-tracker doesn't pick up resources; they aren't Clojure namespaces. In my opinion, this is coherent design decision, given the name, ns-tracker
.
Still, pragmatically, it is clear that from the point of view of Pedestal that we do want to reload when a resource changes.
Now, let me add another thing. From a tooling perspective, let's say you do setup a watch on the resources directory. Even so, it is not easy to identify, in a granular fashion, which specific Clojure namespaces will be impacted. One resource may be used as a defsnippet
by multiple deftemplate
's. Therefore, one resource change can affect multiple Clojure namespaces. Strings pointing to resources might even be constructed dynamically. So, figuring out the exact minimal set of namespaces to reload may be impossible in the general case.
All of this said, it should be 'easy' and safe enough to reload all Clojure namespaces whenever a resource changes.
So, in summary, I have not solved this problem myself, but hopefully what I've explained above will help move the ball forward.