Tenderlove Making

CSSPool released

I just released csspool version 0.1.0 last night, so I thought I’d write a little about it.

CSSPool is a CSS SAC parser. Basically it parses a CSS document calling methods on a document handler object. The parser will send the document handler lots of information about the CSS, like the selectors and properties. The selectors you get are ASTs, and implement .to_css methods so you can get back css.

Here is a quick example:

require 'css/sac/parser'

class SimpleDocHandler < CSS::SAC::DocumentHandler
  def start_selector(selectors)
    p selectors.map { |sel| sel.to_css }.join(', ')

  def property(name, value, important)
    puts "#{name}: #{value} #{important ? '!important' : ''}".strip

csspool = CSS::SAC::Parser.new(SimpleDocHandler.new)

« go back