parse-css
What is this thing?
parse-css is a Ruby wrapper around the parse-css JavaScript library. A number of CSS parsing libraries already exist for Ruby, but none of the ones I tested were able to handle nested CSS. The parse-css JavaScript library is small, fast, handles nested CSS, and doesn't have any dependencies or use special Node.js APIs.
Since this library is a wrapper around the JavaScript one, all the same limitations apply. For example, it doesn't try to validate the CSS it's given, or interpret it in any way. It's just a parser. Your mileage may vary.
Usage
The API of this gem is very simple:
require "parse-css"
ParseCSS.parse("body { color: red; }") # => [{...}]The .parse method produces a simple data structure made up of arrays, hashes, strings, and numbers.
That's it, that's all it does.
How does it work?
Yeah, so how can a library written in JavaScript be used from Ruby? parse-css is made possible by mini_racer, a minimal, embeddable JavaScript runtime for Ruby.
Running Tests
bundle exec rake should do the trick.
License
Licensed under the MIT license. See LICENSE for details.
Authors
- Cameron C. Dutro: http://github.com/camertron