Class: CKEditor5::Rails::Assets::AssetsImportMap

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bundleObject (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_htmlObject



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