Sha256: 0aeb7afbbe061050d2775415cf2a8adf1060ef7817514de325e14276abf2b724

Contents?: true

Size: 1.23 KB

Versions: 8

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeNumberedTable
  class V1

    def bake(table:, number:, always_caption: false)
      Kitchen::Directions::BakeTableBody.v1(table: table, number: number)

      # 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)
        new_caption = <<~HTML
          \n<span class="os-caption">#{caption.children}</span>
        HTML
      elsif always_caption
        new_caption = <<~HTML
          \n<span class="os-caption"></span>
        HTML
      end

      return if table.unnumbered?

      table.append(sibling:
        <<~HTML
          <div class="os-caption-container">
            <span class="os-title-label">#{I18n.t(:table_label)} </span>
            <span class="os-number">#{number}</span>
            <span class="os-divider"> </span>#{caption_title}
            <span class="os-divider"> </span>#{new_caption}
          </div>
        HTML
      )
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
openstax_kitchen-9.2.0 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-9.1.0 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-9.0.0 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-8.0.1 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-8.0.0 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-7.0.0 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-6.1.0 lib/kitchen/directions/bake_numbered_table/v1.rb
openstax_kitchen-6.0.0 lib/kitchen/directions/bake_numbered_table/v1.rb