-
Notifications
You must be signed in to change notification settings - Fork 5
/
core.clj
27 lines (24 loc) · 1.17 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns optimus-sass.core
(:require [clojure.java.io :as io]
[clojure.string :as str]
[optimus.assets.creation :refer [last-modified existing-resource]]
[optimus.assets.load-css :refer [create-css-asset]])
(:import [org.jruby.embed ScriptingContainer LocalContextScope]))
(let [ruby (ScriptingContainer. LocalContextScope/SINGLETON)
sass (.runScriptlet ruby "ENV['GEM_PATH']='deps'
ENV['GEM_HOME']='deps'
require 'sass'
Sass")]
(defn compile-file [^java.io.File file]
(.callMethod ruby sass "compile_file" (.getPath file) String)))
(defn- load-sass-asset [public-dir path]
(let [resource (existing-resource public-dir path)
css (-> resource io/resource compile-file)
css-asset (create-css-asset (str/replace path #"\.sass\z|\.scss\z" ".css")
css
(last-modified resource))]
(assoc css-asset :original-path path)))
(doseq [ext ["sass" "scss"]]
(defmethod optimus.assets.creation/load-asset ext
[public-dir path]
(load-sass-asset public-dir path)))