add helper function to check if a twig function has already been defined
This commit is contained in:
parent
a124170760
commit
ad57995af2
|
@ -2,6 +2,7 @@
|
||||||
(:require [clojure.walk :refer [stringify-keys]]
|
(:require [clojure.walk :refer [stringify-keys]]
|
||||||
[clojure.java.io :as io])
|
[clojure.java.io :as io])
|
||||||
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext)
|
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext)
|
||||||
|
(com.lyncode.jtwig.functions.exceptions FunctionNotFoundException)
|
||||||
(com.lyncode.jtwig.functions.repository DefaultFunctionRepository)
|
(com.lyncode.jtwig.functions.repository DefaultFunctionRepository)
|
||||||
(com.lyncode.jtwig.functions JtwigFunction)
|
(com.lyncode.jtwig.functions JtwigFunction)
|
||||||
(java.io File FileNotFoundException)))
|
(java.io File FileNotFoundException)))
|
||||||
|
@ -10,6 +11,13 @@
|
||||||
; any custom functions added will be added to this instance
|
; any custom functions added will be added to this instance
|
||||||
(defonce functions (atom (new DefaultFunctionRepository (make-array JtwigFunction 0))))
|
(defonce functions (atom (new DefaultFunctionRepository (make-array JtwigFunction 0))))
|
||||||
|
|
||||||
|
(defn- twig-fn-exists? [name]
|
||||||
|
(try
|
||||||
|
(.retrieve @functions name)
|
||||||
|
true
|
||||||
|
(catch FunctionNotFoundException ex
|
||||||
|
false)))
|
||||||
|
|
||||||
(defn- get-resource-path [filename]
|
(defn- get-resource-path [filename]
|
||||||
(-> (Thread/currentThread)
|
(-> (Thread/currentThread)
|
||||||
(.getContextClassLoader)
|
(.getContextClassLoader)
|
||||||
|
|
Reference in a new issue