From 7595cbcf70167ecda6cf6ae737bd93e72be7a07f Mon Sep 17 00:00:00 2001 From: William Roe Date: Sat, 21 Feb 2015 21:56:38 +0000 Subject: [PATCH 1/4] Include --compass when it is available --- src/cryogen_core/sass.clj | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/cryogen_core/sass.clj b/src/cryogen_core/sass.clj index 93d2c2c..f4255cc 100644 --- a/src/cryogen_core/sass.clj +++ b/src/cryogen_core/sass.clj @@ -1,13 +1,23 @@ (ns cryogen-core.sass - (:require [clojure.java.shell :refer [sh]] + (:require [clojure.java.shell :as shell] [clojure.java.io :as io] [cryogen-core.io :refer [ignore match-re-filter]])) +(defmacro sh + [& args] + (let [valid-args (remove nil? args)] + `(shell/sh ~@valid-args))) + (defn sass-installed? "Checks for the installation of Sass." [] (= 0 (:exit (sh "sass" "--version")))) +(defn compass-installed? + "Checks for the installation of Compass." + [] + (= 0 (:exit (sh "compass" "--version")))) + (defn find-sass-files "Given a Diretory, gets files, Filtered to those having scss or sass extention. Ignores files matching any ignored regexps." @@ -24,9 +34,11 @@ done by sh / launching the sass command." [sass-file src-sass - dest-sass] + dest-sass + compass?] (sh "sass" "--update" + (when compass? "--compass") (str src-sass "/" sass-file) (str dest-sass "/" ))) @@ -42,15 +54,16 @@ the command. Shows you any problems it comes across when compiling. " ;; I found sass files, ;; If sass is installed (if (sass-installed?) - ;; I compile all files - (doseq [a-file sass-files] - (println "Compiling Sass File:" a-file) - (let [result (compile-sass-file! a-file src-sass dest-sass)] - (if (zero? (:exit result)) - ;; no problems in sass compilation - (println "Successfully compiled:" a-file) - ;; else I show the error - (println (:err result))))) + (let [compass? (compass-installed?)] + ;; I compile all files + (doseq [a-file sass-files] + (println "Compiling Sass File:" a-file src-sass dest-sass) + (let [result (compile-sass-file! a-file src-sass dest-sass compass?)] + (if (zero? (:exit result)) + ;; no problems in sass compilation + (println "Successfully compiled:" a-file) + ;; else I show the error + (println (:err result)))))) ;; Else I prompt to install Sass (println "Sass seems not to be installed, but you have scss / sass files in " src-sass From 0c7743e6054a78d47d27ebb12a834922a111bbba Mon Sep 17 00:00:00 2001 From: William Roe Date: Sat, 21 Feb 2015 22:07:41 +0000 Subject: [PATCH 2/4] Ensure sass errors printed visably in red Also include the standard output as it frequently includes crucial information in narrowing down where errors lie in SASS files --- src/cryogen_core/sass.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cryogen_core/sass.clj b/src/cryogen_core/sass.clj index f4255cc..ca31e1e 100644 --- a/src/cryogen_core/sass.clj +++ b/src/cryogen_core/sass.clj @@ -1,6 +1,7 @@ (ns cryogen-core.sass (:require [clojure.java.shell :as shell] [clojure.java.io :as io] + [text-decoration.core :refer :all] [cryogen-core.io :refer [ignore match-re-filter]])) (defmacro sh @@ -63,7 +64,8 @@ the command. Shows you any problems it comes across when compiling. " ;; no problems in sass compilation (println "Successfully compiled:" a-file) ;; else I show the error - (println (:err result)))))) + (println (red (:err result)) + (red (:out result))))))) ;; Else I prompt to install Sass (println "Sass seems not to be installed, but you have scss / sass files in " src-sass From 52244956aa4d020865b442878627791dd65a536a Mon Sep 17 00:00:00 2001 From: William Roe Date: Sat, 21 Feb 2015 22:15:40 +0000 Subject: [PATCH 3/4] Option maps are easier to use when calling functions ... with more than a couple of parameters. --- src/cryogen_core/compiler.clj | 6 +++--- src/cryogen_core/sass.clj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 53177f8..0bafd75 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -321,9 +321,9 @@ (rss/make-filtered-channels public config posts-by-tag) (println (blue "compiling sass")) (sass/compile-sass->css! - (str "resources/templates/" sass-src) - (str "resources/public" blog-prefix "/" sass-dest) - ignored-files))) + {:src-sass (str "resources/templates/" sass-src) + :dest-sass (str "resources/public" blog-prefix "/" sass-dest) + :ignored-files ignored-files}))) (defn compile-assets-timed [] (time diff --git a/src/cryogen_core/sass.clj b/src/cryogen_core/sass.clj index ca31e1e..a89411a 100644 --- a/src/cryogen_core/sass.clj +++ b/src/cryogen_core/sass.clj @@ -47,9 +47,9 @@ "Given a directory src-sass, looks for all sass files and compiles them into 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 - ignored-files] + [{:keys [src-sass + dest-sass + ignored-files]}] (let [sass-files (find-sass-files src-sass ignored-files)] (if (seq sass-files) ;; I found sass files, From 5587cc88ef21832bcc04ee18e476e3155964517f Mon Sep 17 00:00:00 2001 From: William Roe Date: Sat, 21 Feb 2015 23:23:05 +0000 Subject: [PATCH 4/4] Run SASS relative to sass/ This is so that SASS/Compass can find images and other assets --- src/cryogen_core/compiler.clj | 7 +++-- src/cryogen_core/sass.clj | 57 +++++++++++++++++------------------ 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 0bafd75..b9e725a 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -321,9 +321,10 @@ (rss/make-filtered-channels public config posts-by-tag) (println (blue "compiling sass")) (sass/compile-sass->css! - {:src-sass (str "resources/templates/" sass-src) - :dest-sass (str "resources/public" blog-prefix "/" sass-dest) - :ignored-files ignored-files}))) + {:src-sass sass-src + :dest-sass (str "../public" blog-prefix "/" sass-dest) + :ignored-files ignored-files + :base-dir "resources/templates/"}))) (defn compile-assets-timed [] (time diff --git a/src/cryogen_core/sass.clj b/src/cryogen_core/sass.clj index a89411a..4da4472 100644 --- a/src/cryogen_core/sass.clj +++ b/src/cryogen_core/sass.clj @@ -22,9 +22,9 @@ (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] + [base-dir dir ignored-files] (let [filename-filter (match-re-filter #"(?i:s[ca]ss$)")] - (->> (.listFiles (io/file dir) filename-filter) + (->> (.listFiles (io/file base-dir dir) filename-filter) (filter #(not (.isDirectory %))) (filter (ignore ignored-files)) (map #(.getName %))))) @@ -33,15 +33,14 @@ "Given a sass file which might be in src-sass directory, output the resulting css in dest-sass. All error handling is done by sh / launching the sass command." - [sass-file - src-sass - dest-sass - compass?] - (sh "sass" - "--update" - (when compass? "--compass") - (str src-sass "/" sass-file) - (str dest-sass "/" ))) + [{:keys [src-sass + dest-sass + base-dir]}] + (shell/with-sh-dir base-dir + (sh "sass" + "--update" + (when (compass-installed?) "--compass") + (str src-sass ":" dest-sass)))) (defn compile-sass->css! "Given a directory src-sass, looks for all sass files and compiles them into @@ -49,24 +48,22 @@ 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. " [{:keys [src-sass dest-sass - ignored-files]}] - (let [sass-files (find-sass-files src-sass ignored-files)] - (if (seq sass-files) + ignored-files + base-dir] :as opts}] + (when-let [sass-files (seq (find-sass-files base-dir src-sass ignored-files))] + (if (sass-installed?) ;; I found sass files, ;; If sass is installed - (if (sass-installed?) - (let [compass? (compass-installed?)] - ;; I compile all files - (doseq [a-file sass-files] - (println "Compiling Sass File:" a-file src-sass dest-sass) - (let [result (compile-sass-file! a-file src-sass dest-sass compass?)] - (if (zero? (:exit result)) - ;; no problems in sass compilation - (println "Successfully compiled:" a-file) - ;; else I show the error - (println (red (:err result)) - (red (:out result))))))) - ;; Else I prompt to install Sass - (println "Sass seems not to be installed, but you have scss / sass files in " - src-sass - " - You might want to install it here: sass-lang.com"))))) + (do + (println "Compiling Sass Files:" src-sass dest-sass) + (let [result (compile-sass-file! opts)] + (if (zero? (:exit result)) + ;; no problems in sass compilation + (println "Successfully compiled sass files") + ;; else I show the error + (println (red (:err result)) + (red (:out result)))))) + ;; Else I prompt to install Sass + (println "Sass seems not to be installed, but you have scss / sass files in " + src-sass + " - You might want to install it here: sass-lang.com"))))