Fork me on GitHub

zoolander by Nick Fitzgerald

A pure Python DSL for CSS.
                    .. .  ..
                    .  E#W# ,:
                .fjLK#W###W,#Kt .
                ,.WW####W###WiD;
              ,tj############j#K.
            tjtW################Di  .
             K#W#################WWK
            L#W###################WE.
            #######################Wj
           W########################W:
          :#W######################WWf
          KWW#WW########WW##WWW###WWK;t
          L K######WEEDLft;iitjt###WWf.
          f.#####KGfti,:::::,;;tt###D .
          .:#####Gffti,,::::,,;;tL#W#;
           D####WLffti,,,,:::,,;iiW##
          .#####DGLjti;,,,,,,,,;iiD##
           W###WEGLjjttt;;,,;,,;;iG#W
           #####EGLftjit;:,,t,,;;iL#WL.
           #W###KDLLt;i;,i:;,;,;ttfW#W.
           ####WGGDEDLGG;;:,iGDEDEf##W
           LW##DGEDGEKKDj:,,iLGft,f##i
           L###DDEjGWEEKGj:,LDLfKti#E
          .K###DDGLKDi;GLG,,tiKEtji#j
          :DK##DDGfDLD:GfG;,,jftjiiWi:
          .GGD#GGLfLGft;fLi;,,ji,,;E,:
          :LLLWGGfjti,,tfLi,;::::,;G;.
         ..fGD#GGftii;;tLGi,;,:,,,;j,.
           jLGKGGLjtiiitLLi:;,,,,;it;
           ffDDDGGfjtiijLft;;,,,;ii;;
           fjfGDGLLfjttjLWDjE,,,;iii:
           :ffGDDLLfjjtjDLLti,,,;ii,.
           .:ifjGLffffjjjfi;;,,,;t;
             .:GDLLLLLfjjf;ii;,;ii;
              .EGGffGGLfftt;;;iiii;
              .DtGLLLDGfGDDEDjttiii
               DDGLLGGLLDGfttjttiiW
              .GDGGLDDGfLGjijtjtiiKW
               GGDGGDDGLLLDDfjjtt#WKE .
               GGEDDDDDGGLLLjtitfWKKKL
               GGDEEEDGLLftiii,i#WKWKEG
               GGDEEEEDLftit;iiEWWKKKKE;.
               GLGEEDEEDLjtjtjWWWKWKKKKKjt:
              WKGGEDGDEKKEDDEWWKKKKKKKKKWWKK#i
      .  .  ,D##LLDEDDW######WKKKKKKKKKKKKKKWK#G:
  ..jDK###W#####DLGDEK###WWWWWWKKKKKKWWWWKWKKKKKKE
;####W##########ELDEEW##WKWWWWWWKKKKKKKKKKKKKKKKKK
WWW#W##########WWLDEEK#WWWWWWWKWKKKKKKKKKKKKKKKKKK
#WW#W############LEEEKWWWWWWWWWWWWWKKWKKKKKWKKWWWK
#WW##############jEDDKWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWW#########W##KWjGfDWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWW#########W#KLEjGLKWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWW##########DLffGD#WWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWW######WW##jtfGK#WWWWWWWWWWWK##WWWWWWWWWWWWWWWW

Clean

Nothing but pure python with a light syntax.

from zoolander import *

sheet = Stylesheet()

with sheet.definitions as rule:

    rule("h1",
         height=px(118),
         margin_top=em(1))

    rule(".tagline",
         font_size=px(26),
         text_align=right)

Variables

    blue = "#3BBFCE"
    margin = px(16)

    rule(".content_navigation",
         border_color=blue,
         margin=margin/2,
         color=blue.replace("CE", "EF"))

    rule(".border",
         margin=margin+3,
         border_color=blue)

Mixins

    table_scaffolding = dict(text_align=center,
                             font_weight=bold,
                             padding=px(2))

    rule("#blind-me-with-science",
         color="#CCCCEE",
         **table_scaffolding)

    def float_left(distance, **props):
        return dict(float=left,
                    margin_left=distance,
                    **props)

    left_table = float_left(px(10), **table_scaffolding)

    rule("#other-data",
         **left_table)

Render

# Returns the CSS, rendered as a string.
sheet.render()

# Render the CSS to a file
sheet.render_to_file("example.css")

Little Extras

As you may have noticed in the code examples above, Zoolander comes with a few batteries included, short-hand variables. These are provided just so that the number of quotes you need to type are minimized. As of right now, these are the ones that are included:

right = "right"
left = "left"
bold = "bold"
italic = "italic"
none = "none"
block = "block"
inline = "inline"

Install

$ git clone git://github.com/fitzgen/zoolander.git
$ cd zoolander/
$ sudo python setup.py install

Then open the example_styles.py file in your favorite editor, run

$ python example_styles.py

and inspect the output.

MIT Licensed

See the LICENSE file for more details.

Thanks

Thanks to Peter Rust and Tavis Rudd for inspiration.

Thanks to Sass, for providing me with a few code examples and ideas that I shamelessly ported to Zoolander. Sass is cool.