This commit is contained in:
lacarmen 2014-12-14 13:37:59 -05:00
parent 749eb7bb53
commit f83497b152

View file

@ -1,7 +1,6 @@
(ns cryogen-core.io (ns cryogen-core.io
(:require [clojure.java.io :refer [file]] (:require [clojure.java.io :as io]
[me.raynes.fs :as fs] [me.raynes.fs :as fs]))
[clojure.java.io :as io]))
(def public "resources/public") (def public "resources/public")
@ -10,7 +9,7 @@
(.getContextClassLoader) (.getContextClassLoader)
(.getResource resource) (.getResource resource)
(.toURI) (.toURI)
(file))) (io/file)))
(defn find-assets [f ext] (defn find-assets [f ext]
(->> (get-resource f) (->> (get-resource f)
@ -18,28 +17,27 @@
(filter (fn [file] (-> file .getName (.endsWith ext)))))) (filter (fn [file] (-> file .getName (.endsWith ext))))))
(defn create-folder [folder] (defn create-folder [folder]
(let [loc (file (str public folder))] (let [loc (io/file (str public folder))]
(when-not (.exists loc) (when-not (.exists loc)
(.mkdirs loc)))) (.mkdirs loc))))
(defn wipe-public-folder [keep-files] (defn wipe-public-folder [keep-files]
(let [filenamefilter (reify java.io.FilenameFilter (accept [this _ filename] (not (some #{filename} keep-files))))] (let [filenamefilter (reify java.io.FilenameFilter (accept [this _ filename] (not (some #{filename} keep-files))))]
(doseq [path (.listFiles (file public) filenamefilter)] (doseq [path (.listFiles (io/file public) filenamefilter)]
(fs/delete-dir path)))) (fs/delete-dir path))))
(defn copy-images-from-markdown-folders [{:keys [blog-prefix]}] (defn copy-images-from-markdown-folders [{:keys [blog-prefix]}]
(let [blog-prefix-relative (if (= \/ (first blog-prefix)) (subs blog-prefix 1) blog-prefix)] (doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")]
(doseq [asset (fs/find-files "resources/templates" #".+(jpg|jpeg|png|gif)")] (io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset))))))
(fs/copy asset (io/file public blog-prefix-relative "img" (.getName asset))))))
(defn copy-resources [{:keys [blog-prefix resources]}] (defn copy-resources [{:keys [blog-prefix resources]}]
(doseq [resource resources] (doseq [resource resources]
(let [src (str "resources/templates/" resource) (let [src (str "resources/templates/" resource)
target (str public blog-prefix "/" resource)] target (str public blog-prefix "/" resource)]
(cond (cond
(not (.exists (file src))) (not (.exists (io/file src)))
(throw (IllegalArgumentException. (str "resource " src " not found"))) (throw (IllegalArgumentException. (str "resource " src " not found")))
(.isDirectory (file src)) (.isDirectory (io/file src))
(fs/copy-dir src target) (fs/copy-dir src target)
:else :else
(fs/copy src target))))) (fs/copy src target)))))