Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for include paths #31

Merged
merged 3 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:dependencies '[[org.clojure/clojure "1.10.1" :scope "provided"]
[metosin/bat-test "0.4.3" :scope "test"]

[io.bit3/jsass "5.10.0"]
[io.bit3/jsass "5.10.3"]
[cheshire "5.9.0"]

[org.webjars/webjars-locator "0.37"]
Expand All @@ -18,7 +18,7 @@
[integrant "0.7.0" :scope "test"]

;; Webjars-locator uses logging
[org.slf4j/slf4j-nop "1.7.25" :scope "test"]
[org.slf4j/slf4j-nop "1.7.29" :scope "test"]

;; For testing the webjars asset locator implementation
[org.webjars.bower/bootstrap "4.3.1" :scope "test"]
Expand Down
11 changes: 6 additions & 5 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{:deps {io.bit3/jsass {:mvn/version "5.5.2"}
cheshire {:mvn/version "5.7.1"}
org.webjars/webjars-locator {:mvn/version "0.32-1"}
{:deps {io.bit3/jsass {:mvn/version "5.10.3"}
cheshire {:mvn/version "5.9.0"}
org.webjars/webjars-locator {:mvn/version "0.37"}
hawk {:mvn/version "0.2.11"}
org.clojure/tools.cli {:mvn/version "0.4.1"}
org.slf4j/slf4j-nop {:mvn/version "1.7.25"}}}
org.clojure/tools.cli {:mvn/version "0.4.2"}}

:aliases {:test {:extra-deps {org.slf4j/slf4j-nop {:mvn/version "1.7.29"}}}}}
15 changes: 7 additions & 8 deletions src/sass4clj/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(core/sass-compile-to-file
path
(.getPath (io/file target-path (string/replace relative-path #"\.(scss|sass)$" ".css")))
(dissoc options :target-path :source-paths))
(dissoc options :target-path))
(catch Exception e
(if auto
(println (.getMessage e))
Expand All @@ -65,13 +65,12 @@
(defn build [{:keys [source-paths auto] :as options}]
(when-not (s/valid? ::options options)
(s/explain-out (s/explain-data ::options options)))
(let [options (dissoc options :source-paths)]
(if auto
(watcher/start source-paths (fn [& _]
(let [main-files (find-main-files source-paths options)]
(compile-sass main-files options))))
(let [main-files (find-main-files source-paths options)]
(compile-sass main-files options)))))
(if auto
(watcher/start source-paths (fn [& _]
(let [main-files (find-main-files source-paths options)]
(compile-sass main-files options))))
(let [main-files (find-main-files source-paths options)]
(compile-sass main-files options))))

(defn start [options]
(build (assoc options :auto true)))
Expand Down
37 changes: 37 additions & 0 deletions test/sass4clj/api_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(ns sass4clj.api-test
(:require [clojure.test :refer [deftest is]]
[clojure.java.io :as io]
[sass4clj.api :as sass])
(:import (java.nio.file Files)
(java.nio.file.attribute FileAttribute)))

(defn- temp-dir
[prefix]
(.toString (Files/createTempDirectory prefix (into-array FileAttribute []))))

(def ^:private includer-scss
"body {
color: red;
}

@import 'includee';
")

(def ^:private includee-sass
"@charset 'utf-8'

p
color: blue
")

(deftest include-paths
(let [input-dir (temp-dir "sass4clj-input")
include-dir (temp-dir "sass4clj-include")
output-dir (temp-dir "sass4clj-output")
options {:source-paths [input-dir include-dir]
:target-path output-dir}]
(spit (io/file input-dir "includer.scss") includer-scss)
(spit (io/file include-dir "includee.sass") includee-sass)
(sass/build options)
(is (= "body {\n color: red; }\n\np {\n color: blue; }\n"
(slurp (io/file output-dir "includer.css"))))))