Permalink
Browse files

Remove all usages of contrib.

  • Loading branch information...
1 parent 56d51eb commit c58a753bd9af4fc10ea8523d29403690daad2fa7 technomancy committed with Oct 21, 2011
Showing with 33 additions and 29 deletions.
  1. +1 −1 project.clj
  2. +16 −16 src/cssgen.clj
  3. +15 −11 src/cssgen/types.clj
  4. +1 −1 test/operations.clj
View
@@ -2,5 +2,5 @@
:description "Generate CSS from clojure code. Like an embedded sass."
:url "http://github.com/paraseba/cssgen"
:dependencies [[org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]]
+ [org.clojure/algo.generic "0.1.0-SNAPSHOT"]]
:dev-dependencies [[vimclojure/server "2.2.0"]])
View
@@ -1,11 +1,8 @@
(ns cssgen
- (:require (clojure.contrib [string :as s]
- [strint :as strint]
- [io :as io]
- [def :as ccdef]))
+ (:require [clojure.string :as s]
+ [clojure.java.io :as io])
(:use [cssgen.types :only (repr)]))
-
(defprotocol Container
(nest [child parent])
(add-properties [this new-props])
@@ -30,7 +27,7 @@
(defn- properties [x] (:properties x))
(defn- rules [x] (:rules x))
(defn- selector [x] (:selector x))
-(ccdef/defvar- empty-mixin (Mixin. [] []))
+(def ^{:private true} empty-mixin (Mixin. [] []))
(defn- empty-rule [selector] (Rule. selector [] []))
(defn- container? [x]
@@ -52,21 +49,22 @@
(defn- rule-css [rule]
(letfn [(format-prop [prop]
- (let [vals (s/join " " (map repr (next prop)))]
- (strint/<< " ~(repr (first prop)): ~{vals};")))
+ (let [key (repr (first prop))
+ vals (s/join " " (map repr (next prop)))]
+ (format " %s: %s;" key vals)))
(format-props [props]
(let [lines (map format-prop props)]
(s/join "\n" lines)))
(nest-single-selector [parent child]
- (if (s/substring? "&" child)
- (s/replace-str "&" parent child)
+ (if (.contains child "&")
+ (.replace child "&" parent)
(str parent (if-not (s/blank? parent) " ") child)))
(nest-selector [parent child]
- (let [parents (s/split #"," (or parent ""))
- children (s/split #"," (or child ""))]
+ (let [parents (s/split (or parent "") #",")
+ children (s/split (or child "") #",")]
(s/join ", " (for [p parents c children]
(nest-single-selector (s/trim p) (s/trim c))))))
@@ -75,15 +73,17 @@
properties (properties rule)
children (rules rule)
nested-selector (nest-selector parent-selector selector)
- parent-css (strint/<< "~{nested-selector} {\n~(format-props properties)\n}\n")
- children-css (s/join "\n" (map #(child-rule-css % nested-selector) children))]
+ parent-css (format "%s {\n%s\n}\n"
+ nested-selector (format-props properties))
+ children-css (s/join "\n" (for [c children]
+ (child-rule-css c nested-selector)))]
(str parent-css children-css)))]
(child-rule-css rule nil)))
(defn css [& rules]
- (s/map-str rule-css rules))
+ (apply str (map rule-css rules)))
(defn css-file [path & rules]
- (io/spit path (apply css rules)))
+ (spit path (apply css rules)))
View
@@ -1,15 +1,19 @@
(ns cssgen.types
- (:require
- (clojure.contrib [string :as s]
- [def :as ccdef])
- [clojure.contrib.generic.arithmetic :as generic]))
+ (:require [clojure.string :as s]
+ [clojure.algo.generic.arithmetic :as generic]))
+
+;; copied from contrib
+(defn- as-str [x]
+ (if (instance? clojure.lang.Named x)
+ (name x)
+ (str x)))
(defprotocol Value
(repr [x]))
(defrecord Length [mag unit]
Value
- (repr [_] (str (s/as-str mag) (s/as-str unit))))
+ (repr [_] (str (as-str mag) (as-str unit))))
(defrecord Color [r g b]
Value
@@ -37,19 +41,19 @@
([r g b] (letfn [(limit [x] (max 0 (min x 255)))]
(Color. (limit r) (limit g) (limit b))))
- ([string] (letfn [(remove-number-sign [s] (s/replace-first-re #"#" "" s))
+ ([string] (letfn [(remove-number-sign [s] (s/replace-first s #"#" ""))
(duplicate [s] (if (= (.length s) 3) (apply str (interleave s s)) s))]
- (let [components (->> string s/as-str remove-number-sign duplicate (re-seq #".."))
+ (let [components (->> string as-str remove-number-sign duplicate (re-seq #".."))
[r g b] (map #(Integer/parseInt % 16) components)]
(make-color r g b)))))
(defn- make-length [mag unit]
{:pre [(number? mag)]}
- (Length. mag (s/as-str unit)))
+ (Length. mag (as-str unit)))
-(ccdef/defmacro- def-length-constr [name]
+(defmacro ^{:private true} def-length-constr [name]
`(defn ~name [x#] (make-length x# ~(keyword name))))
(def-length-constr em)
@@ -95,7 +99,7 @@
(make-length ((generic/qsym generic /) ma num) ua))
-(ccdef/defmacro- compwise-col-col-op [sym f]
+(defmacro ^{:private true} compwise-col-col-op [sym f]
(let [f f]
`(defmethod ~sym [Color Color]
[{ra# :r ga# :g ba# :b} {rb# :r gb# :g bb# :b}]
@@ -111,7 +115,7 @@
((generic/qsym generic /) ba bb)))
-(ccdef/defmacro- compwise-col-num-op [sym f]
+(defmacro ^{:private true} compwise-col-num-op [sym f]
(let [f f]
`(do
(defmethod ~sym [Color Number]
View
@@ -3,7 +3,7 @@
(:use
cssgen cssgen.types
clojure.test
- [clojure.contrib.generic.arithmetic :only (+ - * /)]))
+ [clojure.algo.generic.arithmetic :only (+ - * /)]))
(def all-lengths [em ex px in cm mm pt pc % deg])

0 comments on commit c58a753

Please sign in to comment.