Skip to content

Commit

Permalink
now using the 'zweikopf' library to do jruby interop
Browse files Browse the repository at this point in the history
  • Loading branch information
mylesmegyesi committed Mar 12, 2013
1 parent a35bfd8 commit 256b8b7
Show file tree
Hide file tree
Showing 287 changed files with 51 additions and 91 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This is necessary for loading Sass when Haml is required in Rails 3.
# Once the split is complete, we can remove it.
require File.dirname(__FILE__) + '/../sass'
#require File.dirname(__FILE__) + '/../sass'
require 'sass/util'

module Sass
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.0"]
[org.jruby/jruby-complete "1.6.7.2"]
[zweikopf "0.1.0"]
[chee "1.1.2"]]
:profiles {:dev {:dependencies [[speclj "2.5.0"]]}}
:profiles {:dev {:dependencies [[speclj "2.5.0"]]
:resource-paths ["test_fixtures"]
:main speclj.main}}
:plugins [[speclj "2.5.0"]]
:test-paths ["spec"]
:resource-paths ["resources"])
:resource-paths ["gems"])
5 changes: 0 additions & 5 deletions resources/test-stylesheets/scss/test1.scss

This file was deleted.

26 changes: 13 additions & 13 deletions spec/sass/core_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
margin: 8px;
border-color: #3bbfce; }
"
(render-file-path {} (resource-path "test-stylesheets/test.scss"))))
(render-file-path "test_fixtures/test.scss" {})))

(it "renders a file with a resource path"
(should=
Expand All @@ -34,10 +34,10 @@
margin: 8px;
border-color: #3bbfce; }
"
(render-resource-path {} "test-stylesheets/test.scss")))
(render-resource-path "test.scss" {})))

(it "renders a scss file that has an import to another scss file"
(let [scss-file "test-stylesheets/scss/test1.scss"
(let [scss-file "scss/test1.scss"
file-path (resource-path scss-file)]
(should=
".test2 {
Expand All @@ -46,7 +46,7 @@
.test1 {
border-color: blue; }
"
(render-file-path {:load-paths [(base-dir file-path scss-file)]} file-path))))
(render-file-path file-path {:load-paths [(base-dir file-path scss-file)]}))))

(it "renders a sass file with a file path"
(should=
Expand All @@ -59,54 +59,54 @@
margin: 8px;
border-color: #3bbfce; }
"
(render-file-path {} (resource-path "test-stylesheets/test.sass"))))
(render-file-path (resource-path "test.sass") {})))

(context "options"

(it "output style"
(should=
".content-navigation{border-color:#3bbfce}
"
(render-string {:style :compressed :syntax :scss}
(render-string
"$blue: #3bbfce;
.content-navigation {
border-color: $blue; }
"
)))
{:style :compressed :syntax :scss})))

(it "syntax"
(should=
".content-navigation {
border-color: #3bbfce; }
"
(render-string {:syntax :sass}
(render-string
"$blue: #3bbfce
.content-navigation
border-color: $blue
"
)))
{:syntax :sass})))

(it "property syntax"
(should=
".content-navigation {
border-color: #3bbfce; }
"
(render-string {:syntax :sass :property-syntax :new}
(render-string
"$blue: #3bbfce
.content-navigation
border-color: $blue
"
))
{:syntax :sass :property-syntax :new}))
(should=
".content-navigation {
border-color: #3bbfce; }
"
(render-string {:syntax :sass :property-syntax :old}
(render-string
"$blue: #3bbfce
.content-navigation
:border-color $blue
"
)))
{:syntax :sass :property-syntax :old})))

)
)
57 changes: 27 additions & 30 deletions src/sass/core.clj
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
(ns sass.core
(:require [chee.string :refer [snake-case]]
(:require [clojure.java.io :refer [resource]]
[clojure.string :refer [split]]
[clojure.walk :refer [postwalk]]
[chee.string :refer [snake-case]]
[chee.coerce :refer [->string ->keyword]]
[sass.ruby :refer [run-ruby ->ruby]]))
[zweikopf.core :refer :all]))

(defn- underscore [k]
(defn- underscore-key [k]
(->keyword (snake-case (->string k))))

(defn- underscore-map [m]
(reduce
(fn [underscored [k v]]
(assoc underscored (underscore k) v))
{}
m))
(defn- underscore-keys [m]
(let [f (fn [[k v]] [(underscore-key k) v])]
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))

(defn- ->sass-engine-options [options]
(->ruby
(underscore-map options)))
(defn- new-sass-engine [template-string options]
(call-ruby "Sass::Engine" :new (rubyize template-string) (rubyize options)))

(defn render-file-path [options file-path]
(let [options (->sass-engine-options options)]
(str
(run-ruby
(str "Sass::Engine.for_file(" (->ruby file-path) ", " options ").render")))))
(defn- new-sass-engine-for-file [file-path options]
(call-ruby "Sass::Engine" :for_file (rubyize file-path) (rubyize options)))

(defn render-string [options string]
(let [options (->sass-engine-options options)]
(str
(run-ruby
(str "Sass::Engine.new(" (->ruby string) ", " options ").render")))))
(defn render-file-path [file-path options]
(clojurize (call-ruby (new-sass-engine-for-file file-path (underscore-keys options)) render)))

(defn- resource-path [resource]
(.getPath (clojure.java.io/resource resource)))
(defn render-string [string options]
(clojurize (call-ruby (new-sass-engine string (underscore-keys options)) render)))

(defn render-resource-path [options path]
(render-file-path options (resource-path path)))
(defn- resource-path [path]
(.getPath (resource path)))

(defn render-resource-path [path options]
(render-file-path (resource-path path) options))

(defn- append-to-load-path! [path]
(ruby-eval (str "$: << \"" path "\"")))

(defn- init-sass []
(let [sass-lib-path (first (clojure.string/split (.getPath (clojure.java.io/resource "gems/sass-3.2.6/lib/sass.rb")) #"/sass.rb" 2))]
(run-ruby
(str "$: << \"" sass-lib-path "\"")
"require 'sass'")))
(ruby-require (.getPath (resource "sass-3.2.6/lib/sass.rb"))))

(init-ruby-context)
(init-sass)
39 changes: 0 additions & 39 deletions src/sass/ruby.clj

This file was deleted.

File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions test_fixtures/scss/test1.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "scss/test2";

.test1 {
border-color: blue;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 256b8b7

Please sign in to comment.