csspin-rails 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1717d5c0156c805e78da55e7b3646c305586cc9d74b243d9799b29d76dd2e75
4
- data.tar.gz: 6fa180b07893e1c5a119da73c80318eacd7663791ae2c6c149c46031fe8cde45
3
+ metadata.gz: 3454e0488e9e270d59a784ee6d543b8b78c30358014dbeb625c8687ec439ba5f
4
+ data.tar.gz: 7b2bc27e4cb01fc6a2b9904531537a524af3d6614fdfbecd1a6720dbd8a87c37
5
5
  SHA512:
6
- metadata.gz: 827c66a027c92c20c3e236596903b70cf462eadd8b081dcd491cdb60129791e88b004dfe98576ab8b192a17a90787e766397d3d8e72921f2133e90e67dad4229
7
- data.tar.gz: 7a04c7c035d9fa58e151c0c4af7456b9ce0c7923c78495de426dbef7bb99e63ac5310481ac071a0c681d998d77c45a6313c9e4f7e3aebc3867a11600b033c219
6
+ metadata.gz: a3c8739d3e66f4dafaf259936931e99bc5599c7d9a6a237538a234aed0d3a2a03ad6c6abb40dfbfa4f8387f93e92edd0033f1f2bd79a9743fe5cc532bb8c316d
7
+ data.tar.gz: 71adb4ac5225949c366efb8a3de1b6774e1ad9c12ea29334f2a4839ac4bde1c53555f3a8a8538eceb63f0641297e3be1b8cfae083fa173b40e8f37e29c2d6fb3
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 1.0.1
4
+
5
+ - Inline relative CSS `@import` directives when pinning, so packages that ship an entrypoint stylesheet produce a single usable vendored file.
6
+ - Document the release process in the README.
7
+
8
+ ## 1.0.0
9
+
10
+ - Initial release.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # csspin-rails
2
2
 
