parse-css 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 65c805a944d8d10b13a41d955bc4f06231bded1a436ca09942484872eeae2952
4
+ data.tar.gz: e3c85fd4f482b45f3cd29c95b4dccec5a1b61e0663d9106677c54b311ba8a732
5
+ SHA512:
6
+ metadata.gz: 1a4742ed47acf9426d3c989f09b9b7fdee689fe914d34b387f67caed0a3ec919514021b197516389d89d07de363ab77143e92e97c89944d29d823a6348b2cae4
7
+ data.tar.gz: 014c990d7d981bb9b2d91972003a96ebb11743ccda4098e4538c843d9a2335d73099496bce2f4750cb26b33afd3cffed995c7b167c6d321e6909c2dc78baf6bd
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # 1.0.0
2
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem "rake"
7
+ gem "debug"
8
+ end
9
+
10
+ group :test do
11
+ gem "minitest"
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Cameron Dutro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ ## parse-css
2
+
3
+ ![Unit Tests](https://github.com/camertron/parse-css/actions/workflows/unit_tests.yml/badge.svg?branch=main)
4
+
5
+ ## What is this thing?
6
+
7
+ parse-css is a Ruby wrapper around the [parse-css](https://github.com/tabatkins/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.
8
+
9
+ 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.
10
+
11
+ ## Usage
12
+
13
+ The API of this gem is very simple:
14
+
15
+ ```ruby
16
+ require "parse-css"
17
+
18
+ ParseCSS.parse("body { color: red; }") # => [{...}]
19
+ ```
20
+
21
+ The `.parse` method produces a simple data structure made up of arrays, hashes, strings, and numbers.
22
+
23
+ That's it, that's all it does.
24
+
25
+ ## How does it work?
26
+
27
+ Yeah, so how can a library written in JavaScript be used from Ruby? parse-css is made possible by [mini_racer](https://github.com/rubyjs/mini_racer), a minimal, embeddable JavaScript runtime for Ruby.
28
+
29
+ ## Running Tests
30
+
31
+ `bundle exec rake` should do the trick.
32
+
33
+ ## License
34
+
35
+ Licensed under the MIT license. See LICENSE for details.
36
+
37
+ ## Authors
38
+
39
+ * Cameron C. Dutro: http://github.com/camertron
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/testtask"
4
+ require "rubygems/package_task"
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ Rake::TestTask.new("test") do |t|
9
+ t.warning = false
10
+ t.libs << "test"
11
+ t.test_files = FileList[
12
+ "test/**/*_test.rb"
13
+ ]
14
+ end
15
+
16
+ task default: [:test]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ParseCSS
4
+ VERSION = "1.0.0"
5
+ end
data/lib/parse-css.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mini_racer"
4
+
5
+ module ParseCSS
6
+ class << self
7
+ def parse(source)
8
+ context.call("parseAStylesheetsContents", source)
9
+ end
10
+
11
+ private
12
+
13
+ def context
14
+ @context ||= MiniRacer::Context.new.tap do |context|
15
+ context.eval(File.read(File.join(vendor_dir, "parse-css.js")))
16
+ end
17
+ end
18
+
19
+ def vendor_dir
20
+ @vendor_dir ||= File.join(__dir__, "..", "vendor")
21
+ end
22
+ end
23
+ end
data/parse-css.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+ require "parse-css/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "parse-css"
6
+ s.version = ::ParseCSS::VERSION
7
+ s.authors = ["Cameron Dutro"]
8
+ s.email = ["camertron@gmail.com"]
9
+ s.homepage = "http://github.com/camertron/parse-css"
10
+ s.description = s.summary = "A Ruby wrapper around the parse-css JavaScript library."
11
+ s.platform = Gem::Platform::RUBY
12
+
13
+ s.require_path = "lib"
14
+
15
+ s.add_dependency "mini_racer", "~> 0.19"
16
+
17
+ s.files = Dir["{lib,test}/**/*", "Gemfile", "LICENSE", "CHANGELOG.md", "README.md", "Rakefile", "parse-css.gemspec"]
18
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ParseCSSTest < Minitest::Test
6
+ def test_parse
7
+ assert_equal(
8
+ ParseCSS.parse("body { color: red; }"), [{
9
+ "type" => "QUALIFIED-RULE",
10
+ "prelude" => [{
11
+ "type" => "IDENT",
12
+ "value" => "body"
13
+ }, {
14
+ "type" => "WHITESPACE"
15
+ }],
16
+
17
+ "declarations" => [{
18
+ "type" => "DECLARATION",
19
+ "name" => "color",
20
+ "value" => [{
21
+ "type" => "IDENT",
22
+ "value" => "red"
23
+ }],
24
+
25
+ "important" => false
26
+ }],
27
+
28
+ "rules" => []
29
+ }]
30
+ )
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parse-css"
4
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parse-css
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Dutro
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: mini_racer
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.19'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.19'
26
+ description: A Ruby wrapper around the parse-css JavaScript library.
27
+ email:
28
+ - camertron@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/parse-css.rb
39
+ - lib/parse-css/version.rb
40
+ - parse-css.gemspec
41
+ - test/parse_css_test.rb
42
+ - test/test_helper.rb
43
+ homepage: http://github.com/camertron/parse-css
44
+ licenses: []
45
+ metadata: {}
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.6.7
61
+ specification_version: 4
62
+ summary: A Ruby wrapper around the parse-css JavaScript library.
63
+ test_files: []