【问题标题】:Clojure: Template with EnliveClojure:带有 Enlive 的模板
【发布时间】:2013-09-18 06:36:48
【问题描述】:

我从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 做到这一点?

【问题讨论】:

    标签: clojure enlive


    【解决方案1】:

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

    【讨论】:

    • 原来是templates,移动到src/tampletes,工作正常! resources/templates 也可以。谢谢!
    • 当我简要浏览代码时,它下沉到@98​​7654327@。我不熟悉 Java 基础架构,但这就是 resources/src/ 路径的来源?
    • 当您指定一个字符串路径时,Enlive 使用内置的 java 资源方法。这将搜索当前类加载器的类路径,这是由 Leiningen 使用您的项目配置和默认配置设置的。如果需要其他路径,可以添加到你的project.clj中,也可以自己打开,给deftemplate传一个InputStream。
    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    相关资源
    最近更新 更多