From ee08d7e94d0920f0539e27593a2e99673ca13c42 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 19 Jun 2014 17:38:56 -0400 Subject: [PATCH] convert hard-coded web root resource path to a configurable option --- src/clojure/clj_jtwig/options.clj | 7 ++++++- src/clojure/clj_jtwig/web/web_functions.clj | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/clojure/clj_jtwig/options.clj b/src/clojure/clj_jtwig/options.clj index be9dc1f..e9bbec7 100644 --- a/src/clojure/clj_jtwig/options.clj +++ b/src/clojure/clj_jtwig/options.clj @@ -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})) \ No newline at end of file + :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"})) \ No newline at end of file diff --git a/src/clojure/clj_jtwig/web/web_functions.clj b/src/clojure/clj_jtwig/web/web_functions.clj index 0d51ed7..0428800 100644 --- a/src/clojure/clj_jtwig/web/web_functions.clj +++ b/src/clojure/clj_jtwig/web/web_functions.clj @@ -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))))