Question

I'm trying to add the following Hiccup template function to my file

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

but keep getting an unmatched delimiter when I run lein ring server. This comes from Clojure Data Cookbook, so I am surprised to find an error and suspect the error is just on my end. Below is the rest of the code in the file:

(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)))
Was it helpful?

Solution

In line 5

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

There's an extra ) there.

And in line 13,

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

There's one ) missing. Should be

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

You should use an editor which can do the matching of braces, parentheses, and brackets, etc. automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top