Module: IsoDoc::Function::Table
- Included in:
- Common
- Defined in:
- lib/isodoc/function/table.rb
Constant Summary collapse
- SW =
"solid windowtext".freeze
Instance Method Summary collapse
- #make_table_attr(node) ⇒ Object
-
#make_tr_attr(td, row, totalrows, header) ⇒ Object
def make_tr_attr(td, row, totalrows, cols, totalcols, header) border-left:#? “#{SW 1.5pt;” : “none;”} border-right:#SW #== totalcols && !header ? “1.5” : “1.0”pt;.
- #table_parse(node, out) ⇒ Object
- #table_title_parse(node, out) ⇒ Object
- #tbody_parse(node, t) ⇒ Object
- #tcaption(node, t) ⇒ Object
- #tfoot_parse(node, t) ⇒ Object
- #thead_parse(node, t) ⇒ Object
- #tr_parse(node, out, ord, totalrows, header) ⇒ Object
Instance Method Details
#make_table_attr(node) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/isodoc/function/table.rb', line 47 def make_table_attr(node) attr_code( id: node["id"], class: "MsoISOTable", style: "border-width:1px;border-spacing:0;", title: node["alt"] ) end |
#make_tr_attr(td, row, totalrows, header) ⇒ Object
def make_tr_attr(td, row, totalrows, cols, totalcols, header) border-left:#? “#{SW 1.5pt;” : “none;”} border-right:#SW #== totalcols && !header ? “1.5” : “1.0”pt;
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/isodoc/function/table.rb', line 86 def make_tr_attr(td, row, totalrows, header) style = td.name == "th" ? "font-weight:bold;" : "" td["align"] and style += "text-align:#{td['align']};" rowmax = td["rowspan"] ? row + td["rowspan"].to_i - 1 : row style += <<~STYLE border-top:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'} border-bottom:#{SW} #{rowmax == totalrows ? '1.5' : '1.0'}pt; padding:0; STYLE header and scope = (td["colspan"] ? "colgroup" : "col") !header and td.name == "th" and scope = (td["rowspan"] ? "rowgroup" : "row") { rowspan: td["rowspan"], colspan: td["colspan"], style: style.gsub(/\n/, ""), scope: scope } end |
#table_parse(node, out) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/isodoc/function/table.rb', line 65 def table_parse(node, out) @in_table = true table_title_parse(node, out) out.table **make_table_attr(node) do |t| (node, t) thead_parse(node, t) tbody_parse(node, t) tfoot_parse(node, t) (dl = node.at(ns("./dl"))) && parse(dl, out) node.xpath(ns("./note")).each { |n| parse(n, out) } end @in_table = false # out.p { |p| p << " " } end |
#table_title_parse(node, out) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/isodoc/function/table.rb', line 4 def table_title_parse(node, out) name = node.at(ns("./name")) lbl = anchor(node['id'], :label, false) lbl = nil if labelled_ancestor(node) return if name.nil? && lbl.nil? out.p **{ class: "TableTitle", style: "text-align:center;" } do |p| lbl.nil? or p << l10n("#{@table_lbl} #{lbl}") name and !lbl.nil? and p << l10n(" — ") name and name.children.each { |n| parse(n, p) } end end |
#tbody_parse(node, t) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/isodoc/function/table.rb', line 27 def tbody_parse(node, t) tbody = node.at(ns("./tbody")) || return t.tbody do |h| tbody.element_children.each_with_index do |n, i| tr_parse(n, h, i, tbody.element_children.size, false) end end end |
#tcaption(node, t) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/isodoc/function/table.rb', line 56 def (node, t) return unless node["summary"] t. do |c| c.span **{ style: "display:none" } do |s| s << node["summary"] end end end |
#tfoot_parse(node, t) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/isodoc/function/table.rb', line 36 def tfoot_parse(node, t) tfoot = node.at(ns("./tfoot")) if tfoot t.tfoot do |h| tfoot.element_children.each_with_index do |n, i| tr_parse(n, h, i, tfoot.element_children.size, false) end end end end |
#thead_parse(node, t) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/isodoc/function/table.rb', line 16 def thead_parse(node, t) thead = node.at(ns("./thead")) if thead t.thead do |h| thead.element_children.each_with_index do |n, i| tr_parse(n, h, i, thead.element_children.size, true) end end end end |
#tr_parse(node, out, ord, totalrows, header) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/isodoc/function/table.rb', line 102 def tr_parse(node, out, ord, totalrows, header) out.tr do |r| node.elements.each do |td| attrs = make_tr_attr(td, ord, totalrows - 1, header) r.send td.name, **attr_code(attrs) do |entry| td.children.each { |n| parse(n, entry) } end end end end |