Class: CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle, importmap: true) ⇒ AssetsBundleHtmlSerializer

Returns a new instance of AssetsBundleHtmlSerializer.

Raises:

  • (TypeError)


14
15
16
17
18
19
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 14

def initialize(bundle, importmap: true)
  raise TypeError, 'bundle must be an instance of AssetsBundle' unless bundle.is_a?(AssetsBundle)

  @importmap = importmap
  @bundle = bundle
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle.



12
13
14
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 12

def bundle
  @bundle
end

#importmapObject (readonly)

Returns the value of attribute importmap.



12
13
14
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 12

def importmap
  @importmap
end

Class Method Details

.url_resource_preload_type(url) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 34

def self.url_resource_preload_type(url)
  case File.extname(url)
  when '.js' then 'script'
  when '.css' then 'style'
  else 'fetch'
  end
end

Instance Method Details

#to_htmlObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ckeditor5/rails/assets/assets_bundle_html_serializer.rb', line 21

def to_html
  tags = [
    preload_tags,
    styles_tags,
    window_scripts_tags,
    web_component_tag
  ]

  tags.prepend(AssetsImportMap.new(bundle).to_html) if importmap

  safe_join(tags)
end