add helper functions for compiling a template from a string or file
This commit is contained in:
parent
feefe82a30
commit
65109bccc5
|
@ -13,12 +13,20 @@
|
||||||
; be rendered by calling it's 'render' method
|
; be rendered by calling it's 'render' method
|
||||||
(defonce compiled-templates (atom {}))
|
(defonce compiled-templates (atom {}))
|
||||||
|
|
||||||
|
(defn- compile-template-string [^String contents]
|
||||||
|
(->> contents
|
||||||
|
(new JtwigTemplate)
|
||||||
|
(.compile)))
|
||||||
|
|
||||||
|
(defn- compile-template-file [^File file]
|
||||||
|
(->> file
|
||||||
|
(new JtwigTemplate)
|
||||||
|
(.compile)))
|
||||||
|
|
||||||
(defn- get-compiled-template [file]
|
(defn- get-compiled-template [file]
|
||||||
(if-not (.exists file)
|
(if-not (.exists file)
|
||||||
(throw (new FileNotFoundException (str "Template file \"" file "\" not found.")))
|
(throw (new FileNotFoundException (str "Template file \"" file "\" not found.")))
|
||||||
(->> file
|
(compile-template-file file)))
|
||||||
(new JtwigTemplate)
|
|
||||||
(.compile))))
|
|
||||||
|
|
||||||
(defn- create-function-repository []
|
(defn- create-function-repository []
|
||||||
(new DefaultFunctionRepository (make-array JtwigFunction 0)))
|
(new DefaultFunctionRepository (make-array JtwigFunction 0)))
|
||||||
|
|
Reference in a new issue