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(nonce: nil) ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(bundle) ⇒ AssetsImportMap
Returns a new instance of AssetsImportMap.
98 99 100 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 98 def initialize(bundle) @bundle = bundle end |
Instance Attribute Details
#bundle ⇒ Object (readonly)
Returns the value of attribute bundle.
96 97 98 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 96 def bundle @bundle end |
Instance Method Details
#to_html(nonce: nil) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 112 def to_html(nonce: nil) tag.script( to_json.html_safe, type: 'importmap', nonce: nonce ) end |
#to_json(*_args) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 102 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 |