From: Andrew Stewart Date: 2007-02-07T23:48:19+09:00 Subject: Re: ruby CSS parser >> Anyone know of a decent ruby CSS parser? > > This is the opposite of what you are looking for, but with the > upcoming IOWA 1.0 release I have a Ruby CSS DSL -- write CSS with > Ruby using a syntax that's about as close as I could get it to > actual CSS. It supports everything Ruby does, so variables work as > does nesting of selectors into other selectors, and storing a > selector into a variable that can be refered to later. It also > provides a smart caching feature so that if, for instance, one > customizes the generated CSS according to a cookie setting, it can > cache that generated CSS and reuse it without having to execute all > of the DSL code for every request. > > The goals are to provide much DRYer CSS using Ruby that looks a lot > like CSS, with easy support for dynamic CSS generation, all covered > under the syntax checking of the Ruby parser (which should help one > catch simple errors). And because it's all Ruby code, it's easy to > write tests to validate dynamically generated CSS. This sounds similar to my css_dryer plugin for Rails which allows one to nest selectors and use variables: http://blog.airbladesoftware.com/2006/12/11/cssdryer-dry-up-your-css In the code I have to parse DRY CSS stylesheets as input. At the time I thought I could either build a proper, robust parser or get by with regular expressions and a home-made state machine. Not having any experience building parsers, I went with the latter approach. It works well but would I think be tricky to extend! Regards, Andy Stewart --------------------------------------- AirBlade Software Ltd http://airbladesoftware.com "Software that doesn't make you cry..." ---------------------------------------