Class: ScopeTable

Inherits:
ControlledTable show all
Defined in:
lib/almirah/doc_items/scope_table.rb

Overview

Purpose-built controlled table for a Decision Record's # Scope section (ADR-210, slimmed to presentation only by ADR-222). It is modelled on ControlledTable but addresses its columns by header text (not position): it locates # and Depends On wherever the author placed them, along with the date columns whose cells are kept on one line (ENH-214).

Rendering is the table's whole job: the # column is an anchored row number so individual Scope rows can be linked, and each Depends On reference renders as a clickable link to the referenced record.

Constant Summary

Constants included from HtmlSafe

HtmlSafe::ALLOWED_URL_SCHEMES

Instance Attribute Summary collapse

Attributes inherited from ControlledTable

#column_names, #is_separator_detected, #rows

Attributes inherited from DocItem

#parent_doc, #parent_heading

Instance Method Summary collapse

Methods inherited from ControlledTable

#format_columns

Methods inherited from DocItem

#get_url, #owner_document, #split_table_cells

Methods inherited from TextLine

#bold, #bold_and_italic, broken_links, #format_string, #inline_code, #italic, #link, link_registry, link_registry=, #literal_text, #owner_document, record_broken_link, reset_broken_links, #wiki_link

Methods included from HtmlSafe

#escape_attr, #escape_text, #safe_url

Methods inherited from TextLineBuilderContext

#bold, #bold_and_italic, #inline_code, #italic, #link, #literal_text, #wiki_link

Constructor Details

#initialize(doc, markdown_table) ⇒ ScopeTable

Returns a new instance of ScopeTable.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/almirah/doc_items/scope_table.rb', line 18

def initialize(doc, markdown_table)
  @parent_doc = doc
  @parent_heading = doc.headings[-1]
  @column_names = markdown_table.column_names
  @is_separator_detected = markdown_table.is_separator_detected
  @cells = []
  @rows = []
  @col = locate_columns(@column_names)
  # The switch to ScopeTable happens on the first data row, so the source
  # MarkdownTable carries none yet; any it did are re-read for safety.
  markdown_table.rows.each { |cells| append_cells(cells) }
end

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells.



16
17
18
# File 'lib/almirah/doc_items/scope_table.rb', line 16

def cells
  @cells
end

Instance Method Details

#add_row(row) ⇒ Object



31
32
33
34
# File 'lib/almirah/doc_items/scope_table.rb', line 31

def add_row(row)
  append_cells(split_table_cells(row).map(&:strip))
  true
end

#to_htmlObject

Render as a controlled table: an anchored, centered step number in the # column (so rows are linkable, like the protocol table) and formatted text for every other cell.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/almirah/doc_items/scope_table.rb', line 39

def to_html
  s = +''
  if @@html_table_render_in_progress
    s << "</table>\n"
    @@html_table_render_in_progress = false
  end
  s << "<table class=\"markdown_table\">\n\t<thead>"
  @column_names.each { |h| s << " <th>#{format_string(h.strip)}</th>" }
  s << " </thead>\n"
  @cells.each_with_index { |cells, i| s << row_html(cells, @rows[i]) }
  s << "</table>\n"
  s
end