Making CSS saner (from Patrick of Auctomatic)
patrick.auctomatic.com
patrick.auctomatic.com
Ex. In SASS
!main_width = 10
!unit1 = em
!unit2 = px
!bg_color = #a5f39e #main
:background-color = !bg_color
p
:background-color = !bg_color + #202020
:width = !main_width + !unit1
img.thumb
:width = (!main_width + 15) + !unit2
yields
#main {
background-color: #a5f39e; }
#main p {
background-color: #c5ffbe;
width: 10em; }
#main img.thumb { width: 25em; }
(Edit: Is there some way to format comments here on new.yc like there is on Reddit? I tried using both pre tags and indenting and neither worked…)
Things like this can cause hard to find problems further down the line in a big system build; after the error the target file exists and is newer than the sources.
Either don't use shell re-direction or do "cmd foo foo.tmp && mv foo.tmp foo".
$ make foo
false >foo
make: *** [foo] Error 1
$ make foo
make: `foo' is up to date.
$
I suppose they could do "cmd foo >bar || rm bar" instead of the mv I suggested. But that causes no bar to exist whereas the mv leaves the pre-build one behind.
@define companyred #ff5000
@define warningborder border: 1px red dotted
h1 {
color: @companyred;
} ....
So that the CSS file makes sense by itself.
Second: I use only a CSS, and only a JS file, it takes a lot of sense because the client will cache them both the first time, so even without include it's ok most of the times.
Lastly: It's semantically not more complex than your. Just @define to define and @symbol to expand.
But of course it's just a point of view like many things in design. I wanted to share my view about this because I planned to write the interpreter for this stuff and write a blog entry. Thanks for your article I'm happy it makes sense for others to extend in some way the CSS in order to have some kind of symbols.
CSS gurus and standard fundamentalists will usually reply that with inheritance you should never need this kind of stuff, but they lies ;)
ruby {
.... ruby code defining stuff ...
}
attrib: @stuff
Self contained, not a new language, able to define stuff relative to other stuff.
if you're using rails there's also this:
http://blog.airbladesoftware.com/2006/12/11/cssdryer-dry-up-your-css
also, even if you are just using ruby, why not rake and erb instead of make and eval?