From 65109bccc5c1f390df746a8d064a6033ab3cbcaf Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 2 Mar 2014 12:59:27 -0500 Subject: [PATCH] add helper functions for compiling a template from a string or file --- src/clj_jtwig/core.clj | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/clj_jtwig/core.clj b/src/clj_jtwig/core.clj index ca3c2bb..873b507 100644 --- a/src/clj_jtwig/core.clj +++ b/src/clj_jtwig/core.clj @@ -13,12 +13,20 @@ ; be rendered by calling it's 'render' method (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] (if-not (.exists file) (throw (new FileNotFoundException (str "Template file \"" file "\" not found."))) - (->> file - (new JtwigTemplate) - (.compile)))) + (compile-template-file file))) (defn- create-function-repository [] (new DefaultFunctionRepository (make-array JtwigFunction 0)))