Class: Roll::Amp::Script::IncludeScriptTag

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::OutputSafetyHelper
Defined in:
lib/roll/amp/script/include_script_tag.rb

Overview

The script tag to include AMP scripts. Note, it’s always async.

Direct Known Subclasses

AmpJsTag, AnalyticsScriptTag

Instance Method Summary collapse

Constructor Details

#initialize(src, custom_element = '') ⇒ IncludeScriptTag

Initializes new instance of the include script tag.

Parameters:

  • src (String)

    the URL to the script.

  • custom_element (String) (defaults to: '')

    the custom-element attribute value.



13
14
15
16
# File 'lib/roll/amp/script/include_script_tag.rb', line 13

def initialize(src, custom_element = '')
  @src = src
  @custom_element = custom_element
end

Instance Method Details

#to_htmlString

Prints this tag as HTML.

Returns:

  • (String)

    HTML-safe string containing the tag’s HTML view.



20
21
22
23
24
25
26
27
28
29
# File 'lib/roll/amp/script/include_script_tag.rb', line 20

def to_html
  if @custom_element.empty?
    raw("<script async src=\"#{@src}\"></script>")
  else
    raw(
      "<script async src=\"#{@src}\" " \
      "custom-element=\"#{@custom_element}\"></script>"
    )
  end
end