add helper function to check if a twig function has already been defined

This commit is contained in:
Gered 2014-03-01 15:37:25 -05:00
parent a124170760
commit ad57995af2

View file

@ -2,6 +2,7 @@
(:require [clojure.walk :refer [stringify-keys]]
[clojure.java.io :as io])
(:import (com.lyncode.jtwig JtwigTemplate JtwigContext)
(com.lyncode.jtwig.functions.exceptions FunctionNotFoundException)
(com.lyncode.jtwig.functions.repository DefaultFunctionRepository)
(com.lyncode.jtwig.functions JtwigFunction)
(java.io File FileNotFoundException)))
@ -10,6 +11,13 @@
; any custom functions added will be added to this instance
(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]
(-> (Thread/currentThread)
(.getContextClassLoader)