Clojure:带有Enlive的模板
我从中复制了一个非常基本的示例,但它没有编译:Clojure:带有Enlive的模板,clojure,enlive,Clojure,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/de
(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))
我使用以下命令运行:
lein ring server-headless
如何让它工作
编辑
到目前为止,我的调查是:enlivehtml.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
执行此操作?当找不到模板文件时,通常会发生此错误。使用templates/index.html
,它可以在resources/templates
目录或src/templates
目录中查找。只不过是templates
,移动到src/tampletes
,效果很好<代码>资源/模板也可以使用。非常感谢。当我短暂浏览代码时,它进入ClassLoader.getResourceAsStream
。我不熟悉Java基础架构,但这就是resources/
和src/
路径的来源?当您指定字符串路径时,Enlive使用内置的Java资源方法。这将搜索当前类加载器的类路径(由Leiningen使用项目配置和默认配置设置)。如果需要其他路径,可以将它们添加到project.clj中,也可以自己打开它并向deftemplate传递InputStream。
(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