proper method of rendering template files contained in jars
This commit is contained in:
parent
f68862e784
commit
a84c8588bd
|
@ -1,6 +1,7 @@
|
||||||
(ns clj-jtwig.core
|
(ns clj-jtwig.core
|
||||||
"wrapper functions for working with JTwig from clojure"
|
"wrapper functions for working with JTwig from clojure"
|
||||||
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext JtwigModelMap)
|
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext JtwigModelMap)
|
||||||
|
(com.lyncode.jtwig.resource ClasspathJtwigResource)
|
||||||
(com.lyncode.jtwig.tree.api Content)
|
(com.lyncode.jtwig.tree.api Content)
|
||||||
(java.io File FileNotFoundException ByteArrayOutputStream)
|
(java.io File FileNotFoundException ByteArrayOutputStream)
|
||||||
(java.net URL))
|
(java.net URL))
|
||||||
|
@ -56,9 +57,15 @@
|
||||||
(.compile)))
|
(.compile)))
|
||||||
|
|
||||||
(defn- compile-template-file [^File file]
|
(defn- compile-template-file [^File file]
|
||||||
(->> file
|
(if (inside-jar? file)
|
||||||
(new JtwigTemplate)
|
(->> (.getPath file)
|
||||||
(.compile)))
|
(get-jar-resource-filename)
|
||||||
|
(new ClasspathJtwigResource)
|
||||||
|
(new JtwigTemplate)
|
||||||
|
(.compile))
|
||||||
|
(->> file
|
||||||
|
(new JtwigTemplate)
|
||||||
|
(.compile))))
|
||||||
|
|
||||||
(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)]
|
||||||
|
|
|
@ -9,6 +9,12 @@
|
||||||
; the path of a file inside a jar looks something like "jar:file:/path/to/file.jar!/path/inside/jar/to/file"
|
; the path of a file inside a jar looks something like "jar:file:/path/to/file.jar!/path/inside/jar/to/file"
|
||||||
(.contains "jar!")))
|
(.contains "jar!")))
|
||||||
|
|
||||||
|
(defn get-jar-resource-filename [^String resource-filename]
|
||||||
|
(let [pos (.indexOf resource-filename "jar!")]
|
||||||
|
(if-not (= -1 pos)
|
||||||
|
(subs resource-filename (+ pos 5))
|
||||||
|
resource-filename)))
|
||||||
|
|
||||||
(defn exists? [^File file]
|
(defn exists? [^File file]
|
||||||
(if (inside-jar? file)
|
(if (inside-jar? file)
|
||||||
;; TODO: can't use File.exists() for this
|
;; TODO: can't use File.exists() for this
|
||||||
|
|
Reference in a new issue