3
- [![CI](https://github.com/elalemanyo/csspin-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/elalemanyo/csspin-rails/actions/workflows/ci.yml)
3
+ ![Gem Version](https://img.shields.io/gem/v/csspin-rails)
4
+ ![CI](https://github.com/elalemanyo/csspin-rails/actions/workflows/ci.yml/badge.svg)
5
+ ![License](https://img.shields.io/badge/License-MIT-green)
4
6
 
5
7
  Pin CSS packages from npm into a Rails app's `vendor/assets/stylesheets` — without Node.js.
6
8
 
@@ -24,13 +26,13 @@ bundle install
24
26
 
25
27
  ```bash
26
28
  # Pin a package (latest version)
27
- bundle exec csspin pin trix
29
+ bundle exec csspin pin sourdough-toast
28
30
 
29
31
  # Pin a specific version
30
- bundle exec csspin pin trix@2.0.0
32
+ bundle exec csspin pin sourdough-toast@2.0.7
31
33
 
32
34
  # Pin a scoped package
33
- bundle exec csspin pin @scope/package@1.2.3
35
+ bundle exec csspin pin @37signals/lexxy
34
36
  ```
35
37
 
36
38
  CSS is saved to `vendor/assets/stylesheets/<package>.css`.
@@ -40,8 +42,8 @@ If you want `bin/csspin`, run `bundle binstubs csspin-rails` first.
40
42
  After pinning, the CLI prints integration snippets:
41
43
 
42
44
  ```
43
- Sprockets snippet: *= require trix
44
- Sass snippet: @import "trix";
45
+ Sprockets snippet: *= require sourdough-toast
46
+ Sass snippet: @import "sourdough-toast";
45
47
  ```
46
48
 
47
49
  ## CLI
@@ -72,6 +74,17 @@ bundle exec standardrb
72
74
  bundle exec rake test
73
75
  ```
74
76
 
77
+ ### Releasing
78
+
79
+ This repo publishes via GitHub Actions when you push a tag matching `v*` (see `.github/workflows/release.yml`).
80
+
81
+ 1. Update `lib/csspin/version.rb`
82
+ 2. Run `bundle exec rake test` (and any linting you want)
83
+ 3. Commit
84
+ 4. Tag: `git tag vX.Y.Z`
85
+ 5. Push commit: `git push origin HEAD`
86
+ 6. Push tag: `git push origin vX.Y.Z`
87
+
75
88
  ## License
76
89
 
77
90
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -30,7 +30,10 @@ module Csspin
30
30
  return 1
31
31
  end
32
32
 
33
- saved_path = @writer.write(package_name: spec.package_name, content: result[:body])
33
+ css = Csspin::CssImportsInliner
34
+ .new(downloader: @downloader)
35
+ .inline(result[:body], base_url: result[:url], import_stack: [result[:url]])
36
+ saved_path = @writer.write(package_name: spec.package_name, content: css)
34
37
 
35
38
  snippet_package = File.basename(saved_path, ".css")
36
39
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module Csspin
6
+ class CssImportsInliner
7
+ IMPORT_RE = /\A\s*@import\s+(?:url\(\s*)?["'](?<path>[^"']+)["']\s*\)?\s*(?<media>[^;]*);\s*\z/
8
+
9
+ def initialize(downloader:)
10
+ @downloader = downloader
11
+ end
12
+
13
+ def inline(css, base_url:, import_stack: [])
14
+ return css unless css.include?("@import")
15
+
16
+ out = +""
17
+
18
+ css.each_line do |line|
19
+ match = IMPORT_RE.match(line)
20
+
21
+ out << if match && relative_css_path?(match[:path]) && match[:media].to_s.strip.empty?
22
+ fetch_css(base_url, match[:path], import_stack)
23
+ else
24
+ line
25
+ end
26
+ end
27
+
28
+ out
29
+ end
30
+
31
+ private
32
+
33
+ def fetch_css(base_url, relative_path, import_stack)
34
+ url = URI.join(base_url, relative_path).to_s
35
+
36
+ if import_stack.include?(url)
37
+ raise "Circular CSS import detected: #{(import_stack + [url]).join(" -> ")}"
38
+ end
39
+
40
+ response = @downloader.get(url)
41
+
42
+ raise "Failed to download imported CSS: #{url}" unless response[:ok]
43
+
44
+ import_stack << url
45
+ inlined = inline(response[:body].to_s, base_url: url, import_stack: import_stack)
46
+ inlined.end_with?("\n") ? inlined : "#{inlined}\n"
47
+ ensure
48
+ import_stack.pop if import_stack.last == url
49
+ end
50
+
51
+ def relative_css_path?(path)
52
+ return false if path.start_with?("/", "//")
53
+ return false if path.match?(/\A[a-z][a-z0-9+\-.]*:/i)
54
+
55
+ true
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Csspin
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
data/lib/csspin.rb CHANGED
@@ -6,6 +6,7 @@ require_relative "csspin/css_fallback_candidates"
6
6
  require_relative "csspin/jsdelivr_metadata_client"
7
7
  require_relative "csspin/resolver/jsdelivr"
8
8
  require_relative "csspin/http/downloader"
9
+ require_relative "csspin/css_imports_inliner"
9
10
  require_relative "csspin/vendor_writer"
10
11
  require_relative "csspin/instructions_printer"
11
12
  require_relative "csspin/commands/pin"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csspin-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - elalemanyo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-23 00:00:00.000000000 Z
11
+ date: 2026-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -60,12 +60,14 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - CHANGELOG.md
63
64
  - README.md
64
65
  - exe/csspin
65
66
  - lib/csspin.rb
66
67
  - lib/csspin/cli.rb
67
68
  - lib/csspin/commands/pin.rb
68
69
  - lib/csspin/css_fallback_candidates.rb
70
+ - lib/csspin/css_imports_inliner.rb
69
71
  - lib/csspin/http/downloader.rb
70
72
  - lib/csspin/instructions_printer.rb
71
73
  - lib/csspin/jsdelivr_metadata_client.rb