• Clojure
  • 36 lines
  • Private
  • Pasted by anonymous on August 15, 2013
;; Mustache templates used, required "main" templates like "admin" to contain a {{{capsule}}} element for injected content.

(defmacro TGET [route & body] `(GET ~route [] (render-file (str "templates" ~route) ~@body)))
(defn routes-by-convention [pages] (apply routes (map #(TGET % {}) pages)))

(defroutes admin-routes
     (GET "/" [] (render-file "templates/verySpecial/notCoveredByConvention"  {}))
     (routes-by-convention '("/charts" "/credit" "/customer" "/reporting" "/bi" "/dashboard"))
     ) "templates/admin"))
   (POST "/deployment/upload" {params :multipart-params}
         (do (repository_upload (get params "file")) {:status 200 :body ""}))
   (GET "/deployment/list" [] (u/jresp (repository_list)))))

;; Utilities ;;

(def development? (= "development" (get (System/getenv) "APP_ENV")))

(defn atmpl [content template & params]
  (do (if development? (unregister-all-templates))
      (render-file template (merge (into {} params) {:capsule content})))) 

;; Ring middleware
(defn wrap-template [handler template]
  (fn [request]
    (if-let [response (handler request)]
      (update-in response [:body] atmpl template request))))

(defn wrap-utf8 [handler]
  (fn [request]
    (if-let [response (handler request)]
      (content-type response "text/html;charset=UTF-8"))))

Did you know? CLOSE

  • There are keyboard shortcuts!
    • When Creating A Paste
      • ALT+P Toggle Private
      • CTRL+Enter Create Paste
      • ALT+W Toggle word wrap
    • When Viewing A Paste
      • ALT+G Go to a line
      • ALT+CTRL+E Edit the paste
      • ALT+R Show the raw code
  • There are URL options!
    • When Creating A Paste
      • ?lang=Javascript to default to javascript
    • When Viewing A Paste
      • #L-N Jump to line number N