0

我在 enlive 中创建了一个模板,并且在使用这个产生lazyseq 的片段时遇到了问题。当我在 REPL 中尝试这个 sniptest 时,它会产生“clojure.lang.LazySeq@ba6da9f2”。

    (h/sniptest (template-div) 
     [:div.Row]  (h/content (map #(value-cell %) 
     (for [e(:data-content msh-contents)] 
      (vals e)))))

测试它所需的其余代码如下所示

    (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 文件看起来像这样(也可以在这里找到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>

我看到了一个类似的问题,但解决方案是使用内容而不是 html-content。不知道是什么导致了这里的问题......

4

1 回答 1

1

来自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>"

html-resource文档字符串:"Loads an HTML resource, returns a seq of nodes."

请注意示例中的源代码是 html 字符串的形式,而不是seq of nodes. 为什么它的工作方式击败了我,但您可能需要以下内容:

(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:您使用 sniptest 做什么,因为我直到现在才知道它存在。然后我再次以一种奇怪的方式使用 enlive(没有 deftemplates 或 defsnippets,使用打嗝式 html,以及大量使用宏)。

于 2014-07-13T21:05:06.453 回答