2
訪問本地主機:3001 /測試結果在下面的HTML:Enlive片斷產生懶惰序列
<html>
<head>
</head>
<body>[email protected]</body>
</html>
的Clojure代碼:
(ns notebook.handler
(:require [compojure.core :refer :all]
[compojure.handler :as handler]
[compojure.route :as route]
[net.cgrand.enlive-html :as html]))
(html/defsnippet welcome
(html/html [:h1]) ; html snippet
[:h1] ; selector
[username] ; arguments
[:h1] (html/content username)) ; substitution
(html/deftemplate home-page "templates/base.html"
[username]
[:body] (html/html-content (welcome username)))
(defroutes app-routes
(GET "/test" [] (home-page "oru"))
(route/resources "/")
(route/not-found "Not Found"))
(def app
(handler/site app-routes))
它看起來像我沒有使用模板和正確或者在某個地方搞怠惰。我已經試過在幾個地方放置doall
,希望它能解決懶惰但沒有骰子。
調試嘗試:
(welcome "oru")
=> ({:tag :h1, :attrs {}, :content ("oru")})
(html/emit* (welcome "oru"))
=> ("<" "h1" ">" "oru" "</" "h1" ">")
到目前爲止好...
(home-page "oru")
=> ("<" "html" ">" "\n " "<" "head" ">" "\n " "</" "head" ">" "\n " "<" "body" ">" "[email protected]" "</" "body" ">" "\n\n" "</" "html" ">")
巴姆! "[email protected]"
,這是幹什麼的?