3
votes

I am using the autoreload-server example which is working great for reloading namespaces on changes to the .clj files using ns-tracker.

https://github.com/pedestal/samples/blob/master/auto-reload-server/dev/dev.clj

However, it is not picking up changes to enlive templates in the resources/public dir. I've added my template paths to the vector in defn watch:

`([] (watch ["src" "resources" "resources/public" "public"]))`

As well as this in the namespaces that use enlive deftemplate:

(net.cgrand.reload/auto-reload *ns*)

However this does not work. My assumption is ns-tracker only works for clj files, and that I am using the enlive reload feature incorrectly.

Is anyone using enlive and have this figured out, or have any ideas to try?

2
I am also facing this problem. It makes you crazy, doesn't it? I'm about to dig into the code and see.David J.

2 Answers

0
votes

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:

  1. Use ns-tracker to figure out which namespaces to reload.

  2. 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:

  1. ns-tracker relies on clojure.tools.namespace.find/find-clojure-sources-in-dir.
  2. 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.


0
votes

I could not find a working solution off the shelf, so I ended up writing a small ring wrapper that does the job, see https://github.com/kolov/enlive-reload