Copy each file rather than the whole directory

This commit is contained in:
J Irving 2015-01-07 23:54:58 -05:00
parent 656cc2d0c9
commit 072c093342
3 changed files with 24 additions and 10 deletions

View file

@ -1,4 +1,4 @@
(defproject cryogen-core "0.1.12" (defproject cryogen-core "0.1.13-SNAPSHOT"
:description "Cryogen's compiler" :description "Cryogen's compiler"
:url "https://github.com/lacarmen/cryogen-core" :url "https://github.com/lacarmen/cryogen-core"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"

View file

@ -4,6 +4,15 @@
(def public "resources/public") (def public "resources/public")
(defn re-filter [bool-fn re & other-res]
(let [res (conj other-res re)]
(reify java.io.FilenameFilter
(accept [this _ name]
(bool-fn (some #(re-find % name) res))))))
(def match-re-filter (partial re-filter some?))
(def reject-re-filter (partial re-filter nil?))
(defn get-resource [resource] (defn get-resource [resource]
(-> resource io/resource io/file)) (-> resource io/resource io/file))
@ -33,7 +42,17 @@
(doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")] (doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")]
(io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset)))))) (io/copy asset (io/file (str public blog-prefix "/img/" (.getName asset))))))
(defn copy-resources [{:keys [blog-prefix resources]}] (defn copy-dir [src target ignored-files]
(fs/mkdirs target)
(let [filename-filter (apply reject-re-filter ignored-files)
files (.listFiles (io/file src) filename-filter)]
(doseq [f files]
(let [out (io/file target (.getName f))]
(if (.isDirectory f)
(copy-dir f out ignored-files)
(io/copy f out))))))
(defn copy-resources [{:keys [blog-prefix resources ignored-files]}]
(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)]
@ -41,6 +60,6 @@
(not (.exists (io/file src))) (not (.exists (io/file src)))
(throw (IllegalArgumentException. (str "resource " src " not found"))) (throw (IllegalArgumentException. (str "resource " src " not found")))
(.isDirectory (io/file src)) (.isDirectory (io/file src))
(fs/copy-dir src target) (copy-dir src target ignored-files)
:else :else
(fs/copy src target))))) (fs/copy src target)))))

View file

@ -1,23 +1,18 @@
(ns cryogen-core.sass (ns cryogen-core.sass
(:require [clojure.java.shell :refer [sh]] (:require [clojure.java.shell :refer [sh]]
[clojure.java.io :as io] [clojure.java.io :as io]
[cryogen-core.io :refer [ignore]])) [cryogen-core.io :refer [ignore match-re-filter]]))
(defn sass-installed? (defn sass-installed?
"Checks for the installation of Sass." "Checks for the installation of Sass."
[] []
(= 0 (:exit (sh "sass" "--version")))) (= 0 (:exit (sh "sass" "--version"))))
(defn re-filter [re]
(reify java.io.FilenameFilter
(accept [this _ name]
(not (nil? (re-find re name))))))
(defn find-sass-files (defn find-sass-files
"Given a Diretory, gets files, Filtered to those having scss or sass "Given a Diretory, gets files, Filtered to those having scss or sass
extention. Ignores files matching any ignored regexps." extention. Ignores files matching any ignored regexps."
[dir ignored-files] [dir ignored-files]
(let [filename-filter (re-filter #"(?i:s[ca]ss$)")] (let [filename-filter (match-re-filter #"(?i:s[ca]ss$)")]
(->> (.listFiles (io/file dir) filename-filter) (->> (.listFiles (io/file dir) filename-filter)
(filter #(not (.isDirectory %))) (filter #(not (.isDirectory %)))
(filter (ignore ignored-files)) (filter (ignore ignored-files))