add explicit check to see if the template file exists
JTwig does this too, but I would rather the thrown exception be a FileNotFoundException then a JTwig one
This commit is contained in:
parent
bef3836026
commit
a44b176139
|
@ -2,7 +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)
|
||||||
(java.io File)))
|
(java.io File FileNotFoundException)))
|
||||||
|
|
||||||
(defn- get-resource-path [filename]
|
(defn- get-resource-path [filename]
|
||||||
(-> (Thread/currentThread)
|
(-> (Thread/currentThread)
|
||||||
|
@ -30,6 +30,8 @@
|
||||||
[filename model-map & [options]]
|
[filename model-map & [options]]
|
||||||
(let [file (new File filename)
|
(let [file (new File filename)
|
||||||
template (new JtwigTemplate file)]
|
template (new JtwigTemplate file)]
|
||||||
|
(if-not (.exists file)
|
||||||
|
(throw (new FileNotFoundException (str "Template file \"" filename "\" not found."))))
|
||||||
(render-template template model-map options)))
|
(render-template template model-map options)))
|
||||||
|
|
||||||
(defn render-resource
|
(defn render-resource
|
||||||
|
|
Reference in a new issue