add macro for defining custom JTwig functions
This commit is contained in:
parent
ad57995af2
commit
8baf4e6045
|
@ -18,6 +18,17 @@
|
||||||
(catch FunctionNotFoundException ex
|
(catch FunctionNotFoundException ex
|
||||||
false)))
|
false)))
|
||||||
|
|
||||||
|
(defmacro deftwigfn [fn-name args & body]
|
||||||
|
`(do
|
||||||
|
(if (twig-fn-exists? ~fn-name)
|
||||||
|
(throw (new Exception (str "JTwig template function \"" ~fn-name "\" already defined.")))
|
||||||
|
(let [func# (fn ~args ~@body)
|
||||||
|
handler# (reify JtwigFunction
|
||||||
|
(execute [_ arguments#]
|
||||||
|
#_(func# (vec (aclone arguments#)))
|
||||||
|
(apply func# (vec (aclone arguments#)))))]
|
||||||
|
(.add @functions handler# ~fn-name (make-array String 0))))))
|
||||||
|
|
||||||
(defn- get-resource-path [filename]
|
(defn- get-resource-path [filename]
|
||||||
(-> (Thread/currentThread)
|
(-> (Thread/currentThread)
|
||||||
(.getContextClassLoader)
|
(.getContextClassLoader)
|
||||||
|
|
Reference in a new issue