A summary of data about the Ruby ecosystem.

https://github.com/rgrove/crass

A Ruby CSS parser that's fully compliant with the CSS Syntax Level 3 specification.
https://github.com/rgrove/crass

Keywords

css parser ruby

Keywords from Contributors

activerecord rubygems gem ruby-gem cucumber mvc activejob sinatra polyglot-release test-coverage

Last synced: about 4 hours ago
JSON representation

Repository metadata

A Ruby CSS parser that's fully compliant with the CSS Syntax Level 3 specification.

README.md

Crass

Crass is a Ruby CSS parser that's fully compliant with the CSS Syntax Level 3 specification.

Gem Version
Tests

Links

Features

  • Pure Ruby, with no runtime dependencies other than Ruby 1.9.x or higher.

  • Tokenizes and parses CSS according to the rules defined in the 14 November 2014 editor's draft of the CSS Syntax Level 3 specification.

  • Extremely tolerant of broken or invalid CSS. If a browser can handle it, Crass should be able to handle it too.

  • Optionally includes comments in the token stream.

  • Optionally preserves certain CSS hacks, such as the IE "*" hack, which would otherwise be discarded according to CSS3 tokenizing rules.

  • Capable of serializing the parse tree back to CSS while maintaining all original whitespace, comments, and indentation.

Problems

  • Crass isn't terribly fast. I mean, it's Ruby, and it's not really slow by Ruby standards. But compared to the CSS parser in your average browser? Yeah, it's slow.

  • Crass only parses the CSS syntax; it doesn't understand what any of it means, doesn't coalesce selectors, etc. You can do this yourself by consuming the parse tree, though.

  • While any node in the parse tree (or the parse tree as a whole) can be serialized back to CSS with perfect fidelity, changes made to those nodes (except for wholesale removal of nodes) are not reflected in the serialized output.

  • Crass only supports UTF-8 input and doesn't respect @charset rules. Input in any other encoding will be converted to UTF-8.

Installing

gem install crass

Examples

Say you have a string containing some CSS:

/* Comment! */
a:hover {
  color: #0d8bfa;
  text-decoration: underline;
}

Parsing it is simple:

tree = Crass.parse(css, :preserve_comments => true)

This returns a big beautiful parse tree, which looks like this:

[{:node=>:comment, :pos=>0, :raw=>"/* Comment! */", :value=>" Comment! "},
 {:node=>:whitespace, :pos=>14, :raw=>"\n"},
 {:node=>:style_rule,
  :selector=>
   {:node=>:selector,
    :value=>"a:hover",
    :tokens=>
     [{:node=>:ident, :pos=>15, :raw=>"a", :value=>"a"},
      {:node=>:colon, :pos=>16, :raw=>":"},
      {:node=>:ident, :pos=>17, :raw=>"hover", :value=>"hover"},
      {:node=>:whitespace, :pos=>22, :raw=>" "}]},
  :children=>
   [{:node=>:whitespace, :pos=>24, :raw=>"\n  "},
    {:node=>:property,
     :name=>"color",
     :value=>"#0d8bfa",
     :children=>
      [{:node=>:whitespace, :pos=>33, :raw=>" "},
       {:node=>:hash,
        :pos=>34,
        :raw=>"#0d8bfa",
        :type=>:unrestricted,
        :value=>"0d8bfa"}],
     :important=>false,
     :tokens=>
      [{:node=>:ident, :pos=>27, :raw=>"color", :value=>"color"},
       {:node=>:colon, :pos=>32, :raw=>":"},
       {:node=>:whitespace, :pos=>33, :raw=>" "},
       {:node=>:hash,
        :pos=>34,
        :raw=>"#0d8bfa",
        :type=>:unrestricted,
        :value=>"0d8bfa"}]},
    {:node=>:semicolon, :pos=>41, :raw=>";"},
    {:node=>:whitespace, :pos=>42, :raw=>"\n  "},
    {:node=>:property,
     :name=>"text-decoration",
     :value=>"underline",
     :children=>
      [{:node=>:whitespace, :pos=>61, :raw=>" "},
       {:node=>:ident, :pos=>62, :raw=>"underline", :value=>"underline"}],
     :important=>false,
     :tokens=>
      [{:node=>:ident,
        :pos=>45,
        :raw=>"text-decoration",
        :value=>"text-decoration"},
       {:node=>:colon, :pos=>60, :raw=>":"},
       {:node=>:whitespace, :pos=>61, :raw=>" "},
       {:node=>:ident, :pos=>62, :raw=>"underline", :value=>"underline"}]},
    {:node=>:semicolon, :pos=>71, :raw=>";"},
    {:node=>:whitespace, :pos=>72, :raw=>"\n"}]}]

If you want, you can stringify the parse tree:

css = Crass::Parser.stringify(tree)

...which gives you back exactly what you put in!

/* Comment! */
a:hover {
  color: #0d8bfa;
  text-decoration: underline;
}

Wasn't that exciting?

Versioning

As of version 1.0.0, Crass adheres strictly to SemVer 2.0.

Contributing

The best way to contribute is to use Crass and create issues when you run into problems.

Pull requests that fix bugs are more than welcome as long as they include tests. Please adhere to the style and format of the surrounding code, or I might ask you to change things.

If you want to add a feature or refactor something, please get in touch first to make sure I'm on board with your idea and approach; I'm pretty picky, and I'd hate to have to turn down a pull request you spent a lot of time on.

Acknowledgments

I'm deeply grateful to Simon Sapin for his wonderfully comprehensive CSS parsing tests, which I adapted to create many of Crass's tests. They've been invaluable in helping me fix bugs and handle weird edge cases, and Crass would be much crappier without them.

