Merge pull request #8 from j0ni/fix-sass-ignores

Sass compilation respects :ignored-files config
This commit is contained in:
Dmitri Sotnikov 2015-01-01 12:08:54 -05:00
commit 7a84c4c6f5
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))
(println (blue "compiling sass"))
(sass/compile-sass->css!
(str "resources/templates/" sass-src)
(str "resources/public" blog-prefix "/" sass-dest))))
(str "resources/templates/" sass-src)
(str "resources/public" blog-prefix "/" sass-dest)
ignored-files)))
(defn compile-assets-timed []
(time
(try
(compile-assets)
(catch Exception e
(if
(or (instance? IllegalArgumentException e)
(instance? clojure.lang.ExceptionInfo e))
(if (or (instance? IllegalArgumentException e)
(instance? clojure.lang.ExceptionInfo e))
(println (red "Error:") (yellow (.getMessage e)))
(write-exception e))))))

View file

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

View file

@ -1,18 +1,27 @@
(ns cryogen-core.sass
(:require [clojure.java.shell :refer [sh]]
[clojure.java.io :as io]))
[clojure.java.io :as io]
[cryogen-core.io :refer [ignore]]))
(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"
[dir]
(->> (.list (io/file dir))
(seq)
(filter (comp not nil? (partial re-find #"(?i:s[ca]ss$)")))))
"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$)")]
(->> (.listFiles (io/file dir) filename-filter)
(filter #(not (.isDirectory %)))
(filter (ignore ignored-files))
(map #(.getName %)))))
(defn compile-sass-file!
"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
the command. Shows you any problems it comes across when compiling. "
[src-sass
dest-sass]
(let [sass-files (find-sass-files src-sass)]
dest-sass
ignored-files]
(let [sass-files (find-sass-files src-sass ignored-files)]
(if (seq sass-files)
;; I found sass files,
;; If sass is installed