Class: CKEditor5::Rails::Assets::AssetsImportMap
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Assets::AssetsImportMap
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb
Instance Attribute Summary collapse
-
#bundle ⇒ Object
readonly
Returns the value of attribute bundle.
Instance Method Summary collapse
-
#initialize(bundle) ⇒ AssetsImportMap
constructor
A new instance of AssetsImportMap.
- #to_html ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(bundle) ⇒ AssetsImportMap
Returns a new instance of AssetsImportMap.
79 80 81 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 79 def initialize(bundle) @bundle = bundle end |
Instance Attribute Details
#bundle ⇒ Object (readonly)
Returns the value of attribute bundle.
77 78 79 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 77 def bundle @bundle end |
Instance Method Details
#to_html ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 93 def to_html tag.script( to_json.html_safe, type: 'importmap', nonce: true ) end |
#to_json(*_args) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 83 def to_json(*_args) import_map = bundle.scripts.each_with_object({}) do |script, map| next if !script.esm? || looks_like_url?(script.import_name) map[script.import_name] = script.url end { imports: import_map }.to_json end |