【问题标题】:Hiccup template function打嗝模板功能
【发布时间】:2014-05-18 19:39:09
【问题描述】:

我正在尝试将以下 Hiccup 模板函数添加到我的文件中

(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)))

【问题讨论】:

    标签: clojure compojure ring


    【解决方案1】:

    在第 5 行

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

    那里多了一个)

    在第 13 行,

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

    缺少一个)。应该是

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 2023-04-05
      • 2011-11-05
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      相关资源
      最近更新 更多