Auto-reloading enlive templates?

263 views
Skip to first unread message

Bastien

unread,
Nov 26, 2013, 5:30:38 AM11/26/13
to enliv...@googlegroups.com
Hi all,

I've read this thread about auto-reloading enlive templates
https://github.com/cgrand/enlive/issues/6

but (like others) I'm not sure how to use it.

I have a directory with these two files:

,----
| html/index.html
| html/templates.clj
`----

and my templates.clj file looks like this:

,----
| (ns net111213.html.templates
| (:require
| [net.cgrand.enlive-html :as html]
| [net.cgrand.reload :as reload]))
|
| (html/deftemplate index-tpl "net111213/html/index.html" [])
|
| (reload/auto-reload *ns*)
`----

Modifications in index.html don't trigger templates.clj to be
reloaded.

Any hint?

Thanks in advance!

--
Bastien

Christophe Grand

unread,
Nov 26, 2013, 5:50:12 AM11/26/13
to enlive-clj
Ok, sorry for the abysmal latency, I'm gpoing to investigate this: which OS/JVM?



--
You received this message because you are subscribed to the Google Groups "Enlive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enlive-clj+...@googlegroups.com.
To post to this group, send email to enliv...@googlegroups.com.
Visit this group at http://groups.google.com/group/enlive-clj.
For more options, visit https://groups.google.com/groups/opt_out.



--
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/

Bastien

unread,
Nov 26, 2013, 5:53:41 AM11/26/13
to Christophe Grand, enlive-clj
Christophe Grand <chris...@cgrand.net> writes:

> Ok, sorry for the abysmal latency, I'm gpoing to investigate this:
> which OS/JVM?

This is within a project where I use Immutant (installed Debian 7).

https://github.com/bzg/kickhub/

and the files:
https://github.com/bzg/kickhub/blob/master/src/kickhub/html/index.html
https://github.com/bzg/kickhub/blob/master/src/kickhub/html/templates.clj

I regularily pull commits using a cron job on the machine,
and I'd like to see the website correctly updated whenever
those commits are pulled and merged.

Thanks a lot!

--
Bastien

Christophe Grand

unread,
Nov 26, 2013, 6:10:07 AM11/26/13
to enlive-clj
Ok, could you give me the URL returned by (.getResource (clojure.lang.RT/baseLoader) "kickhub/html/index.html") (from within your deployment) ?



--
 Bastien

--
You received this message because you are subscribed to the Google Groups "Enlive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enlive-clj+...@googlegroups.com.
To post to this group, send email to enliv...@googlegroups.com.
Visit this group at http://groups.google.com/group/enlive-clj.
For more options, visit https://groups.google.com/groups/opt_out.

Bastien

unread,
Nov 26, 2013, 6:26:31 AM11/26/13
to Christophe Grand, enlive-clj
Christophe Grand <chris...@cgrand.net> writes:

> Ok, could you give me the URL returned by (.getResource
> (clojure.lang.RT/baseLoader) "kickhub/html/index.html") (from within your
> deployment) ?

#<URL file:/home/guerry/install/git/boulot/kickhub/src/kickhub/html/index.html>

(This is from within my local immutant instance, not the one accessible
through kickhub.com.)

--
Bastien

Christophe Grand

unread,
Dec 2, 2013, 11:54:02 AM12/2/13
to enlive-clj
Ok I published Enlive 1.1.5 which hopefully fixes the auto-reload issue.
Tell me if it works for you.

Christophe



--
 Bastien

--
You received this message because you are subscribed to the Google Groups "Enlive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enlive-clj+...@googlegroups.com.
To post to this group, send email to enliv...@googlegroups.com.
Visit this group at http://groups.google.com/group/enlive-clj.
For more options, visit https://groups.google.com/groups/opt_out.

Bastien

unread,
Dec 2, 2013, 4:27:19 PM12/2/13
to Christophe Grand, enlive-clj
Christophe Grand <chris...@cgrand.net> writes:

> Ok I published Enlive 1.1.5 which hopefully fixes the auto-reload
> issue.
> Tell me if it works for you.

Thanks. I just tested it but it does not work for me. Remember I'm
using Immutant, not sure if it makes a difference (and don't see why
it should.)

The first time I modify a .html file, immutant stdout says:

22:20:34,663 INFO [stdout] (clojure-agent-send-off-pool-4) Reloading kickhub.html.templates

which sounds good -- bot no change have been taking into account.
If I modify a .html file again, no message is sent.

And this time:

(.getResource (clojure.lang.RT/baseLoader) "kickhub/html/index.html")

is `nil`.

Let me know if I can give more information to help you debug this!

--
Bastien

Christophe Grand

unread,
Dec 3, 2013, 4:44:35 AM12/3/13
to enlive-clj
On Mon, Dec 2, 2013 at 10:27 PM, Bastien <bastie...@gmail.com> wrote:
Thanks.  I just tested it but it does not work for me.

grmf..
 
The first time I modify a .html file, immutant stdout says:

  22:20:34,663 INFO  [stdout] (clojure-agent-send-off-pool-4) Reloading kickhub.html.templates

which sounds good -- bot no change have been taking into account.

