Hoopla!

now with extra whiz-bang!

Hoopla!

Converting CSS to SASS files

April 16, 2008 · 0 comments

If I were to write a post about how much Haml and Sass have changed the way I develop for the web I’d spend the first few paragraphs gushing about how Haml lets you write your DOM directly and takes care of the hideous (X)HTML in the middle. Then I’d write an elaborate sonnet about how SASS makes CSS almost usable for developers who like to keep things DRY.

But we’ll save that Yegge-length post for another day. For now, here’s a chance to almostly completely convert your CSS files into SASS with just a few regexps (using $’s rather than \’s because TextMate likes it that way):

1
2
3
4
5
6
7
8
9
10
11
12

# trim opening braces
find: /\s?{\s*$/
replace:

# and closing braces
find: /^\s*}/
replace:

# and rearrange your punctuation
find: /^([ ]*)([\w-]+):\s*([\w\d #%,\(\)/\.-]+);\s*$/
replace: $1:$2 $3

Then rearrange and simplify to your heart’s content. Haml+Sass makes developers happy.

→ 0 comments Tags: