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.



84
85
86
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 84

def initialize(bundle)
  @bundle = bundle
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle.



82
83
84
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 82

def bundle
  @bundle
end

Instance Method Details

#to_htmlObject



98
99
100
101
102
103
104
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 98

def to_html
  tag.script(
    to_json.html_safe,
    type: 'importmap',
    nonce: true
  )
end

#to_json(*_args) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 88

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