百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

css_parser

> 前端框架
开源

Ruby CSS 解析器

299 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Ruby CSS 解析器

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubycss-parserruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

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