@@ -14,12 +14,12 @@ def javascript_importmap_tags(entry_point = "application", shim: true)
14
14
# By default, `Rails.application.importmap.to_json(resolver: self)` is used.
15
15
def javascript_inline_importmap_tag ( importmap_json = Rails . application . importmap . to_json ( resolver : self ) )
16
16
tag . script importmap_json . html_safe ,
17
- type : "importmap" , "data-turbo-track" : "reload" , nonce : content_security_policy_nonce
17
+ type : "importmap" , "data-turbo-track" : "reload" , nonce : request &. content_security_policy
18
18
end
19
19
20
20
# Configure es-modules-shim with nonce support if the application is using a content security policy.
21
21
def javascript_importmap_shim_nonce_configuration_tag
22
- if content_security_policy?
22
+ if request &. content_security_policy
23
23
tag . script ( { nonce : content_security_policy_nonce } . to_json . html_safe ,
24
24
type : "esms-options" , nonce : content_security_policy_nonce )
25
25
end
@@ -28,14 +28,14 @@ def javascript_importmap_shim_nonce_configuration_tag
28
28
# Include the es-modules-shim needed to make importmaps work in browsers without native support (like Firefox + Safari).
29
29
def javascript_importmap_shim_tag ( minimized : true )
30
30
javascript_include_tag minimized ? "es-module-shims.min.js" : "es-module-shims.js" ,
31
- async : true , "data-turbo-track" : "reload" , nonce : content_security_policy_nonce
31
+ async : true , "data-turbo-track" : "reload" , nonce : request &. content_security_policy
32
32
end
33
33
34
34
# Import a named JavaScript module(s) using a script-module tag.
35
35
def javascript_import_module_tag ( *module_names )
36
36
imports = Array ( module_names ) . collect { |m | %(import "#{ m } ") } . join ( "\n " )
37
37
tag . script imports . html_safe ,
38
- type : "module" , nonce : content_security_policy_nonce
38
+ type : "module" , nonce : request &. content_security_policy
39
39
end
40
40
41
41
# Link tags for preloading all modules marked as preload: true in the `importmap`
@@ -48,7 +48,7 @@ def javascript_importmap_module_preload_tags(importmap = Rails.application.impor
48
48
# Link tag(s) for preloading the JavaScript module residing in `*paths`. Will return one link tag per path element.
49
49
def javascript_module_preload_tag ( *paths )
50
50
safe_join ( Array ( paths ) . collect { |path |
51
- tag . link rel : "modulepreload" , href : path , nonce : content_security_policy_nonce
51
+ tag . link rel : "modulepreload" , href : path , nonce : request &. content_security_policy
52
52
} , "\n " )
53
53
end
54
54
end
0 commit comments