I would tend to believe that the reloading failed, no exception in logs?
 
If I modify a .html file again, no message is sent.

If there is an exception during require then auto-reload is not sscheduled again.
 
And this time:

(.getResource (clojure.lang.RT/baseLoader) "kickhub/html/index.html"

is `nil`.

What did change since last time?

This is key to your problem: if it is nil then it's the exception cause.

Christophe

Bastien

unread,
Dec 3, 2013, 10:35:28 AM12/3/13
to Christophe Grand, enlive-clj
Christophe Grand <chris...@cgrand.net> writes:

> On Mon, Dec 2, 2013 at 10:27 PM, Bastien <bastie...@gmail.com>
> wrote:
>
> Thanks. �I just tested it but it does not work for me.
>
> grmf..

Well, I retested and it works well when

1. (reload/auto-reload *ns*) is right after the (ns ...) form

2. I update a .html template from within an Emacs with a nrepl
connection.

I'm not sure why (1) is needed, just mentioning it here in case.

The other use-case I'm interested in is when I'm on a server where a
git pull write a new version of a .html template. In this case, the
templates are not reloaded and a ~$ touch [src]/index.html does not
work either, but given (2) I guess this is expected. I probably
should use a git hook or something similar.

Thanks for your patience!

--
Bastien

Christophe Grand

unread,
Dec 4, 2013, 4:27:55 AM12/4/13
to enlive-clj
On Tue, Dec 3, 2013 at 4:35 PM, Bastien <bastie...@gmail.com> wrote:
Well, I retested and it works well when

Is this a conjunction or a disjunction?
 
1. (reload/auto-reload *ns*) is right after the (ns ...) form

I suspect that by registerinig it first for auto-reload it prevents auto-reloading behaviour to get discraded by an exception.
How many times do you get "Reloading kickhub.html.templates" when you modify a html file?
 
2. I update a .html template from within an Emacs with a nrepl
   connection.

huh? Could you explain a bit more your setup? If you just ssh into the box and modify (touch) the file, does it trigger a reload?
 
The other use-case I'm interested in is when I'm on a server where a
git pull write a new version of a .html template.  In this case, the
templates are not reloaded and a ~$ touch [src]/index.html does not
work either, but given (2) I guess this is expeected.  I probably

should use a git hook or something similar.

The watch mechanism is tied to the parent folder of the template through its inode, not its path so it may explain why you don't get reloads after git pull (if you could confirm with ls -i it would be nice).

Bastien

unread,
Dec 6, 2013, 5:34:11 AM12/6/13
to Christophe Grand, enlive-clj
Sorry for the delay.

Christophe Grand <chris...@cgrand.net> writes:

> On Tue, Dec 3, 2013 at 4:35 PM, Bastien <bastie...@gmail.com>
> wrote:
>
> Well, I retested and it works well when
>
>
> Is this a conjunction or a disjunction?

Conjunction.

> 1. (reload/auto-reload *ns*) is right after the (ns ...) form
>
>
> I suspect that by registerinig it first for auto-reload it prevents
> auto-reloading behaviour to get discraded by an exception.
> How many times do you get "Reloading kickhub.html.templates" when you
> modify a html file?

When (reload/auto-reload *ns*) is at the end of the file, I get this
message once, the change in the .html is reflected okay, but further
changes are not.

When (reload/auto-reload *ns*) is right after the (ns ...) form I
never get this message but all changes in .html are reflected okay.

> 2. I update a .html template from within an Emacs with a nrepl
> � �connection.
>
> huh? Could you explain a bit more your setup?

I use immutant. My init.clj in immutant is basic:

(ns immutant.init
(:use kickhub.core)
(:require [immutant.web :as web]))

(web/start #'ring-handler)

and my #'ring-handler nothing very fancy:

(def ring-handler
(middleware/app-handler
[(wrap-friend-github (wrap-friend app-routes))]))

Then I start immutant with

~$ lein immutant run

and get all those messages.

From there, touching .html files does not trigger any change.

My defproject form contains:

:immutant {:context-path "/" :nrepl-port 4005}

which allows me to connect to the immutant instant through Emacs.
I start M-x cider RET within my project.clj file (or any other .clj
file of the project), load the templates.clj file with C-c C-l (the
cider function to load the code in the buffer).

Then, if I edit a .html buffer and save it, the changes are reflected
in localhost:8080

> If you just ssh into
> the box and modify (touch) the file, does it trigger a reload?

Nope.

> The other use-case I'm interested in is when I'm on a server
> where a
> git pull write a new version of a .html template. �In this case,
> the
> templates are not reloaded and a ~$ touch [src]/index.html does
> not
> work either, but given (2) I guess this is expeected. �I probably
> should use a git hook or something similar.
>
>
> The watch mechanism is tied to the parent folder of the template
> through its inode, not its path so it may explain why you don't get
> reloads after git pull (if you could confirm with ls -i it would be
> nice).

I'm not sure what to test here.

I hope the explanations above make sense, and that someone else can
confirm how the auto-reloading works for him from immutant!

Thanks,

--
Bastien
Reply all
Reply to author
Forward
0 new messages