Reputation: 345
I'm creating a template in enlive and having trouble with this snippet which produces lazyseq. When I try this sniptest in REPL it produces "clojure.lang.LazySeq@ba6da9f2".
(h/sniptest (template-div)
[:div.Row] (h/content (map #(value-cell %)
(for [e(:data-content msh-contents)]
(vals e)))))
The rest of the code needed to test this looks like this
(require '[net.cgrand.enlive-html :as h])
(def msh-contents {:title "Events mashup",
:data-content [{:title "ICTM Study Group ",
:url "http://some-url.com"}
{:title "Volodja Balzalorsky - Hinko Haas",
:url "http://some- other-url.com"}
]})
(defn template-div[] (h/html-resource "index.html"))
(h/defsnippet value-cell (template-div)
[:div.Row :div.Cell] [value]
(h/content value))
The index.html file looks something like this (it can also be found here http://www.filedropper.com/index_25))
<div class="Table">
<div class="Title">
<p>This is a Table</p>
</div>
<div class="Heading">
<div class="Cell">
<p>Heading 1</p>
</div>
</div>
<div class="Row">
<div class="Cell">
<p>Row 1 Column 1</p>
</div>
</div>
I saw a similar question, but the solution was to use content instead of html-content. Not sure what causes the issue here...
Upvotes: 0
Views: 90
Reputation: 5217
Example from https://github.com/cgrand/enlive/wiki/Getting-started
x=> (sniptest "<html><body><span>Hello </span>"
[:span] (append "World"))
"<html><body><span>Hello World</span></body></html>"
From html-resource
docstring: "Loads an HTML resource, returns a seq of nodes."
Notice how in the example the source is in the form of a html string and not a seq of nodes
. Why it works the way it does beats me but you'll probably want the following:
(h/sniptest (clojure.string/join (h/emit* (template-div))) ; this feeds it a html str instead
[:div.Row] (h/content (map #(value-cell %)
(for [e(:data-content msh-contents)]
(vals e)))))
PS: What are you using sniptest for because I was unaware it existed until now. Then again I use enlive in an odd way(no deftemplates or defsnippets, use of hiccup style html, and heavy use of macros).
Upvotes: 1