Class: ArticleJSON::Export::AMP::CustomElementLibraryResolver
- Inherits:
-
Object
- Object
- ArticleJSON::Export::AMP::CustomElementLibraryResolver
- Defined in:
- lib/article_json/export/amp/custom_element_library_resolver.rb
Overview
AMP uses custom HTML tags for elements like iframes or embedded youtube videos. These elements each require a javascript to be loaded to be properly rendered by the browser. This class resolves the custom tags to a list of javascript libraries which then can be included on the page.
Instance Method Summary collapse
-
#initialize(custom_element_tags) ⇒ CustomElementLibraryResolver
constructor
A new instance of CustomElementLibraryResolver.
-
#script_tags ⇒ Array[String]
Return all custom library script tags required for the given custom element tags.
-
#sources ⇒ Hash[Symbol => String]
List of all custom tags with their library source URI.
Constructor Details
#initialize(custom_element_tags) ⇒ CustomElementLibraryResolver
Returns a new instance of CustomElementLibraryResolver.
10 11 12 |
# File 'lib/article_json/export/amp/custom_element_library_resolver.rb', line 10 def initialize() @custom_element_tags = end |
Instance Method Details
#script_tags ⇒ Array[String]
Return all custom library script tags required for the given custom element tags
26 27 28 29 30 31 32 33 34 |
# File 'lib/article_json/export/amp/custom_element_library_resolver.rb', line 26 def sources.map do |custom_element_tag, src| <<-HTML.gsub(/\s+/, ' ').strip <script async custom-element="#{custom_element_tag}" src="#{src}"></script> HTML end end |
#sources ⇒ Hash[Symbol => String]
List of all custom tags with their library source URI
16 17 18 19 20 21 |
# File 'lib/article_json/export/amp/custom_element_library_resolver.rb', line 16 def sources @custom_element_tags.each_with_object({}) do |custom_element, mapping| src = custom_element_script_mapping(custom_element) mapping[custom_element] = src if src end end |