style_capsule 2.0.0 → 2.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/style_capsule/stylesheet_registry.rb +68 -5
- data/lib/style_capsule/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66f1dc7d0d5addb480cfba5b2301305f390e23b8f6d533c69e57d8703fe9bf9d
|
|
4
|
+
data.tar.gz: 559cb7b3d87328da61419bf7a8ce1f4014a4425e4476966bfa0b129acc2fca26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfa2dd98b0465d2d83145b11801e35b7f7a1f1e8d4d26fb18ae8f2c9af35b4d6d4b58a8d4fed3c66d037c45dd8e1a988091b9d8aef28b50e9981c1a03a3f0807
|
|
7
|
+
data.tar.gz: 10390d9e96e507b1966a4b31bc4eb490d232eda1034f029a1604d7765d75653c75b1649054aa0170b2b32acba4eca406b5c49922823696e95da3f0da24ce4c40
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.0.1 (2026-07-03)
|
|
6
|
+
|
|
7
|
+
- Fix `render_head_stylesheets` clearing request-scoped registrations added after a template pre-render but before layout head (Phlex + Rails layout capture)
|
|
8
|
+
- Only remove request-scoped entries that existed when head rendering started; later body registrations remain for `HeadInjectionMiddleware`
|
|
9
|
+
- Document Phlex + Rails layout pattern: when `HeadInjectionMiddleware` is enabled, omit `stylesheet_registry_tags` for request-scoped namespaces and let the middleware inject all pending styles before `</head>` (calling `render_head_stylesheets` in layout head clears pre-captured template registrations without reliably writing tags into the Phlex buffer)
|
|
10
|
+
|
|
5
11
|
## 2.0.0 (2026-07-03)
|
|
6
12
|
|
|
7
13
|
- BREAKING: split `StylesheetRegistry.register` into request-scoped `register` and boot-time `register_eager`
|
|
@@ -567,16 +567,18 @@ module StyleCapsule
|
|
|
567
567
|
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity -- renders mixed inline and file registrations
|
|
568
568
|
def self.render_head_stylesheets(view_context = nil, namespace: nil)
|
|
569
569
|
if namespace.nil? || namespace.to_s.strip.empty?
|
|
570
|
+
request_files_snapshot = request_file_stylesheets.transform_values { |files| files.keys.dup }
|
|
571
|
+
request_inline_snapshot = request_inline_stylesheets.transform_values(&:dup)
|
|
572
|
+
|
|
570
573
|
all_stylesheets = merged_file_registrations_all_namespaces
|
|
571
574
|
|
|
572
575
|
request_inline_stylesheets.each do |_ns, inline|
|
|
573
576
|
all_stylesheets.concat(inline)
|
|
574
577
|
end
|
|
575
578
|
|
|
576
|
-
clear # Clear request-scoped inline CSS and file paths only
|
|
577
579
|
return safe_string("") if all_stylesheets.empty?
|
|
578
580
|
|
|
579
|
-
all_stylesheets.map do |stylesheet|
|
|
581
|
+
rendered = all_stylesheets.map do |stylesheet|
|
|
580
582
|
if stylesheet[:type] == :inline
|
|
581
583
|
render_inline_stylesheet(stylesheet, view_context)
|
|
582
584
|
else
|
|
@@ -584,15 +586,19 @@ module StyleCapsule
|
|
|
584
586
|
end
|
|
585
587
|
end.join("\n").then { |s| safe_string(s) }
|
|
586
588
|
|
|
589
|
+
clear_snapshotted_request_registrations(request_files_snapshot, request_inline_snapshot)
|
|
590
|
+
rendered
|
|
591
|
+
|
|
587
592
|
else
|
|
588
593
|
# Render specific namespace
|
|
589
594
|
ns = normalize_namespace(namespace)
|
|
595
|
+
snapshotted_file_paths = request_file_stylesheets[ns]&.keys&.dup || []
|
|
596
|
+
snapshotted_inline = request_inline_stylesheets[ns]&.dup || []
|
|
590
597
|
stylesheets = stylesheets_for(namespace: ns).dup
|
|
591
|
-
clear(namespace: ns) # Clear request-scoped inline CSS and file paths only
|
|
592
598
|
|
|
593
599
|
return safe_string("") if stylesheets.empty?
|
|
594
600
|
|
|
595
|
-
stylesheets.map do |stylesheet|
|
|
601
|
+
rendered = stylesheets.map do |stylesheet|
|
|
596
602
|
if stylesheet[:type] == :inline
|
|
597
603
|
render_inline_stylesheet(stylesheet, view_context)
|
|
598
604
|
else
|
|
@@ -600,6 +606,13 @@ module StyleCapsule
|
|
|
600
606
|
end
|
|
601
607
|
end.join("\n").then { |s| safe_string(s) }
|
|
602
608
|
|
|
609
|
+
clear_snapshotted_request_registrations_for_namespace(
|
|
610
|
+
ns,
|
|
611
|
+
file_paths: snapshotted_file_paths,
|
|
612
|
+
snapshotted_inline_stylesheets: snapshotted_inline
|
|
613
|
+
)
|
|
614
|
+
rendered
|
|
615
|
+
|
|
603
616
|
end
|
|
604
617
|
end
|
|
605
618
|
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
|
|
@@ -633,6 +646,55 @@ module StyleCapsule
|
|
|
633
646
|
end
|
|
634
647
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
635
648
|
|
|
649
|
+
# @api private
|
|
650
|
+
def self.clear_snapshotted_request_registrations(files_snapshot, inline_snapshot)
|
|
651
|
+
files_snapshot.each do |ns, file_paths|
|
|
652
|
+
clear_snapshotted_request_registrations_for_namespace(
|
|
653
|
+
ns,
|
|
654
|
+
file_paths: file_paths,
|
|
655
|
+
snapshotted_inline_stylesheets: inline_snapshot[ns] || []
|
|
656
|
+
)
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
inline_snapshot.each do |ns, snapshotted_inline_stylesheets|
|
|
660
|
+
next if files_snapshot.key?(ns)
|
|
661
|
+
|
|
662
|
+
clear_snapshotted_request_registrations_for_namespace(
|
|
663
|
+
ns,
|
|
664
|
+
file_paths: [],
|
|
665
|
+
snapshotted_inline_stylesheets: snapshotted_inline_stylesheets
|
|
666
|
+
)
|
|
667
|
+
end
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
# @api private
|
|
671
|
+
def self.clear_snapshotted_request_registrations_for_namespace(namespace, file_paths:, snapshotted_inline_stylesheets:)
|
|
672
|
+
ns = normalize_namespace(namespace)
|
|
673
|
+
|
|
674
|
+
if file_paths.any?
|
|
675
|
+
file_registry = request_file_stylesheets
|
|
676
|
+
file_paths.each { |path| file_registry[ns]&.delete(path) }
|
|
677
|
+
file_registry.delete(ns) if file_registry[ns] && file_registry[ns].empty?
|
|
678
|
+
self.request_file_stylesheets = file_registry
|
|
679
|
+
end
|
|
680
|
+
|
|
681
|
+
return if snapshotted_inline_stylesheets.empty?
|
|
682
|
+
|
|
683
|
+
inline_registry = inline_stylesheets
|
|
684
|
+
current_inline = inline_registry[ns] || []
|
|
685
|
+
remaining_inline = current_inline.reject do |entry|
|
|
686
|
+
snapshotted_inline_stylesheets.any? { |snapshot_entry| snapshot_entry.equal?(entry) || snapshot_entry == entry }
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
if remaining_inline.empty?
|
|
690
|
+
inline_registry.delete(ns)
|
|
691
|
+
else
|
|
692
|
+
inline_registry[ns] = remaining_inline
|
|
693
|
+
end
|
|
694
|
+
|
|
695
|
+
self.inline_stylesheets = inline_registry
|
|
696
|
+
end
|
|
697
|
+
|
|
636
698
|
# Inject pending request-scoped stylesheets into an HTML document before +</head>+.
|
|
637
699
|
#
|
|
638
700
|
# Used by +HeadInjectionMiddleware+ after the body has rendered and components have
|
|
@@ -718,7 +780,8 @@ module StyleCapsule
|
|
|
718
780
|
end
|
|
719
781
|
private_class_method :pending_request_stylesheets, :render_stylesheet_tags,
|
|
720
782
|
:merged_file_registrations_for_namespace, :merged_file_registrations_all_namespaces,
|
|
721
|
-
:merge_file_registrations
|
|
783
|
+
:merge_file_registrations, :clear_snapshotted_request_registrations,
|
|
784
|
+
:clear_snapshotted_request_registrations_for_namespace
|
|
722
785
|
|
|
723
786
|
# Render a file-based stylesheet
|
|
724
787
|
def self.render_file_stylesheet(stylesheet, view_context)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: style_capsule
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -63,6 +63,20 @@ dependencies:
|
|
|
63
63
|
- - "~>"
|
|
64
64
|
- !ruby/object:Gem::Version
|
|
65
65
|
version: '3'
|
|
66
|
+
- !ruby/object:Gem::Dependency
|
|
67
|
+
name: polyrun
|
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - "~>"
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: 1.5.0
|
|
73
|
+
type: :development
|
|
74
|
+
prerelease: false
|
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - "~>"
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: 1.5.0
|
|
66
80
|
- !ruby/object:Gem::Dependency
|
|
67
81
|
name: webmock
|
|
68
82
|
requirement: !ruby/object:Gem::Requirement
|