Clojure:带有Enlive的模板

时间:2013-09-17 22:21:35

标签: clojure enlive

我从https://github.com/cgrand/enlive复制了一个非常基本的样本,但它没有编译:

(ns web.handler
  (:require
    [compojure.core :refer :all]
    [compojure.handler]
    [compojure.route :as route]
    [net.cgrand.enlive-html :as html]))

;; Compiler throws in the next line, see the message below.
(html/deftemplate main-template "templates/index.html"
  []
  [:head :title] (html/content "Enlive starter kit"))

(defroutes app-routes
  (GET "/" [] "Hello")
  (GET "/ping/:what" [what] (str "<h1>Ping '" what "'</h1>"))
  (route/resources "/")
  (route/not-found "Not Found"))

(def app
  (compojure.handler/site app-routes))

我得到错误:

java.lang.NullPointerException, compiling:(handler.clj:9:1)

我用命令运行:

lein ring server-headless

如何让它发挥作用?

修改

到目前为止我的调查:enlive-html.clj:54错误抛出:

(defn tagsoup-parser 
 "Loads and parse an HTML resource and closes the stream."
 [stream]
  (filter map?
    (with-open [^java.io.Closeable stream stream]
      (xml/parse (org.xml.sax.InputSource. stream) startparse-tagsoup)))) ; #54 

可能未引用org.xml.sax?如何使用lein

执行此操作

1 个答案:

答案 0 :(得分:2)

当找不到模板文件时,通常会发生该错误。使用templates/index.html,它会查看resources/templates目录或src/templates目录。