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:, always_caption: false, cases: false) ⇒ 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
# File 'lib/kitchen/directions/bake_numbered_table/v1.rb', line 6

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

  # 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 = "      \\n<span class=\"os-title\" data-type=\"title\">\#{title.children}</span>\n    HTML\n  end\n\n  if (caption = table.caption&.cut) && !caption&.children&.to_s&.blank?\n    new_caption = <<~HTML\n      \\n<span class=\"os-caption\">\#{caption.children}</span>\n    HTML\n  elsif always_caption\n    new_caption = <<~HTML\n      \\n<span class=\"os-caption\"></span>\n    HTML\n  end\n\n  return if table.unnumbered?\n\n  table.append(sibling:\n    <<~HTML\n      <div class=\"os-caption-container\">\n        <span class=\"os-title-label\">\#{I18n.t(\"table\#{'.nominative' if cases}\")} </span>\n        <span class=\"os-number\">\#{number}</span>\n        <span class=\"os-divider\"> </span>\#{caption_title}\n        <span class=\"os-divider\"> </span>\#{new_caption}\n      </div>\n    HTML\n  )\n\n  table.parent.add_class('os-timeline-table-container') if table.has_class?('timeline-table')\nend\n"