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

Instance Method Details

#colgroup(node, table) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/isodoc/function/table.rb', line 61

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) ⇒ 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;



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/isodoc/function/table.rb', line 92

def make_tr_attr(cell, row, totalrows, header)
  style = cell.name == "th" ? "font-weight:bold;" : ""
  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 += "    border-top:\#{row.zero? ? \"\#{SW} 1.5pt;\" : 'none;'}\n    border-bottom:\#{SW} \#{rowmax == totalrows ? '1.5' : '1.0'}pt;\n  STYLE\n  header and scope = (cell[\"colspan\"] ? \"colgroup\" : \"col\")\n  !header and cell.name == \"th\" and scope =\n                                      (cell[\"rowspan\"] ? \"rowgroup\" : \"row\")\n  { rowspan: cell[\"rowspan\"], colspan: cell[\"colspan\"],\n    style: style.gsub(/\\n/, \"\"), scope: scope }\nend\n"

#table_attrs(node) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/isodoc/function/table.rb', line 41

def table_attrs(node)
  width = node["width"] ? "width:#{node['width']};" : nil
  attr_code(
    id: node["id"],
    class: "MsoISOTable",
    style: "border-width:1px;border-spacing:0;#{width}#{keep_style(node)}",
    title: node["alt"],
  )
end

#table_parse(node, out) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/isodoc/function/table.rb', line 70

def table_parse(node, out)
  @in_table = true
  table_title_parse(node, out)
  out.table **table_attrs(node) do |t|
    tcaption(node, t)
    colgroup(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 << "&nbsp;" }
end

#table_title_parse(node, out) ⇒ Object



3
4
5
6
7
8
# File 'lib/isodoc/function/table.rb', line 3

def table_title_parse(node, out)
  name = node.at(ns("./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



21
22
23
24
25
26
27
28
# File 'lib/isodoc/function/table.rb', line 21

def tbody_parse(node, table)
  tbody = node.at(ns("./tbody")) || return
  table.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, table) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/function/table.rb', line 51

def tcaption(node, table)
  return unless node["summary"]

  table.caption do |c|
    c.span **{ style: "display:none" } do |s|
      s << node["summary"]
    end
  end
end

#tfoot_parse(node, table) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/isodoc/function/table.rb', line 30

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.element_children.size, false)
      end
    end
  end
end

#thead_parse(node, table) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/isodoc/function/table.rb', line 10

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.element_children.size, true)
      end
    end
  end
end

#tr_parse(node, out, ord, totalrows, header) ⇒ Object



108
109
110
111
112
113
114
115
116
117
# File 'lib/isodoc/function/table.rb', line 108

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