convert hard-coded web root resource path to a configurable option

This commit is contained in:
Gered 2014-06-19 17:38:56 -04:00
parent b1a605e758
commit ee08d7e94d
2 changed files with 8 additions and 7 deletions

View file

@ -36,4 +36,9 @@
; having to do any manual conversions yourself and to keep your Clojure code as idiomatic
; as possible. Jtwig model-maps at the very least do require all the keys to be strings
; (not keywords) to ensure that model-map value resolution works as expected.
:auto-convert-map-keywords true}))
:auto-convert-map-keywords true
; the root path (relative to the classpath) where web resources such as js, css, images are
; located. typically in your project structure this path will be located under the
; "resources" directory.
:web-resource-path-root "public"}))

View file

@ -9,10 +9,6 @@
[clj-jtwig.utils]
[clj-jtwig.options]))
;; TODO: while 'public' is the default with Compojure, applications can override with something else ...
;; should make this customizable (some option added to clj-jtwig.options likely ...)
(def root-resource-path "public")
(defn- get-context-url [url]
(str *servlet-context-path* url))
@ -24,7 +20,7 @@
(defn- get-resource-modification-timestamp [^String resource-url]
(if (relative-url? resource-url)
(->> (str root-resource-path resource-url)
(->> (str (:web-resource-path-root @options) resource-url)
(get-context-url)
(get-resource-modification-date))))
@ -52,7 +48,7 @@
(minified-url? url))
url
(let [minified-url (make-minified-url url)]
(if (get-resource-path (str root-resource-path minified-url))
(if (get-resource-path (str (:web-resource-path-root @options) minified-url))
minified-url
url))))