Skip to content

Commit 15182da

Browse files
committed
Add option :all_app_last to stylesheet_link_tag to ensure external styles can be overwritten without bundling
1 parent 68bb8c5 commit 15182da

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/propshaft/helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ def compute_asset_path(path, options = {})
6868
# # => <link rel="stylesheet" href="/assets/application-abc123.css"
6969
# # integrity="sha256-xyz789...">
7070
#
71-
# stylesheet_link_tag :all # All stylesheets in load path
72-
# stylesheet_link_tag :app # Only app/assets stylesheets
71+
# stylesheet_link_tag :all # All stylesheets in load path
72+
# stylesheet_link_tag :app # Only app/assets stylesheets
73+
# stylesheet_link_tag :all_app_last # All stylesheets in load path ensuring app/assets last,
74+
# so vendor and gem styles can safely be overwritten
7375
def stylesheet_link_tag(*sources)
7476
options = sources.extract_options!
7577

@@ -78,6 +80,9 @@ def stylesheet_link_tag(*sources)
7880
sources = all_stylesheets_paths
7981
when :app
8082
sources = app_stylesheets_paths
83+
when :all_app_last
84+
app_paths = app_stylesheets_paths
85+
sources = (all_stylesheets_paths - app_paths) + app_paths
8186
end
8287

8388
_build_asset_tags(sources, options, :stylesheet) { |source, opts| super(source, opts) }

test/propshaft/helper_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ class Propshaft::HelperTest < ActionView::TestCase
105105
HTML
106106
end
107107

108+
test "stylesheet_link_tag with :all_app_last option" do
109+
result = stylesheet_link_tag(:all_app_last)
110+
111+
assert_dom_equal(<<~HTML, result)
112+
<link rel="stylesheet" href="/assets/library-86a3b7a9.css" />
113+
<link rel="stylesheet" href="/assets/goodbye-b1dc9940.css" />
114+
<link rel="stylesheet" href="/assets/hello_world-4137140a.css" />
115+
HTML
116+
end
117+
108118
test "stylesheet_link_tag with :app option" do
109119
result = stylesheet_link_tag(:app)
110120

0 commit comments

Comments
 (0)