I'm also grateful to Tab Atkins-Bittner and Simon Sapin (again!) for their work on the CSS Syntax Level 3 specification, which defines the tokenizing and parsing rules that Crass implements.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 106
Total Committers: 10
Avg Commits per committer: 10.6
Development Distribution Score (DDS): 0.104

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Ryan Grove r****n@w****m 95
Simon s****o@t****o 2
Mike Dalessio m****o@g****m 2
Yasuo Honda y****a@g****m 1
Vít Ondruch v****h@r****m 1
Tom Richards t****m@t****t 1
Peter Goldstein p****n@g****m 1
Orien Madgwick _@o****o 1
Nicolas Leger n****r 1
Adam Bachman a****n@g****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: 4 months ago

Total issues: 9
Total pull requests: 9
Average time to close issues: about 23 hours
Average time to close pull requests: 1 day
Total issue authors: 6
Total pull request authors: 9
Average comments per issue: 2.89
Average comments per pull request: 1.56
Merged pull request: 9
Bot issues: 0
Bot pull requests: 0

Past year issues: 0
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 0
Past year average comments per issue: 0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/rgrove/crass

Top Issue Authors

  • stoivo (3)
  • Fustrate (2)
  • abachman (1)
  • bf4 (1)
  • veesahni (1)
  • wlipa (1)

Top Pull Request Authors

  • rgrove (1)
  • voxik (1)
  • nicolasleger (1)
  • petergoldstein (1)
  • stoivo (1)
  • t-richards (1)
  • yahonda (1)
  • flavorjones (1)
  • orien (1)

Top Issue Labels

  • bug (2)

Top Pull Request Labels


Package metadata

gem.coop: crass

Crass is a pure Ruby CSS parser based on the CSS Syntax Level 3 spec.

  • Homepage: https://github.com/rgrove/crass/
  • Documentation: http://www.rubydoc.info/gems/crass/
  • Licenses: MIT
  • Latest release: 1.0.6 (published about 6 years ago)
  • Last Synced: 2026-03-02T05:31:55.790Z (1 day ago)
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 544,499,589 Total
  • Docker Downloads: 804,267,774
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.04%
    • Downloads: 0.043%
    • Docker downloads count: 0.116%
  • Maintainers (1)
rubygems.org: crass

Crass is a pure Ruby CSS parser based on the CSS Syntax Level 3 spec.

  • Homepage: https://github.com/rgrove/crass/
  • Documentation: http://www.rubydoc.info/gems/crass/
  • Licenses: MIT
  • Latest release: 1.0.6 (published about 6 years ago)
  • Last Synced: 2026-02-28T12:02:45.025Z (3 days ago)
  • Versions: 12
  • Dependent Packages: 13
  • Dependent Repositories: 345,725
  • Downloads: 544,258,305 Total
  • Docker Downloads: 804,267,774
  • Rankings:
    • Downloads: 0.043%
    • Dependent repos count: 0.06%
    • Docker downloads count: 0.151%
    • Dependent packages count: 1.536%
    • Average: 2.373%
    • Stargazers count: 4.73%
    • Forks count: 7.719%
  • Maintainers (1)
proxy.golang.org: github.com/rgrove/crass

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/rgrove/crass#section-documentation
  • Licenses: mit
  • Latest release: v1.0.6 (published about 6 years ago)
  • Last Synced: 2026-02-28T12:02:46.441Z (3 days ago)
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Stargazers count: 4.064%
    • Forks count: 5.765%
    • Average: 7.552%
    • Dependent packages count: 9.576%
    • Dependent repos count: 10.802%
ubuntu-23.10: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Licenses:
  • Latest release: 1.0.2-3 (published 18 days ago)
  • Last Synced: 2026-02-13T18:17:33.257Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.04: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Licenses:
  • Latest release: 1.0.2-3 (published 25 days ago)
  • Last Synced: 2026-02-06T15:02:49.738Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-23.04: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Licenses:
  • Latest release: 1.0.2-3 (published 20 days ago)
  • Last Synced: 2026-02-11T06:37:31.391Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Licenses:
  • Latest release: 1.0.2-2 (published 18 days ago)
  • Last Synced: 2026-02-13T07:12:01.285Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Licenses:
  • Latest release: 1.0.2-3ubuntu1 (published 22 days ago)
  • Last Synced: 2026-02-09T16:21:59.782Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-11: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Documentation: https://packages.debian.org/bullseye/ruby-crass
  • Licenses:
  • Latest release: 1.0.2-2.1 (published 21 days ago)
  • Last Synced: 2026-02-13T08:19:15.090Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-10: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Documentation: https://packages.debian.org/buster/ruby-crass
  • Licenses:
  • Latest release: 1.0.2-2 (published 20 days ago)
  • Last Synced: 2026-02-13T04:20:03.219Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Licenses:
  • Latest release: 1.0.2-3 (published 18 days ago)
  • Last Synced: 2026-02-13T13:14:52.274Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Documentation: https://packages.debian.org/bookworm/ruby-crass
  • Licenses:
  • Latest release: 1.0.2-3 (published 19 days ago)
  • Last Synced: 2026-02-12T23:27:34.091Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-13: ruby-crass

  • Homepage: https://github.com/rgrove/crass/
  • Documentation: https://packages.debian.org/trixie/ruby-crass
  • Licenses:
  • Latest release: 1.0.6-1 (published 19 days ago)
  • Last Synced: 2026-02-13T13:14:27.007Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

crass.gemspec rubygems
  • minitest ~> 5.0.8 development
  • rake ~> 10.1.0 development
.github/workflows/tests.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems

Score: 28.988042170105633