Skip to content

Commit b17c7fc

Browse files
committed
Change stylesheet_link_tag and javascript_include_tag to extract options from sources
1 parent 83437cf commit b17c7fc

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/propshaft/helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def compute_asset_path(path, options = {})
7070
#
7171
# stylesheet_link_tag :all # All stylesheets in load path
7272
# stylesheet_link_tag :app # Only app/assets stylesheets
73-
def stylesheet_link_tag(*sources, **options)
73+
def stylesheet_link_tag(*sources)
74+
options = sources.extract_options!
75+
7476
case sources.first
7577
when :all
7678
sources = all_stylesheets_paths
@@ -95,7 +97,9 @@ def stylesheet_link_tag(*sources, **options)
9597
# javascript_include_tag "application", integrity: true
9698
# # => <script src="/assets/application-abc123.js"
9799
# # integrity="sha256-xyz789..."></script>
98-
def javascript_include_tag(*sources, **options)
100+
def javascript_include_tag(*sources)
101+
options = sources.extract_options!
102+
99103
_build_asset_tags(sources, options, :javascript) { |source, opts| super(source, opts) }
100104
end
101105

test/propshaft/helper_test.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ class Propshaft::HelperTest < ActionView::TestCase
131131
HTML
132132
end
133133

134+
test "stylesheet_link_tag should extract options from the sources" do
135+
result = stylesheet_link_tag(
136+
"hello_world",
137+
{
138+
media: "print",
139+
data: { turbo_track: "reload" }
140+
}
141+
)
142+
143+
assert_dom_equal(<<~HTML, result)
144+
<link
145+
rel="stylesheet"
146+
href="/assets/hello_world-4137140a.css"
147+
media="print"
148+
data-turbo-track="reload"
149+
/>
150+
HTML
151+
end
152+
134153
test "javascript_include_tag with integrity in secure context" do
135154
request.headers["HTTPS"] = "on"
136155

@@ -200,6 +219,24 @@ class Propshaft::HelperTest < ActionView::TestCase
200219
HTML
201220
end
202221

222+
test "javascript_include_tag should extract options from the sources" do
223+
result = javascript_include_tag(
224+
"hello_world",
225+
{
226+
defer: true,
227+
data: { turbo_track: "reload" }
228+
}
229+
)
230+
231+
assert_dom_equal(<<~HTML, result)
232+
<script
233+
src="/assets/hello_world-888761f8.js"
234+
defer="defer"
235+
data-turbo-track="reload"
236+
></script>
237+
HTML
238+
end
239+
203240
test "all_stylesheets_paths returns array of CSS asset paths" do
204241
paths = all_stylesheets_paths
205242

0 commit comments

Comments
 (0)