Class: TestStepReferenceColumn
- Inherits:
-
ControlledTableColumn
- Object
- TextLineBuilderContext
- TextLine
- ControlledTableColumn
- TestStepReferenceColumn
- Defined in:
- lib/almirah/doc_items/controlled_table.rb
Constant Summary
Constants included from HtmlSafe
Instance Attribute Summary collapse
-
#parent_row ⇒ Object
Returns the value of attribute parent_row.
-
#up_link_doc_ids ⇒ Object
Returns the value of attribute up_link_doc_ids.
-
#up_link_ids ⇒ Object
Returns the value of attribute up_link_ids.
Attributes inherited from ControlledTableColumn
Instance Method Summary collapse
-
#dangling?(link_id) ⇒ Boolean
An uplink to a paragraph missing from an existing specification, per the owning document's wrong-links collection (ENH-225).
-
#initialize(parent_row, text) ⇒ TestStepReferenceColumn
constructor
A new instance of TestStepReferenceColumn.
- #link_class(link_id) ⇒ Object
- #link_title(link_id, resolved_title) ⇒ Object
- #to_html ⇒ Object
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(parent_row, text) ⇒ TestStepReferenceColumn
Returns a new instance of TestStepReferenceColumn.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 52 def initialize(parent_row, text) super(text) @up_link_ids = nil @up_link_doc_ids = {} @parent_row = parent_row up_links = nil # check if it contains the uplink (one or many) first_pos = text.length # for trailing commas tmp = text.scan(/(>\[(?>[^\[\]]|\g<0>)*\])/) # >[SRS-001], >[SYS-002] unless tmp.empty? up_links = [] tmp.each do |ul| lnk = ul[0] # do not add links for the self document doc_id = /([a-zA-Z]+)-\d+/.match(lnk) # SRS up_links << lnk.upcase if doc_id # (doc_id) and (doc_id[1].downcase != doc.id.downcase) # try to find the real end of text pos = text.index(lnk) first_pos = pos if pos < first_pos # remove uplink from text text = text.split(lnk, 1).join('') end # remove trailing commas and spaces if text.length > first_pos first_pos -= 1 text = text[0..first_pos].strip end end if up_links # rubocop:disable Style/GuardClause up_links.uniq! # remove duplicates # doc.items_with_uplinks_number += 1 # for statistics up_links.each do |ul| next unless tmp = />\[(\S*)\]$/.match(ul) # >[SRS-001] up_link_id = tmp[1] @up_link_ids ||= [] @up_link_ids.append(up_link_id) if tmp = /^([a-zA-Z]+)-\d+/.match(up_link_id) # SRS @up_link_doc_ids[tmp[1].downcase.to_s] = tmp[1].downcase # multiple documents could be up-linked end end end end |
Instance Attribute Details
#parent_row ⇒ Object
Returns the value of attribute parent_row.
50 51 52 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 50 def parent_row @parent_row end |
#up_link_doc_ids ⇒ Object
Returns the value of attribute up_link_doc_ids.
50 51 52 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 50 def up_link_doc_ids @up_link_doc_ids end |
#up_link_ids ⇒ Object
Returns the value of attribute up_link_ids.
50 51 52 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 50 def up_link_ids @up_link_ids end |
Instance Method Details
#dangling?(link_id) ⇒ Boolean
An uplink to a paragraph missing from an existing specification, per the owning document's wrong-links collection (ENH-225). The cell renders it with the wrong-links red background and the broken-link style, keeping the link to the target document clickable.
141 142 143 144 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 141 def dangling?(link_id) doc = @parent_row.parent_doc doc.respond_to?(:wrong_links_hash) && doc.wrong_links_hash.key?(link_id) end |
#link_class(link_id) ⇒ Object
146 147 148 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 146 def link_class(link_id) dangling?(link_id) ? 'external broken_link' : 'external' end |
#link_title(link_id, resolved_title) ⇒ Object
150 151 152 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 150 def link_title(link_id, resolved_title) dangling?(link_id) ? 'Linked item does not exist' : resolved_title end |
#to_html ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/almirah/doc_items/controlled_table.rb', line 102 def to_html s = '' specifications_path = @parent_row.parent_doc.specifications_path if @up_link_ids cell_style = 'text-align: center;' cell_style += ' background-color: #fcc;' if @up_link_ids.any? { |lnk| dangling?(lnk) } if @up_link_ids.length == 1 if tmp = /^([a-zA-Z]+)-\d+/.match(@up_link_ids[0]) up_link_doc_name = tmp[1].downcase end s += "\t\t<td class=\"item_id\" style=\"#{cell_style}\">\ <a href=\"#{specifications_path}#{up_link_doc_name}/#{up_link_doc_name}.html##{@up_link_ids[0]}\" \ class=\"#{link_class(@up_link_ids[0])}\" title=\"#{link_title(@up_link_ids[0], 'Linked to')}\">#{@up_link_ids[0]}</a></td>\n" else s += "\t\t<td class=\"item_id\" style=\"#{cell_style}\">" s += "<div id=\"COV_#{@parent_row.id}\" style=\"display: block;\">" s += "<a href=\"#\" onclick=\"coverageLink_OnClick(this.parentElement); return false;\" \ class=\"external\" title=\"Number of verified items\">#{@up_link_ids.length}</a>" s += '</div>' s += "<div id=\"COVS_#{@parent_row.id}\" style=\"display: none;\">" @up_link_ids.each do |lnk| if tmp = /^([a-zA-Z]+)-\d+/.match(lnk) up_link_doc_name = tmp[1].downcase end s += "\t\t\t<a href=\"#{specifications_path}#{up_link_doc_name}/#{up_link_doc_name}.html##{lnk}\" \ class=\"#{link_class(lnk)}\" title=\"#{link_title(lnk, 'Verifies')}\">#{lnk}</a>\n<br>" end s += '</div>' s += "</td>\n" end else "\t\t<td style=\"text-align: center;\"></td>\n\r" end end |