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
- #bordered_table_style(node, klass) ⇒ Object
- #colgroup(node, table) ⇒ Object
-
#make_tr_attr(cell, row, totalrows, header, bordered) ⇒ 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;.
- #make_tr_attr_style(row, rowmax, totalrows, _header, bordered) ⇒ Object
- #table_attrs(node) ⇒ Object
- #table_attrs_style(node, klass) ⇒ Object
- #table_bordered?(node) ⇒ Boolean
- #table_parse(node, out) ⇒ Object
- #table_parse_core(node, out) ⇒ Object
- #table_parse_tail(node, out) ⇒ Object
- #table_title_parse(node, out) ⇒ Object
- #tbody_parse(node, table) ⇒ Object
- #tcaption(node, table) ⇒ Object
- #tfoot_parse(node, table) ⇒ Object
- #thead_parse(node, table) ⇒ Object
- #tr_parse(node, out, ord, totalrows, header) ⇒ Object
Instance Method Details
#bordered_table_style(node, klass) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/isodoc/function/table.rb', line 43 def bordered_table_style(node, klass) bordered = "border-width:1px;border-spacing:0;" (node["plain"] != "true" && (%w(modspec).include?(klass) || !klass)) or bordered = "" bordered end |
#colgroup(node, table) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/isodoc/function/table.rb', line 76 def colgroup(node, table) colgroup = node.at(ns("./colgroup")) or return table.colgroup do |cg| colgroup.xpath(ns("./col")).each do |c| cg.col style: "width: #{c['width']};" end end end |
#make_tr_attr(cell, row, totalrows, header, bordered) ⇒ 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;
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/isodoc/function/table.rb', line 117 def make_tr_attr(cell, row, totalrows, header, bordered) style = cell.name == "th" ? "font-weight:bold;" : "" cell["style"] and style += "#{cell['style']};" cell["align"] and style += "text-align:#{cell['align']};" cell["valign"] and style += "vertical-align:#{cell['valign']};" rowmax = cell["rowspan"] ? row + cell["rowspan"].to_i - 1 : row style += make_tr_attr_style(row, rowmax, totalrows, header, bordered) header and scope = (cell["colspan"] ? "colgroup" : "col") !header && cell.name == "th" and scope = (cell["rowspan"] ? "rowgroup" : "row") { rowspan: cell["rowspan"], colspan: cell["colspan"], style: style.delete("\n"), scope: scope, class: cell["class"] } end |
#make_tr_attr_style(row, rowmax, totalrows, _header, bordered) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/isodoc/function/table.rb', line 131 def make_tr_attr_style(row, rowmax, totalrows, _header, bordered) bordered or return "" <<~STYLE.delete("\n") border-top:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'} border-bottom:#{SW} #{rowmax >= totalrows ? '1.5' : '1.0'}pt; STYLE end |
#table_attrs(node) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/isodoc/function/table.rb', line 50 def table_attrs(node) c = node["class"] style = table_attrs_style(node, c) attr_code(id: node["id"], class: node["plain"] == "true" ? nil : (c || "MsoISOTable"), style: style, title: node["alt"]) end |
#table_attrs_style(node, klass) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/isodoc/function/table.rb', line 58 def table_attrs_style(node, klass) width = node["width"] ? "width:#{node['width']};" : nil bordered = bordered_table_style(node, klass) style = node["style"] ? "" : "#{bordered}#{width}" style += keep_style(node) || "" style.empty? and style = nil style end |
#table_bordered?(node) ⇒ Boolean
139 140 141 142 143 |
# File 'lib/isodoc/function/table.rb', line 139 def table_bordered?(node) node.parent.parent["plain"] == "true" and return false c = node.parent.parent["class"] %w(modspec).include?(c) || !c end |
#table_parse(node, out) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/isodoc/function/table.rb', line 85 def table_parse(node, out) @in_table = true table_title_parse(node, out) out.table **table_attrs(node) do |t| table_parse_core(node, t) table_parse_tail(node, t) end @in_table = false end |
#table_parse_core(node, out) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/isodoc/function/table.rb', line 103 def table_parse_core(node, out) tcaption(node, out) colgroup(node, out) thead_parse(node, out) tbody_parse(node, out) tfoot_parse(node, out) end |
#table_parse_tail(node, out) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/isodoc/function/table.rb', line 95 def table_parse_tail(node, out) (dl = node.at(ns("./dl"))) && parse(dl, out) node.xpath(ns("./fmt-source")).each { |n| parse(n, out) } node.xpath(ns("./note")).each { |n| parse(n, out) } node.xpath(ns("./fmt-footnote-container/fmt-fn-body")) .each { |n| parse(n, out) } end |
#table_title_parse(node, out) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/isodoc/function/table.rb', line 4 def table_title_parse(node, out) name = node.at(ns("./fmt-name")) or return out.p class: "TableTitle", style: "text-align:center;" do |p| name&.children&.each { |n| parse(n, p) } end end |
#tbody_parse(node, table) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/isodoc/function/table.rb', line 22 def tbody_parse(node, table) tbody = node.at(ns("./tbody")) or return rowcount = tbody.xpath(ns("./tr")).size table.tbody do |h| tbody.element_children.each_with_index do |n, i| tr_parse(n, h, i, rowcount, false) end end end |
#tcaption(node, table) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/isodoc/function/table.rb', line 67 def tcaption(node, table) node["summary"] or return table.caption do |c| c.span style: "display:none" do |s| s << node["summary"] end end end |
#tfoot_parse(node, table) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/isodoc/function/table.rb', line 32 def tfoot_parse(node, table) tfoot = node.at(ns("./tfoot")) if tfoot table.tfoot do |h| tfoot.element_children.each_with_index do |n, i| tr_parse(n, h, i, tfoot.xpath(ns("./tr")).size, false) end end end end |
#thead_parse(node, table) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/isodoc/function/table.rb', line 11 def thead_parse(node, table) thead = node.at(ns("./thead")) if thead table.thead do |h| thead.element_children.each_with_index do |n, i| tr_parse(n, h, i, thead.xpath(ns("./tr")).size, true) end end end end |
#tr_parse(node, out, ord, totalrows, header) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/isodoc/function/table.rb', line 145 def tr_parse(node, out, ord, totalrows, header) bordered = table_bordered?(node) out.tr **attr_code(style: node["style"]) do |r| node.elements.each do |td| attrs = make_tr_attr(td, ord, totalrows - 1, header, bordered) r.send td.name, **attr_code(attrs) do |entry| td.children.each { |n| parse(n, entry) } end end end end |