From 8ff3f19362dfa5362533991287eab62cfa488b26 Mon Sep 17 00:00:00 2001 From: Adam Tankanow Date: Sun, 11 Jan 2015 14:20:10 -0500 Subject: [PATCH] find-assets handles get-resource returning nilern - this can/will happen if a user doesn't have a resource root directory, e.g. if the resources/templates/asc/posts directory doesn't exist. --- src/cryogen_core/io.clj | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index e554111..53cad2c 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -22,11 +22,18 @@ matches (map #(re-find % name) ignored-files)] (not (some seq matches))))) -(defn find-assets [f ext ignored-files] - (->> (get-resource f) - file-seq - (filter (ignore ignored-files)) - (filter (fn [file] (-> file .getName (.endsWith ext)))))) +(defn find-assets + "Find all assets in the given root directory (f) and the given file + extension (ext) ignoring any files that match the given (ignored-files). + First make sure that the root directory exists, if yes: process as normal; + if no, return empty vector." + [f ext ignored-files] + (if-let [root (get-resource f)] + (->> (get-resource f) + file-seq + (filter (ignore ignored-files)) + (filter (fn [file] (-> file .getName (.endsWith ext))))) + [])) (defn create-folder [folder] (let [loc (io/file (str public folder))]