Permalink
Browse files

Update to clojure 1.4.0

  • Loading branch information...
1 parent b4251a2 commit e87e69276b8adfc1d96442eab48bfee5a47e472f @cdaddr committed Jul 18, 2012
Showing with 49 additions and 15 deletions.
  1. +2 −4 project.clj
  2. +8 −7 src/gaka/core.clj
  3. +39 −4 test/gaka/core_test.clj
View
@@ -1,5 +1,3 @@
-(defproject gaka/gaka "0.2.0"
+(defproject gaka "0.3.0"
:description "A CSS-generating library for Clojure"
- :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
- [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]]
- :dev-dependencies [[swank-clojure "1.2.1"]])
+ :dependencies [[org.clojure/clojure "1.4.0"]])
View
@@ -1,17 +1,17 @@
(ns gaka.core
- (:require (clojure.contrib [string :as s])
+ (:require (clojure [string :as s])
(clojure.java [io :as io])))
-(def *context* [])
-(def *print-indent* true)
+(def ^:dynamic *context* [])
+(def ^:dynamic *print-indent* true)
(defn make-rule [selector keyvals]
{:selector selector
:keyvals keyvals})
(defn indent [n]
(when *print-indent*
- (s/repeat n " ")))
+ (reduce str (repeat n " "))))
(defn render-val [x]
(cond (number? x) (str x)
@@ -21,7 +21,7 @@
(when-not val
(throw (IllegalArgumentException. (str "Missing value for key " (pr-str key) "."))))
(let [indent (indent n)]
- (str indent (name key) ": " (render-val val) ";")))
+ (str indent (name key) ": " (render-val val) ";")))
(defn- render-keyvals [n sep keyvals]
(s/join sep (map #(render-keyval n %)
@@ -71,14 +71,15 @@
(reduce (fn [rs x]
(compile* rs x))
rules subrules))))
- rules (s/split #"\s*,\s*" (name selector))))
+ rules (s/split (name selector) #"\s*,\s*")))
(defn css [& rules]
(let [rules (filter (complement empty?) rules)]
(if-not (seq rules)
""
(let [rules (reduce compile* [] rules)]
- (s/map-str render-rule rules)))))
+ (reduce str
+ (map render-rule rules))))))
(defn inline-css [& keyvals]
(render-keyvals 0 " " (flatten-keyvals keyvals)))
View
@@ -151,11 +151,46 @@
"a {\n color: red;}\n\n a img {\n border: none;}\n\n"
(css [:a :color :red [:img :border :none] :font-style :italic])
- "a {\n color: red;\n font-style: italic;}\n\n a img {\n border: none;}\n\n"))
+ "a {\n color: red;\n font-style: italic;}\n\n a img {\n border: none;}\n\n"
+
+ (css [:body
+ :padding 0
+ [:div#foo
+ [:a :color :red]]
+ :margin 0
+ [:div#bar
+ [:a :color :blue]]
+ :border 0])
+ "body {\n padding: 0;\n margin: 0;\n border: 0;}\n\n body div#foo a {\n color: red;}\n\n body div#bar a {\n color: blue;}\n\n"))
+
+(deftest test-css-no-indent
+ (binding [gaka.core/*print-indent* false]
+ (=? (css nil)
+ ""
+
+ (css [:a :color :red [:img :border :none]])
+ "a {\ncolor: red;}\n\na img {\nborder: none;}\n\n"
+
+ (css [:a {:color :red} [:img {:border :none}]])
+ "a {\ncolor: red;}\n\na img {\nborder: none;}\n\n"
+
+ (css [:a :color :red [:img :border :none] :font-style :italic])
+ "a {\ncolor: red;\nfont-style: italic;}\n\na img {\nborder: none;}\n\n"
+
+ (css [:body
+ :padding 0
+ [:div#foo
+ [:a :color :red]]
+ :margin 0
+ [:div#bar
+ [:a :color :blue]]
+ :border 0])
+ "body {\npadding: 0;\nmargin: 0;\nborder: 0;}\n\nbody div#foo a {\ncolor: red;}\n\nbody div#bar a {\ncolor: blue;}\n\n")))
(deftest test-inline-css
(=? (inline-css :color :red :border 1)
- "color: red; border: 1;"
+ "color: red; border: 1;")
+ (is
+ (re-find #"^(color: red; border: 1;|border: 1; color: red;)$"
+ (inline-css {:color :red :border 1}))))
- (inline-css {:color :red :border 1})
- "color: red; border: 1;"))

0 comments on commit e87e692

Please sign in to comment.