git.fiddlerwoaroof.com
Raw Blame History
(ns app.route
  (:require [clojure.string]
            [javelin.core :as j]
            [hoplon.core :as h]
            [cuerdas.core]
            [cemerick.url]
            [secretary.core]))

(def r (h/route-cell))

(def path
  (j/cell= (-> r
               (cuerdas.core/strip-prefix "#")
               (cuerdas.core/strip-prefix "/")
               (#(str "/" %))
               (#(do (print "The url is: " %)
                     %)))))


(defn generate-route
  ([path] (generate-route path nil))
  ([path query]
   {:pre [(sequential? path) (or (nil? query) (map? query))]}
   (str "#/"
        (clojure.string/join "/" path)
        (if query
          (str "?"
               (cemerick.url/map->query query))))))

(defn set-route!
  "Set the URL hash to work fo the given route."
  ([route]
   (if (string? route)
     (set! (.-hash (.-location js/window))
           route)
     (set-route! (generate-route route))))
  ([path query]
   (set-route! (generate-route path query))))