Permalink
Browse files

no prop call needed in rules and mixins

  • Loading branch information...
1 parent efb6547 commit e0969814641c6495c55bbaece2a4ec27a4bf73bc @paraseba committed May 1, 2010
Showing with 33 additions and 44 deletions.
  1. +16 −27 src/cssgen.clj
  2. +17 −17 test/rules.clj
View
@@ -14,6 +14,9 @@
(defmethod add-rule-item ::Mixin [parent {components :components}]
(reduce add-rule-item parent components))
+(defmethod add-rule-item nil [parent _]
+ parent)
+
(defprotocol Value
(repr [x]))
@@ -65,30 +68,6 @@
; (make-value mag unit)))
-;(defprotocol ProcessProperty
-; (process-property [x]))
-
-;(extend-protocol ProcessProperty
-; clojure.lang.IPersistentMap
-; (process-property [m] (:prop m))
-
-; clojure.lang.IPersistentVector
-; (process-property [v] [(map process-property v)])
-
-; clojure.lang.Keyword
-; (process-property [k] k)
-;
-; clojure.lang.Symbol
-; (process-property [s] (symbol->value s))
-
-; Object
-; (process-property [o] o))
-
-
-
-
-
-
(defn prop [& forms]
(letfn [(expand-item [item]
(if (map? item)
@@ -98,12 +77,22 @@
in-pairs (apply vector (partition 2 expanded))]
{:tag ::Prop :prop in-pairs})))
+(defn- create-props [forms]
+ (letfn [(is-obj? [x] (or (map? x) (nil? x)))]
+ (let [parts (partition-by is-obj? forms)]
+ (mapcat #(if (is-obj? (first %))
+ %
+ [(apply prop %)])
+ parts))))
+
(defn rule [selector & forms]
- (reduce add-rule-item {:tag ::Rule :selector selector :children nil} forms))
+ (reduce add-rule-item
+ {:tag ::Rule :selector selector :children nil}
+ (create-props forms)))
+
(defn mixin [& forms]
- (let [filtered (filter (complement nil?) forms)]
- {:tag ::Mixin :components (vec filtered)}))
+ {:tag ::Mixin :components (vec (create-props forms))})
(defn rule-css [rule]
(letfn [(format-prop [prop]
View
@@ -12,7 +12,7 @@
"
(rule "div.klass#id, tr > td"
- (prop :padding [:1px :2px :5.5em :-3.3cm]))
+ :padding [:1px :2px :5.5em :-3.3cm])
"div.klass#id, tr > td {
padding: 1px 2px 5.5em -3.3cm;
}
@@ -22,16 +22,16 @@
(are [the-rule css] (= css (rule-css the-rule))
(rule "a"
- (prop :color :#aaa)
- (prop :background-color :#fafbfc))
+ :color "#aaa"
+ :background-color :#fafbfc)
"a {
color: #aaa;
background-color: #fafbfc;
}
"
(rule "a"
- (prop :color :#aaa :background-color :#fff))
+ :color :#aaa :background-color :#fff)
"a {
color: #aaa;
background-color: #fff;
@@ -42,9 +42,9 @@
(are [the-rule css] (= css (rule-css the-rule))
(rule "tr"
- (prop "background-color" :#fff)
+ :background-color :#fff
(rule "td"
- (prop "color" "black")))
+ :color "black"))
"tr {
background-color: #fff;
}
@@ -54,11 +54,11 @@ tr td {
"
(rule "tr"
- (prop :background-color :#fff
- :color "black")
+ :background-color :#fff
+ :color "black"
(rule "td"
- (prop :color "red")
- (prop :width "50%")))
+ :color "red"
+ :width "50%"))
"tr {
background-color: #fff;
color: black;
@@ -83,9 +83,9 @@ tr td {
(deftest inner-prop
(are [the-rule css] (= css (rule-css the-rule))
(rule "tr"
- (prop :padding 0 prop1)
- (prop prop2 prop3)
- (prop :border "none"))
+ :padding 0 prop1
+ prop2 prop3
+ :border "none")
"tr {
padding: 0;
color: #fff;
@@ -99,9 +99,9 @@ tr td {
(defn mixin1 []
(mixin
- (prop :padding 0)
+ :padding 0
(rule "a"
- (prop :color :blue))))
+ :color :blue)))
(deftest multiple-rules-and-props
(are [the-rule css] (= css (rule-css the-rule))
@@ -119,9 +119,9 @@ tr td {
(are [the-rule css] (= css (rule-css the-rule))
(rule "a"
(mixin
- (prop :color "blue")
+ :color "blue"
nil
- (prop :font-size :2mm)))
+ :font-size :2mm))
"a {
color: blue;
font-size: 2mm;

0 comments on commit e096981

Please sign in to comment.