Class: Kitchen::Directions::BakeUnitPageTitle::V1

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

Instance Method Summary collapse

Instance Method Details

#bake(book:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/kitchen/directions/bake_unit_page_title/v1.rb', line 5

def bake(book:)
  book.units.each do |unit|
    @unit_title = I18n.t(:unit)
    @unit_number = unit.count_in(:book)
    unit.element_children.only(Kitchen::PageElement).each do |page|
      compose_unit_page_title(page: page, unit_title_prefix: @unit_title,
                              unit_number: @unit_number)
    end
  end
end

#compose_unit_page_title(page:, unit_title_prefix:, unit_number:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kitchen/directions/bake_unit_page_title/v1.rb', line 16

def compose_unit_page_title(page:, unit_title_prefix:, unit_number:)
  title = page.title
  title.name = 'h2'
  title.replace_children(with:
    <<~HTML
      <span class="os-part-text">#{unit_title_prefix} </span>
      <span class="os-number">#{unit_number}</span>
      <span class="os-divider"> </span>
      <span data-type="" itemprop="" class="os-text">#{title.text}</span>
    HTML
  )
end