{"id":13878558,"url":"https://github.com/premailer/css_parser","last_synced_at":"2025-05-13T23:10:11.357Z","repository":{"id":45434787,"uuid":"408234","full_name":"premailer/css_parser","owner":"premailer","description":"Ruby CSS Parser","archived":false,"fork":false,"pushed_at":"2025-04-17T17:27:03.000Z","size":696,"stargazers_count":285,"open_issues_count":21,"forks_count":111,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-21T03:06:04.720Z","etag":null,"topics":["css-parser","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/premailer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-12-08T17:22:24.000Z","updated_at":"2025-04-17T17:27:07.000Z","dependencies_parsed_at":"2024-02-26T00:59:51.248Z","dependency_job_id":"c84239b6-5311-4eea-a02c-10d18331db6a","html_url":"https://github.com/premailer/css_parser","commit_stats":{"total_commits":380,"total_committers":69,"mean_commits":5.507246376811594,"dds":0.781578947368421,"last_synced_commit":"54b8ea5d542297efd0690bd22e390cf7640ee7d3"},"previous_names":["alexdunae/css_parser"],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fcss_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fcss_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fcss_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fcss_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/premailer","download_url":"https://codeload.github.com/premailer/css_parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250158164,"owners_count":21384338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-parser","ruby"],"created_at":"2024-08-06T08:01:53.067Z","updated_at":"2025-05-13T23:10:11.274Z","avatar_url":"https://github.com/premailer.png","language":"Ruby","readme":"# Ruby CSS Parser [![Build Status](https://github.com/premailer/css_parser/workflows/Run%20css_parser%20CI/badge.svg)](https://github.com/ojab/css_parser/actions?query=workflow%3A%22Run+css_parser+CI%22) [![Gem Version](https://badge.fury.io/rb/css_parser.svg)](https://badge.fury.io/rb/css_parser)\n\nLoad, parse and cascade CSS rule sets in Ruby.\n\n# Setup\n\n```Bash\ngem install css_parser\n```\n\n# Usage\n\n```Ruby\nrequire 'css_parser'\ninclude CssParser\n\nparser = CssParser::Parser.new\nparser.load_uri!('http://example.com/styles/style.css')\n\nparser = CssParser::Parser.new\nparser.load_uri!('file://home/user/styles/style.css')\n\n# load a remote file, setting the base_uri and media_types\nparser.load_uri!('../style.css', {base_uri: 'http://example.com/styles/inc/', media_types: [:screen, :handheld]})\n\n# load a local file, setting the base_dir and media_types\nparser.load_file!('print.css', '~/styles/', :print)\n\n# load a string\nparser = CssParser::Parser.new\nparser.load_string! 'a { color: hotpink; }'\n\n# lookup a rule by a selector\nparser.find_by_selector('#content')\n#=\u003e 'font-size: 13px; line-height: 1.2;'\n\n# lookup a rule by a selector and media type\nparser.find_by_selector('#content', [:screen, :handheld])\n\n# iterate through selectors by media type\nparser.each_selector(:screen) do |selector, declarations, specificity|\n  ...\nend\n\n# add a block of CSS\ncss = \u003c\u003c-EOT\n  body { margin: 0 1em; }\nEOT\n\nparser.add_block!(css)\n\n# output all CSS rules in a single stylesheet\nparser.to_s\n=\u003e #content { font-size: 13px; line-height: 1.2; }\n   body { margin: 0 1em; }\n\n# capturing byte offsets within a file\nparser.load_uri!('../style.css', {base_uri: 'http://example.com/styles/inc/', capture_offsets: true)\ncontent_rule = parser.find_rule_sets(['#content']).first\ncontent_rule.filename\n#=\u003e 'http://example.com/styles/styles.css'\ncontent_rule.offset\n#=\u003e 10703..10752\n\n# capturing byte offsets within a string\nparser.load_string!('a { color: hotpink; }', {filename: 'index.html', capture_offsets: true)\ncontent_rule = parser.find_rule_sets(['a']).first\ncontent_rule.filename\n#=\u003e 'index.html'\ncontent_rule.offset\n#=\u003e 0..21\n```\n\n# Testing\n\n```Bash\nbundle\nbundle exec rake\n```\n\nRuns on Ruby 3.0/JRuby 9.4 or above.\n\n# Credits\n\nBy Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-11.\n\nLicense: MIT\n\nThanks to [all the wonderful contributors](http://github.com/premailer/css_parser/contributors) for their updates.\n\nMade on Vancouver Island.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpremailer%2Fcss_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpremailer%2Fcss_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpremailer%2Fcss_parser/lists"}