add utils namespace. move common utility functions over
This commit is contained in:
parent
57bb442808
commit
1b4fa0fa6f
|
@ -5,7 +5,8 @@
|
||||||
(java.io File FileNotFoundException ByteArrayOutputStream)
|
(java.io File FileNotFoundException ByteArrayOutputStream)
|
||||||
(java.net URL))
|
(java.net URL))
|
||||||
(:require [clojure.walk :refer [stringify-keys]])
|
(:require [clojure.walk :refer [stringify-keys]])
|
||||||
(:use [clj-jtwig.functions]))
|
(:use [clj-jtwig.functions]
|
||||||
|
[clj-jtwig.utils]))
|
||||||
|
|
||||||
; global options
|
; global options
|
||||||
(defonce options (atom {; true/false to enable/disable compiled template caching when using templates from
|
(defonce options (atom {; true/false to enable/disable compiled template caching when using templates from
|
||||||
|
@ -59,17 +60,6 @@
|
||||||
(new JtwigTemplate)
|
(new JtwigTemplate)
|
||||||
(.compile)))
|
(.compile)))
|
||||||
|
|
||||||
(defn- inside-jar? [^File file]
|
|
||||||
(-> file
|
|
||||||
(.getPath)
|
|
||||||
; the path of a file inside a jar looks something like "jar:file:/path/to/file.jar!/path/to/file"
|
|
||||||
(.contains "jar!")))
|
|
||||||
|
|
||||||
(defn- get-file-last-modified [^File file]
|
|
||||||
(if (inside-jar? file)
|
|
||||||
0
|
|
||||||
(.lastModified file)))
|
|
||||||
|
|
||||||
(defn- newer? [^File file other-timestamp]
|
(defn- newer? [^File file other-timestamp]
|
||||||
(let [file-last-modified (get-file-last-modified file)]
|
(let [file-last-modified (get-file-last-modified file)]
|
||||||
; a time of 0 means the modification time couldn't be read or the file is inside a JAR container. if it's an I/O
|
; a time of 0 means the modification time couldn't be read or the file is inside a JAR container. if it's an I/O
|
||||||
|
@ -129,12 +119,6 @@
|
||||||
[]
|
[]
|
||||||
(reset! compiled-templates {}))
|
(reset! compiled-templates {}))
|
||||||
|
|
||||||
(defn- get-resource-path
|
|
||||||
(^URL [^String filename]
|
|
||||||
(-> (Thread/currentThread)
|
|
||||||
(.getContextClassLoader)
|
|
||||||
(.getResource filename))))
|
|
||||||
|
|
||||||
(defn- make-model-map [model-map-values {:keys [skip-model-map-stringify?] :as options}]
|
(defn- make-model-map [model-map-values {:keys [skip-model-map-stringify?] :as options}]
|
||||||
(let [model-map-obj (new JtwigModelMap)
|
(let [model-map-obj (new JtwigModelMap)
|
||||||
values (if-not skip-model-map-stringify?
|
values (if-not skip-model-map-stringify?
|
||||||
|
|
28
src/clj_jtwig/utils.clj
Normal file
28
src/clj_jtwig/utils.clj
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
(ns clj-jtwig.utils
|
||||||
|
"various helper / utility functions"
|
||||||
|
(:import (java.net URL)
|
||||||
|
(java.io File)))
|
||||||
|
|
||||||
|
(defn inside-jar? [^File file]
|
||||||
|
(-> file
|
||||||
|
(.getPath)
|
||||||
|
; the path of a file inside a jar looks something like "jar:file:/path/to/file.jar!/path/inside/jar/to/file"
|
||||||
|
(.contains "jar!")))
|
||||||
|
|
||||||
|
(defn get-file-last-modified [^File file]
|
||||||
|
(if (inside-jar? file)
|
||||||
|
0
|
||||||
|
(.lastModified file)))
|
||||||
|
|
||||||
|
(defn get-resource-path
|
||||||
|
(^URL [^String filename]
|
||||||
|
(-> (Thread/currentThread)
|
||||||
|
(.getContextClassLoader)
|
||||||
|
(.getResource filename))))
|
||||||
|
|
||||||
|
(defn get-resource-modification-date [^String filename]
|
||||||
|
(when-let [resource-filename (get-resource-path filename)]
|
||||||
|
(->> resource-filename
|
||||||
|
(.getPath)
|
||||||
|
(new File)
|
||||||
|
(get-file-last-modified))))
|
Reference in a new issue