From f75a1a9c519c52c665e0d3b884232747c78439ea Mon Sep 17 00:00:00 2001 From: lukas Date: Thu, 20 Feb 2020 12:19:11 +0100 Subject: [PATCH] refactored find-assets Co-authored-by: Jan Krebs --- src/cryogen_core/new_io.clj | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cryogen_core/new_io.clj b/src/cryogen_core/new_io.clj index fef9815..15b131b 100644 --- a/src/cryogen_core/new_io.clj +++ b/src/cryogen_core/new_io.clj @@ -60,3 +60,20 @@ (remove st/blank?) (st/join "/") (#(st/replace % #"/+" "/")))) + +(defn get-file-extension-from-resource + [resource] + (str "." (last (st/split (:virtual-path resource) #"\.")))) + +(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." + [base-path paths ext ignored-files] + (let [assets (cp-io/get-resources "" base-path paths) + filter-file (fn [xs] (filter #(= (:resource-type %) :file) xs)) + filter-ext (fn [xs] (filter #(= (get-file-extension-from-resource %) ext) xs))] + (->> assets + filter-file + filter-ext))) \ No newline at end of file