Clojure 克洛朱尔:为什么斯奈普泰斯特生产懒猴
我正在用enlive创建一个模板,但这个代码段产生了lazyseq,这让我很头疼。当我在REPL中尝试这个sniptest时,它会生成“clojure.lang”。LazySeq@ba6da9f2". 测试这一点所需的其余代码如下所示Clojure 克洛朱尔:为什么斯奈普泰斯特生产懒猴,clojure,lazy-sequences,enlive,Clojure,Lazy Sequences,Enlive,我正在用enlive创建一个模板,但这个代码段产生了lazyseq,这让我很头疼。当我在REPL中尝试这个sniptest时,它会生成“clojure.lang”。LazySeq@ba6da9f2". 测试这一点所需的其余代码如下所示 (require '[net.cgrand.enlive-html :as h]) (def msh-contents {:title "Events mashup", :data-content [
(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))
index.html文件如下所示(也可以在此处找到))
这是一张桌子
标题1
第1行第1列
我看到了一个类似的问题,但解决方案是使用内容而不是html内容。不确定是什么原因导致此问题…示例来自
PS:你用sniptest做什么,因为我直到现在都不知道它的存在。然后我又以一种奇怪的方式使用了enlive(没有defmetlates或defsnippets,使用hiccup样式的html,大量使用宏)。不正确的缩进确实会让人失去动力。@A.Webb我更改了缩进,对此表示歉意。我用它来尝试一个片段,因为我的defmetlate不起作用,因为片段产生了LazySeq。这确实有效,但我的deftemplate仍然无效:(如果你有时间,你可以在这里看到问题
(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))
<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>
x=> (sniptest "<html><body><span>Hello </span>"
[:span] (append "World"))
"<html><body><span>Hello World</span></body></html>"
(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)))))