Skip to content

Commit

Permalink
Better handling of deleted partials
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegray committed May 4, 2016
1 parent 5cd8299 commit 86c2ea5
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/leiningen/scss/partials.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@
(string/join " | " result)))
result))

(defn partial-from-import-str*
(defn partial-from-import-str
"Takes a partial string and return the actual file."
[build-map file partial-str]
(let [partial-str (string/replace partial-str #"(.+?/)?([^/]+)$" "$1_$2.scss")
relative-candidate (string/replace file #"/[^/]*?$" (str "/" partial-str))
absolute-candidate (str (source-dir build-map) partial-str)
file? #(let [f (-> % io/as-file)] (when (.isFile f) f))]
(or (file? absolute-candidate) (file? relative-candidate))))
(def partial-from-import-str (memoize partial-from-import-str*))

(defn deps-in-scss
"Get all direct dependencies for an .scss file"
[build-map file]
(with-open [rdr (io/reader file)]
(->> (some->> rdr
line-seq
(map #(re-find #"@import\s+['\"](.*)['\"]" %))
(remove nil?)
(map last)
(map (partial partial-from-import-str build-map file)))
(remove nil?)
doall)))
(try
(with-open [rdr (io/reader file)]
(->> (some->> rdr
line-seq
(map #(re-find #"@import\s+['\"](.*)['\"]" %))
(remove nil?)
(map last)
(map (partial partial-from-import-str build-map file)))
(remove nil?)
doall))
(catch java.io.FileNotFoundException e (lein/info (color :red e)))))

(defn all-deps-for-scss
"Get all dependencies for an .scss file, dependencies of partials too."
Expand Down

0 comments on commit 86c2ea5

Please sign in to comment.