Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

css_parser

> 前端框架
Open source

Ruby CSS Parser

299 stars0 likes1 views
WebsiteGitHub

About

Ruby CSS Parser

Ruby CSS Parser

Load, parse and cascade CSS rule sets in Ruby.

Setup

bash
gem install css_parser

Usage

…

Subresource Integrity

Parser#load_uri! accepts an integrity: option that verifies a fetched remote stylesheet against a Subresource Integrity value before it's parsed -- the same value an HTML `` attribute carries.

ruby
parser.load_uri!(
  'http://example.com/styles/style.css',
  integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC'
)

When the fetched body doesn't match, CssParser::IntegrityError (a subclass of CssParser::RemoteFileError, so existing rescue RemoteFileError code is unaffected) is raised if io_exceptions is enabled, or nothing is loaded otherwise.

integrity: also accepts several space-separated values, exactly like the HTML attribute does. When more than one hash algorithm is present, only the strongest one is checked (sha512 > sha384 > sha256) and every weaker value is ignored; multiple values for that same strongest algorithm are treated as alternatives -- matching any one of them is enough (useful during a stylesheet rotation, when a CDN may still serve the old version for a while):

ruby
parser.load_uri!(
  'http://example.com/styles/style.css',
  integrity: 'sha256-Br6tO8uuFyBAw2O0eUNdXVyuS/POLb5jpHxXaxIq6Q0= sha384-0gCPKBW0n+VzQzZu5gzP+YMxy9QTLyn1y/O/TMvLTpVajzRKAx6d7TiPB5W7DnDn'
)
# only the sha384 value is actually checked here; the sha256 one is present
# (e.g. for browsers/tools that only understand sha256) but ignored by this
# library since a stronger algorithm is also listed.

Testing

bash
bundle
bundle exec rake

Runs on Ruby 3.0/JRuby 9.4 or above.

Credits

By Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-11.

License: MIT

Thanks to all the wonderful contributors for their updates.

Made on Vancouver Island.

Issues· 24 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubycss-parserruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架