Class: Kitchen::Directions::BakeIframes::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_iframes/v1.rb

Instance Method Summary collapse

Instance Method Details

#bake(outer_element:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kitchen/directions/bake_iframes/v1.rb', line 5

def bake(outer_element:)
  iframes = outer_element.search('iframe')
  return unless iframes.any?

  iframes.each do |iframe|
    next if iframe.has_class?('os-is-iframe')

    iframe.wrap('<div class="os-has-iframe" data-type="alternatives">')
    iframe.add_class('os-is-iframe')
    link_ref = iframe[:src]
    next unless link_ref

    iframe = iframe.parent
    iframe.add_class('os-has-link')
    iframe.prepend(child:
      <<~HTML
        <a class="os-is-link" href="#{link_ref}" target="_window">#{I18n.t(:iframe_link_text)}</a>
      HTML
    )
  end
end