Permalink
Browse files

clean up the api a bit and adds some more examples

  • Loading branch information...
1 parent e352451 commit 7bfc1b099cc8c0e6fb01cf7d504776d3f2cc636f @mylesmegyesi committed Mar 13, 2013
Showing with 38 additions and 25 deletions.
  1. +15 −3 README.md
  2. +8 −8 spec/sass/core_spec.clj
  3. +15 −14 src/sass/core.clj
View
@@ -12,18 +12,30 @@ This should only be used as a development dependency. This library depends on JR
To render a file
``` clojure
-(render-file-path {} "public/test.scss")
+; using default options
+(render-file-path "public/test.scss")
+
+; with options
+(render-file-path "public/test.scss" :property-syntax :new :style :compressed)
```
To render a resource
``` clojure
-(render-resource-path {} "test.scss")
+; using default options
+(render-resource-path "test.scss")
+
+; with options
+(render-file-path "test.scss" :load-paths ["src/stylesheets"])
```
Rendering a string
``` clojure
-(render-string {:style :compressed :syntax :scss} "$blue: #3bbfce; .content-navigation { border-color: $blue; }")
+; using default options
+(render-string "$blue: #3bbfce; .content-navigation { border-color: $blue; }")
; ".content-navigation{border-color:#3bbfce}"
+
+; with options
+(render-string "$blue: #3bbfce; .content-navigation { border-color: $blue; }" :style :compressed :syntax :scss)
```
View
@@ -21,7 +21,7 @@
margin: 8px;
border-color: #3bbfce; }
"
- (render-file-path "test_fixtures/test.scss" {})))
+ (render-file-path "test_fixtures/test.scss")))
(it "renders a file with a resource path"
(should=
@@ -34,7 +34,7 @@
margin: 8px;
border-color: #3bbfce; }
"
- (render-resource-path "test.scss" {})))
+ (render-resource-path "test.scss")))
(it "renders a scss file that has an import to another scss file"
(let [scss-file "scss/test1.scss"
@@ -46,7 +46,7 @@
.test1 {
border-color: blue; }
"
- (render-file-path file-path {:load-paths [(base-dir file-path scss-file)]}))))
+ (render-file-path file-path :load-paths [(base-dir file-path scss-file)]))))
(it "renders a sass file with a file path"
(should=
@@ -59,7 +59,7 @@
margin: 8px;
border-color: #3bbfce; }
"
- (render-file-path (resource-path "test.sass") {})))
+ (render-file-path (resource-path "test.sass"))))
(context "options"
@@ -72,7 +72,7 @@
.content-navigation {
border-color: $blue; }
"
- {:style :compressed :syntax :scss})))
+ :style :compressed :syntax :scss)))
(it "syntax"
(should=
@@ -84,7 +84,7 @@
.content-navigation
border-color: $blue
"
- {:syntax :sass})))
+ :syntax :sass)))
(it "property syntax"
(should=
@@ -96,7 +96,7 @@
.content-navigation
border-color: $blue
"
- {:syntax :sass :property-syntax :new}))
+ :syntax :sass :property-syntax :new))
(should=
".content-navigation {
border-color: #3bbfce; }
@@ -106,7 +106,7 @@
.content-navigation
:border-color $blue
"
- {:syntax :sass :property-syntax :old})))
+ :syntax :sass :property-syntax :old)))
)
)
View
@@ -6,6 +6,15 @@
[chee.coerce :refer [->string ->keyword]]
[zweikopf.core :refer :all]))
+(defn- init-sass []
+ (ruby-require (.getPath (resource "sass-3.2.6/lib/sass.rb"))))
+
+(init-ruby-context)
+(init-sass)
+
+(defn- resource-path [path]
+ (.getPath (resource path)))
+
(defn- underscore-key [k]
(->keyword (snake-case (->string k))))
@@ -19,20 +28,12 @@
(defn- new-sass-engine-for-file [file-path options]
(call-ruby "Sass::Engine" :for_file (rubyize file-path) (rubyize options)))
-(defn render-file-path [file-path options]
- (clojurize (call-ruby (new-sass-engine-for-file file-path (underscore-keys options)) render)))
+(defn render-file-path [file-path & {:as options}]
+ (clojurize (call-ruby (new-sass-engine-for-file file-path (underscore-keys (or options {}))) render)))
-(defn render-string [string options]
- (clojurize (call-ruby (new-sass-engine string (underscore-keys options)) render)))
+(defn render-string [string & {:as options}]
+ (clojurize (call-ruby (new-sass-engine string (underscore-keys (or options {}))) render)))
-(defn- resource-path [path]
- (.getPath (resource path)))
-
-(defn render-resource-path [path options]
- (render-file-path (resource-path path) options))
-
-(defn- init-sass []
- (ruby-require (.getPath (resource "sass-3.2.6/lib/sass.rb"))))
+(defn render-resource-path [path & options]
+ (apply render-file-path (resource-path path) options))
-(init-ruby-context)
-(init-sass)

0 comments on commit 7bfc1b0

Please sign in to comment.