Module: Iconmap::IconmapTagsHelper
- Defined in:
- app/helpers/iconmap/iconmap_tags_helper.rb
Instance Method Summary collapse
-
#javascript_iconmap_module_preload_tags(iconmap = Rails.application.iconmap, entry_point: "application") ⇒ Object
Link tags for preloading all modules marked as preload: true in the ‘iconmap` (defaults to Rails.application.iconmap), such that they’ll be fetched in advance by browsers supporting this link type (caniuse.com/?search=modulepreload).
-
#javascript_iconmap_tags(entry_point = "application", iconmap: Rails.application.iconmap) ⇒ Object
Setup all script tags needed to use an iconmap-powered entrypoint (which defaults to application.js).
-
#javascript_import_module_tag(*module_names) ⇒ Object
Import a named JavaScript module(s) using a script-module tag.
-
#javascript_inline_iconmap_tag(iconmap_json = Rails.application.iconmap.to_json(resolver: self)) ⇒ Object
Generate an inline iconmap tag using the passed ‘iconmap_json` JSON string.
-
#javascript_module_preload_tag(*paths) ⇒ Object
Link tag(s) for preloading the JavaScript module residing in ‘*paths`.
Instance Method Details
#javascript_iconmap_module_preload_tags(iconmap = Rails.application.iconmap, entry_point: "application") ⇒ Object
Link tags for preloading all modules marked as preload: true in the ‘iconmap` (defaults to Rails.application.iconmap), such that they’ll be fetched in advance by browsers supporting this link type (caniuse.com/?search=modulepreload).
27 28 29 |
# File 'app/helpers/iconmap/iconmap_tags_helper.rb', line 27 def (iconmap = Rails.application.iconmap, entry_point: "application") javascript_module_preload_tag(*iconmap.preloaded_module_paths(resolver: self, entry_point:, cache_key: entry_point)) end |
#javascript_iconmap_tags(entry_point = "application", iconmap: Rails.application.iconmap) ⇒ Object
Setup all script tags needed to use an iconmap-powered entrypoint (which defaults to application.js)
3 4 5 6 7 8 9 |
# File 'app/helpers/iconmap/iconmap_tags_helper.rb', line 3 def (entry_point = "application", iconmap: Rails.application.iconmap) safe_join [ javascript_inline_iconmap_tag(iconmap.to_json(resolver: self)), (iconmap, entry_point:), javascript_import_module_tag(entry_point) ], "\n" end |
#javascript_import_module_tag(*module_names) ⇒ Object
Import a named JavaScript module(s) using a script-module tag.
19 20 21 22 |
# File 'app/helpers/iconmap/iconmap_tags_helper.rb', line 19 def javascript_import_module_tag(*module_names) imports = Array(module_names).collect { |m| %(import "#{m}") }.join("\n") tag.script imports.html_safe, type: "module", nonce: request&.content_security_policy_nonce end |
#javascript_inline_iconmap_tag(iconmap_json = Rails.application.iconmap.to_json(resolver: self)) ⇒ Object
Generate an inline iconmap tag using the passed ‘iconmap_json` JSON string. By default, `Rails.application.iconmap.to_json(resolver: self)` is used.
13 14 15 16 |
# File 'app/helpers/iconmap/iconmap_tags_helper.rb', line 13 def javascript_inline_iconmap_tag(iconmap_json = Rails.application.iconmap.to_json(resolver: self)) tag.script iconmap_json.html_safe, type: "iconmap", "data-turbo-track": "reload", nonce: request&.content_security_policy_nonce end |
#javascript_module_preload_tag(*paths) ⇒ Object
Link tag(s) for preloading the JavaScript module residing in ‘*paths`. Will return one link tag per path element.
32 33 34 35 36 |
# File 'app/helpers/iconmap/iconmap_tags_helper.rb', line 32 def javascript_module_preload_tag(*paths) safe_join(Array(paths).collect { |path| tag.link rel: "modulepreload", href: path, nonce: request&.content_security_policy_nonce }, "\n") end |