打嗝模板功能

时间:2014-04-06 17:39:10

标签: clojure compojure ring

我试图将以下打嗝模板功能添加到我的文件

(defn d3-page [title js body & {:keys [extra-js] :or {extra-js []}}]
        (html5
            [:head
                [:title title]
            (include-css "/css/nv.d3.css"))
            (include-css "/css/style.css")]
            [:body
        (concat
            [body]
            [(include-js "http://d3js.org/d3.v3.min.js")
             (include-js (str "https://raw.github.com"
                              "/novus/nvd3"
                              "/master/nv.d3.min.js")]
        (map include-js extra-js)
            [(include-js "/js/script.js")
             (javascript-tag js)])]))

但是当我运行lein ring server时,不断获得无法匹配的分隔符。这来自 Clojure Data Cookbook ,所以我很惊讶地发现了一个错误,并怀疑错误就在我的最后。下面是文件中的其余代码:

(ns web-viz.web
(:require [compojure.route :as route]
      [compojure.handler :as handler]
      [clojure.string :as str])
(:use compojure.core
  ring.adapter.jetty
  [ring.middleware.content-type :only
  (wrap-content-type)]
  [ring.middleware.file :only (wrap-file)]
  [ring.middleware.file-info :only
  (wrap-file-info)]
  [ring.middleware.stacktrace :only
  (wrap-stacktrace)]
  [ring.util.response :only (redirect)]
  [hiccup core element page]
  [hiccup.middleware :only (wrap-base-url)]))

 (defn d3-page...as above
  ...)

 (deftype Group [key values])
 (deftype Point [x y size])

 (defn add-label [chart axis label]
    (if-not (nil? label)
            (.axisLabel (aget chart axis) label)))

 (defn add-axes-labels [chart x-label y-label]
    (doto chart (add-label "xAxis" x-label)
                (add-label "yAxis" y-label)))

(defn populate-node [selector chart groups transition continuation]
    (-> (.select js/d3 selector)
        (.datum groups)
        (.transition)
        (.duration (if transition 500 0))
        (.call chart)
        (.call continuation)))

 (defn force-layout-plot [] 
(d3-page "Force-Directed Layout"
"webviz.force.force_layout();"
[:div#force.chart [:svg]]))

 (defroutes site-routes
(GET "/force" [] (force-layout-plot))
(GET "/force/data.json" []
(redirect "/data/census-race.json"))
(route/resources "/")
(route/not-found "Page not found"))

(def app (-> (handler/site site-routes)))

1 个答案:

答案 0 :(得分:2)

第5行

(include-css "/css/nv.d3.css"))

那里有一个额外的)

在第13行,

"/master/nv.d3.min.js")]

缺少一个)。应该是

"/master/nv.d3.min.js"))]

你应该使用一个编辑器,它可以自动匹配大括号,圆括号和括号等。