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

#make_table_attr(node) ⇒ Object



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

def make_table_attr(node)
  attr_code(
    id: node["id"],
    class: "MsoISOTable",
    border: 1,
    cellspacing: 0,
    cellpadding: 0,
    title: node["alt"]
  )
end

#make_tr_attr(td, row, totalrows) ⇒ 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;



82
83
84
85
86
87
88
89
90
91
# File 'lib/isodoc/function/table.rb', line 82

def make_tr_attr(td, row, totalrows)
  style = td.name == "th" ? "font-weight:bold;" : ""
  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;
  STYLE
  { rowspan: td["rowspan"], colspan: td["colspan"],
    align: td["align"], style: style.gsub(/\n/, "") }
end

#table_parse(node, out) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/isodoc/function/table.rb', line 62

def table_parse(node, out)
  @in_table = true
  table_title_parse(node, out)
  out.table **make_table_attr(node) do |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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/isodoc/function/table.rb', line 4

def table_title_parse(node, out)
  name = node.at(ns("./name"))
  out.p **{ class: "TableTitle", align: "center" } do |p|
    lbl = anchor(node['id'], :label, false)
    lbl.nil? or p << l10n("#{@table_lbl} #{lbl}")
    name and !lbl.nil? and p << l10n("&nbsp;&mdash; ")
=begin
    get_anchors[node['id']][:label].nil? or
      p << l10n("#{@table_lbl} #{get_anchors[node['id']][:label]}")
    name and !get_anchors[node['id']][:label].nil? and
      p << l10n("&nbsp;&mdash; ")
=end
    name and name.children.each { |n| parse(n, p) }
  end
end

#tbody_parse(node, t) ⇒ Object



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

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

#tfoot_parse(node, t) ⇒ Object



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

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



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

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



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

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)
      # i, node.elements.size - 1, header)
      r.send td.name, **attr_code(attrs) do |entry|
        td.children.each { |n| parse(n, entry) }
      end
    end
  end
end