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-194). It is modelled on ControlledTable but addresses its columns by header text (not position) and has no fixed link column: it locates #, Item, Owner, Depends On, and Status wherever the author placed them.

Each data row becomes a WorkItem (the dependency-network node). The table also keeps a plain header-addressed cell grid (cells) so the ADR-193 Scope readers (owners / WIP / dates) keep working unchanged after the Scope section stopped being a plain MarkdownTable.

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.



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

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 = []
  @work_items = []
  @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.



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

def cells
  @cells
end

#work_itemsObject (readonly)

Returns the value of attribute work_items.



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

def work_items
  @work_items
end

Instance Method Details

#add_row(row) ⇒ Object



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

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

#step_column?Boolean

True when the table has a leading # step column, hence a per-row anchor a dependent record can deep-link to (ADR-194).

Returns:

  • (Boolean)


39
40
41
# File 'lib/almirah/doc_items/scope_table.rb', line 39

def step_column?
  !@col[:step].nil?
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.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/almirah/doc_items/scope_table.rb', line 46

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, @work_items[i]) }
  s << "</table>\n"
  s
end