From ad57995af225231bd2ca51450536bb42fb2e41bc Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 1 Mar 2014 15:37:25 -0500 Subject: [PATCH] add helper function to check if a twig function has already been defined --- src/clj_jtwig/core.clj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/clj_jtwig/core.clj b/src/clj_jtwig/core.clj index 937c6ad..7cc95fb 100644 --- a/src/clj_jtwig/core.clj +++ b/src/clj_jtwig/core.clj @@ -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)