Class: Kitchen::Directions::BakeNumberedTable::V1

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

Instance Method Summary collapse

Instance Method Details

#bake(table:, number:, cases: false, move_caption_on_top: false, label_class: nil) ⇒ Object



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
40
41
42
43
44
45
46
# File 'lib/kitchen/directions/bake_numbered_table/v1.rb', line 6

def bake(table:, number:, cases: false, move_caption_on_top: false, label_class: nil)
  Kitchen::Directions::BakeTableBody::V1.new.bake(table: table,
                                                  number: number,
                                                  cases: cases,
                                                  label_class: label_class)

  # TODO: extra spaces added here to match legacy implementation, but probably not meaningful?
  new_caption = ''
  caption_title = ''

  if (title = table.first("span[data-type='title']")&.cut)
    caption_title = <<~HTML
      \n<span class="os-title" data-type="title">#{title.children}</span>
    HTML
  end

  if (caption = table.caption&.cut) && !caption&.children&.to_s&.blank?
    new_caption = <<~HTML
      \n<span class="os-caption">#{caption.children}</span>
    HTML
  end

  return if table.unnumbered?

  sibling = <<~HTML
    <div class="os-caption-container">
      <span class="os-title-label">#{I18n.t("table#{'.nominative' if cases}")} </span>
      <span class="os-number">#{number}</span>
      <span class="os-divider"> </span>#{caption_title}
      <span class="os-divider"> </span>#{new_caption}
    </div>
  HTML

  move_caption_on_top ? table.prepend(sibling: sibling) : table.append(sibling: sibling)

  return unless table.baked_caption

  Kitchen::Directions::BakeAsideInCaption.v1(
    caption_container: table.baked_caption
  )
end