From 072c093342917efab7d5591247ed1ed05bcc8927 Mon Sep 17 00:00:00 2001 From: J Irving Date: Wed, 7 Jan 2015 23:54:58 -0500 Subject: [PATCH] Copy each file rather than the whole directory --- project.clj | 2 +- src/cryogen_core/io.clj | 23 +++++++++++++++++++++-- src/cryogen_core/sass.clj | 9 ++------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/project.clj b/project.clj index 7dfa9bf..880bc08 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject cryogen-core "0.1.12" +(defproject cryogen-core "0.1.13-SNAPSHOT" :description "Cryogen's compiler" :url "https://github.com/lacarmen/cryogen-core" :license {:name "Eclipse Public License" diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj index e8e90df..e554111 100644 --- a/src/cryogen_core/io.clj +++ b/src/cryogen_core/io.clj @@ -4,6 +4,15 @@ (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] (-> resource io/resource io/file)) @@ -33,7 +42,17 @@ (doseq [asset (fs/find-files "resources/templates/md" #".+(jpg|jpeg|png|gif)")] (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] (let [src (str "resources/templates/" resource) target (str public blog-prefix "/" resource)] @@ -41,6 +60,6 @@ (not (.exists (io/file src))) (throw (IllegalArgumentException. (str "resource " src " not found"))) (.isDirectory (io/file src)) - (fs/copy-dir src target) + (copy-dir src target ignored-files) :else (fs/copy src target))))) diff --git a/src/cryogen_core/sass.clj b/src/cryogen_core/sass.clj index 6b3770a..93d2c2c 100644 --- a/src/cryogen_core/sass.clj +++ b/src/cryogen_core/sass.clj @@ -1,23 +1,18 @@ (ns cryogen-core.sass (:require [clojure.java.shell :refer [sh]] [clojure.java.io :as io] - [cryogen-core.io :refer [ignore]])) + [cryogen-core.io :refer [ignore match-re-filter]])) (defn sass-installed? "Checks for the installation of Sass." [] (= 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 "Given a Diretory, gets files, Filtered to those having scss or sass extention. Ignores files matching any ignored regexps." [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) (filter #(not (.isDirectory %))) (filter (ignore ignored-files))