Class: Kitchen::Directions::BakeAnnotationClasses::V1

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

Instance Method Summary collapse

Instance Method Details

#bake(book:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kitchen/directions/bake_annotation_classes/v1.rb', line 5

def bake(book:)
  book.search('p.annotation').each do |annotation|
    annotation.wrap_children('span', class: 'os-text')
    annotation.prepend(child:
      <<~HTML
        <div class="os-icons"></div>
      HTML
    )
  end
  annotation_icon_classes = %w[linguistic-icon
                               culture-icon
                               dreaming-icon
                               visual-icon
                               speech-icon
                               auditory-icon
                               kinesthetic-icon]
  annotation_icon_classes.each do |annotation_icon_class|
    book.search("p.#{annotation_icon_class}").each do |annotation_with_icon_class|
      annotation_with_icon_class.search('div.os-icons').first&.name = 'span'

      icon_title = I18n.t(:"annotation_icons.#{annotation_icon_class}.title")

      annotation_with_icon_class.search('span.os-icons').first.append(child:
        <<~HTML
          <span
            class = "#{annotation_icon_class}"
            role="img"
            title="#{icon_title}"
            aria-label="#{icon_title}"
          ></span>
        HTML
      )
    end
  end
end