CSSes: gem to generate a CSS slate for Rails apps
I try to follow some good guidelines when developing a website. I separate content from style with CSS, for example, by judiciously using class and id attributes for html elements. Of course, I also usually leave the styling until the content has been mostly completed. The problem with that, though, is I end up with many views and many helpers that reference class and id attributes for elements I haven’t styled yet.
So I made CSSes. It searches helpers and views (you’re not putting style information in your controllers or models are you?) for references to html entities, and creates a bare-bones CSS file.
It has a few shortcomings. It doesn’t yet handle link_to* or image_tag or any of the form building methods, just raw referenced html. It’s only Rails 2.0.x friendly so far. It makes just one file, public/stylesheets/application.css, and you can’t control the name. If you use the < character in html attribute values, it will probably make a little noise. It doesn’t have any unit tests.
But! It was sure nice to run after working on a site for a while and finding this waiting for me:
body {}
div {}
div#author_bio {}
div#author_url {}
div#chapbook_exceprt {}
...
div.chapbook_links {}
div.poem_content {}
div.poem_links {}
...
h1 {}
h1#author_name {}
h1#chapbooks_header {}
...
Get it:
sudo gem install csses
Run it:
script/generate css
Any help at all would be greatly appreciated; it’s pretty raw. But I plan on making it more robust and more fun.
Update!: We’ve got tests, automatic anchor tag pseudo-classes, and basic link_to* and image_tag support (figuring out how to handle class and id attributes in rails helpers is a little trickier than I guessed at first). AND: it’s a gem now.
Dr Nic said,
December 31, 2007 @ 3:21 am
Very cool idea.
Support for the rails helpers would be an awesome/important addition.
frederico said,
December 31, 2007 @ 5:12 am
Nice…
already using it, and I like the idea…
Thanks for the good work to the community ;)
Robert Dempsey said,
December 31, 2007 @ 6:59 am
Very cool indeed. I will have to try it out today. Thanks Chris.