Skip to content

Commit

Permalink
fixed clojure 1.2 deftype changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jharwig committed Apr 25, 2010
1 parent cca24c5 commit 6f1f7a7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/spriter/core.clj
Expand Up @@ -41,7 +41,7 @@
(.println writer (str "/* CSS Sprite File Generated by css-spriter on " (java.util.Date.) " ...*/\n" ))
(let [css-writer (output-type outputs)]
(println (str "Generated sprite PNG with "
(count (for [image (with-coordinates (layout-type layouts) images)] (write-css-selector css-writer writer image)))
(count (for [image (with-coordinates (layout-type layouts) images)] (write-css-selector css-writer writer image)))
" images")))))


Expand Down
7 changes: 3 additions & 4 deletions src/spriter/layout.clj
Expand Up @@ -6,16 +6,15 @@
(with-coordinates [l images]))

(deftype Simple [direction]
:as this
Layout
(sprite-dimensions [i]
(sprite-dimensions [this, i]
(let [vertical (= direction :vertical)
images (with-coordinates this i)
x-dimension (apply max (map #((:dimensions %1) (if vertical 0 1)) images))
y-dimension (+ ((:coordinates (last images)) (if vertical 1 0)) ((:dimensions (last images)) (if vertical 1 0)))
dimensions [x-dimension y-dimension]]
(if vertical dimensions (vec (reverse dimensions)))))
(with-coordinates [images]
(with-coordinates [_ images]
(if (contains? (first images) :coordinates)
images
(let [vertical (= direction :vertical)
Expand All @@ -26,4 +25,4 @@
coord (if vertical coord (vec (reverse coord)))]
(merge image {:coordinates coord})))))))

(def layouts {:vertical (Simple :vertical) :horizontal (Simple :horizontal)})
(def layouts {:vertical (new Simple :vertical) :horizontal (new Simple :horizontal)})
2 changes: 1 addition & 1 deletion src/spriter/util.clj
Expand Up @@ -19,4 +19,4 @@

(defn num->css-str
([num] (num->css-str num "px"))
([num unit] (apply str (if (zero? num) [0] [num unit]))))
([num unit] (str num (when-not (zero? num) unit))))

This comment has been minimized.

Copy link
@jharwig

jharwig Apr 25, 2010

Author Owner

improvement suggestion by Seth, @foogoof

5 changes: 2 additions & 3 deletions src/spriter/writer.clj
Expand Up @@ -13,9 +13,8 @@
(write-css-selector [c writer image]))

(deftype Writer [format]
:as this
CssWriter
(write-css-selector [writer image]
(write-css-selector [_ writer image]
(let [class-name (str "." (image->class-name image))
nl (if (= format :verbose) "\n" "")
[css-width css-height] (map num->css-str (:dimensions image))
Expand All @@ -27,4 +26,4 @@
" background-position: " css-x " " css-y ";" nl
"}")))))

(def outputs {:verbose (Writer :verbose) :compact (Writer :compact)})
(def outputs {:verbose (new Writer :verbose) :compact (new Writer :compact)})
4 changes: 2 additions & 2 deletions test/spriter/layout_test.clj
Expand Up @@ -11,5 +11,5 @@
(should (= (count coord-images) (count images)))))

(testing "available layouts"
(should (= (:vertical layouts) (Simple :vertical)))
(should (= (:horizontal layouts) (Simple :horizontal))))
(should (not (nil? (:vertical layouts))))
(should (not (nil? (:horizontal layouts)))))

0 comments on commit 6f1f7a7

Please sign in to comment.