diff --git a/src/clj_jtwig/core.clj b/src/clj_jtwig/core.clj index fe29a83..2655bc3 100644 --- a/src/clj_jtwig/core.clj +++ b/src/clj_jtwig/core.clj @@ -2,7 +2,8 @@ "wrapper functions for working with JTwig from clojure" (:import (com.lyncode.jtwig JtwigTemplate JtwigContext JtwigModelMap) (com.lyncode.jtwig.tree.api Content) - (java.io File FileNotFoundException ByteArrayOutputStream)) + (java.io File FileNotFoundException ByteArrayOutputStream) + (java.net URL)) (:require [clojure.walk :refer [stringify-keys]]) (:use [clj-jtwig.functions])) @@ -128,10 +129,11 @@ [] (reset! compiled-templates {})) -(defn- get-resource-path [filename] - (-> (Thread/currentThread) - (.getContextClassLoader) - (.getResource filename))) +(defn- get-resource-path + (^URL [^String filename] + (-> (Thread/currentThread) + (.getContextClassLoader) + (.getResource filename)))) (defn- make-model-map [model-map-values {:keys [skip-model-map-stringify?] :as options}] (let [model-map-obj (new JtwigModelMap) @@ -165,7 +167,7 @@ (defn render-file "renders a template from a file, using the values in model-map as the model for the template" - [filename model-map & [options]] + [^String filename model-map & [options]] (let [file (new File filename) compiled-template (compile-template! file)] (render-compiled-template compiled-template model-map options))) @@ -173,6 +175,6 @@ (defn render-resource "renders a template from a resource file, using the values in the model-map as the model for the template." - [filename model-map & [options]] + [^String filename model-map & [options]] (if-let [resource-filename (get-resource-path filename)] (render-file (.getPath resource-filename) model-map options))) diff --git a/src/clj_jtwig/functions.clj b/src/clj_jtwig/functions.clj index 56562eb..426af78 100644 --- a/src/clj_jtwig/functions.clj +++ b/src/clj_jtwig/functions.clj @@ -41,7 +41,7 @@ [] (reset! functions (create-function-repository))) -(defn function-exists? [name] +(defn function-exists? [^String name] (try (.retrieve @functions name) true @@ -52,9 +52,9 @@ "adds a new template function under the name specified. templates can call the function by the name specified (or one of the aliases specified) and passing in the same number of arguments accepted by f. the return value of f is returned to the template." - ([name f] + ([^String name f] (add-function! name nil f)) - ([name aliases f] + ([^String name aliases f] (let [handler (make-function-handler f)] (.add @functions handler name (make-aliased-array aliases)) (.retrieve @functions name))))