This is a read-only archive!

gaka 0.2.0

Per many commenters' suggestions and thanks to code from Steve Purcell, you can now use maps for CSS attributes in gaka.

user> (println (gaka/css [:a {:color :red}]))
a {
  color: red;}

This looks more like vanilla CSS thanks to the curlies, which is nice. You just have to keep in mind that your key/value pairs could end up being printed in random order, and order is significant1 in CSS.

It just so happens that maps are implemented in Clojure right now such that if they only have a few entries (16 key/value pairs), the order will be preserved, because you get a PersistentArrayMap instead of a PersistentHashMap. But it's highly dangerous to rely on such a thing. It could change at any time in the future.

In any case, you can also mix and match maps, lists and "flat" keyvals. They'll all be flattened That can help preserve attribute order in those cases where you need to.

user> (println (gaka/css [:a :color "red" {:padding 0} (list :margin 0)]))
a {
  color: red;
  padding: 0;
  margin: 0;}

I've also enhanced "mixins" a bit further. You can now mixin entire tags as well as attributes. Or a combination of both. Say you want a mixin that means "Make my element have no padding, and make links within the element be red":

user> (println (gaka/css [ mixin :margin 0]
                         [ mixin])) {
  padding: 0;
  margin: 0;} a {
    color: red;} {
  padding: 0;} a {
    color: red;}

You can get gaka from github or Clojars.

  1. Order is only significant in cases where you're doing things like padding: 0; padding-left: 1px. This is arguably bad CSS style, but it's valid, and it's also possible you'll have this kind of thing if you're generating CSS procedurally. But most of the time, order is not significant. e.g. it doesn't matter if you set text color first and background color second, or vice versa. So maybe this isn't so much of a problem in practice.

July 29, 2010 @ 6:59 AM PDT
Cateogory: Programming


Matija "hook" Šuklje
Quoth Matija "hook" Šuklje on July 29, 2010 @ 8:13 AM PDT

Erm, that's not the Sam&Max Steve Purcell, is it? O_o

Quoth Brian on July 29, 2010 @ 8:39 AM PDT

I believe not.

Matija "hook" Šuklje
Quoth Matija "hook" Šuklje on July 29, 2010 @ 8:41 AM PDT

Thought so.

A fun coincidence though ;)

Steve Purcell
Quoth Steve Purcell on July 29, 2010 @ 6:45 PM PDT

Nope, I'm not the same one. Nor am I the Steve Purcell who was a city mayor in Scotland. But I am all the others.