Sass compilation respects :ignored-files config

This is an oversight from lacarmen/cryogen-core#4.

Also some slight refactoring.
This commit is contained in:
J Irving 2015-01-01 03:49:03 -05:00
parent bca0e89aa2
commit 6f7cb79a65
3 changed files with 26 additions and 20 deletions

View file

@ -303,16 +303,16 @@
(spit (str public blog-prefix "/" rss-name) (rss/make-channel config posts)) (spit (str public blog-prefix "/" rss-name) (rss/make-channel config posts))
(println (blue "compiling sass")) (println (blue "compiling sass"))
(sass/compile-sass->css! (sass/compile-sass->css!
(str "resources/templates/" sass-src) (str "resources/templates/" sass-src)
(str "resources/public" blog-prefix "/" sass-dest)))) (str "resources/public" blog-prefix "/" sass-dest)
ignored-files)))
(defn compile-assets-timed [] (defn compile-assets-timed []
(time (time
(try (try
(compile-assets) (compile-assets)
(catch Exception e (catch Exception e
(if (if (or (instance? IllegalArgumentException e)
(or (instance? IllegalArgumentException e) (instance? clojure.lang.ExceptionInfo e))
(instance? clojure.lang.ExceptionInfo e))
(println (red "Error:") (yellow (.getMessage e))) (println (red "Error:") (yellow (.getMessage e)))
(write-exception e)))))) (write-exception e))))))

View file

@ -5,11 +5,7 @@
(def public "resources/public") (def public "resources/public")
(defn get-resource [resource] (defn get-resource [resource]
(-> (Thread/currentThread) (-> resource io/resource io/file))
(.getContextClassLoader)
(.getResource resource)
(.toURI)
(io/file)))
(defn ignore [ignored-files] (defn ignore [ignored-files]
(fn [file] (fn [file]

View file

@ -1,18 +1,27 @@
(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]]))
(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 extention" "Given a Diretory, gets files, Filtered to those having scss or sass
[dir] extention. Ignores files matching any ignored regexps."
(->> (.list (io/file dir)) [dir ignored-files]
(seq) (let [filename-filter (re-filter #"(?i:s[ca]ss$)")]
(filter (comp not nil? (partial re-find #"(?i:s[ca]ss$)"))))) (->> (.listFiles (io/file dir) filename-filter)
(filter #(not (.isDirectory %)))
(filter (ignore ignored-files))
(map #(.getName %)))))
(defn compile-sass-file! (defn compile-sass-file!
"Given a sass file which might be in src-sass directory, "Given a sass file which might be in src-sass directory,
@ -31,8 +40,9 @@
dest-sass. Prompts you to install sass if he finds sass files and can't find dest-sass. Prompts you to install sass if he finds sass files and can't find
the command. Shows you any problems it comes across when compiling. " the command. Shows you any problems it comes across when compiling. "
[src-sass [src-sass
dest-sass] dest-sass
(let [sass-files (find-sass-files src-sass)] ignored-files]
(let [sass-files (find-sass-files src-sass ignored-files)]
(if (seq sass-files) (if (seq sass-files)
;; I found sass files, ;; I found sass files,
;; If sass is installed ;; If sass is installed