Module: Metanorma::Standoc::Lists

Included in:
Converter
Defined in:
lib/metanorma/converter/lists.rb

Instance Method Summary collapse

Instance Method Details

#colist(node) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/metanorma/converter/lists.rb', line 121

def colist(node)
  noko do |xml|
    node.items.each_with_index do |item, i|
      xml.callout_annotation **attr_code(id: i + 1) do |xml_li|
        xml_li.p { |p| p << item.text }
      end
    end
  end
end

#dd(ddefn, xml_dl) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/metanorma/converter/lists.rb', line 90

def dd(ddefn, xml_dl)
  if ddefn.nil?
    xml_dl.dd
    return
  end
  xml_dl.dd **dl_attrs(ddefn) do |xml_dd|
    xml_dd.p { |t| t << ddefn.text } if ddefn.text?
    xml_dd << ddefn.content if ddefn.blocks?
  end
end

#dl_attrs(node) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/metanorma/converter/lists.rb', line 101

def dl_attrs(node)
  attr_code(id_attr(node).merge(keep_attrs(node)
    .merge(
      metadata: node.option?("metadata") ? "true" : nil,
      key: node.option?("key") ? "true" : nil,
    )))
end

#dlist(node) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/metanorma/converter/lists.rb', line 109

def dlist(node)
  noko do |xml|
    xml.dl **dl_attrs(node) do |xml_dl|
      list_caption(node, xml_dl)
      node.items.each do |terms, dd|
        dt(terms, xml_dl)
        dd(dd, xml_dl)
      end
    end
  end
end

#dt(terms, xml_dl) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/metanorma/converter/lists.rb', line 81

def dt(terms, xml_dl)
  terms.each_with_index do |dt, idx|
    xml_dl.dt { |xml_dt| xml_dt << dt.text }
    if idx < terms.size - 1
      xml_dl.dd
    end
  end
end

#li(xml_ul, item) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/metanorma/converter/lists.rb', line 4

def li(xml_ul, item)
  xml_ul.li do |xml_li|
    if item.blocks?
      xml_li.p(**attr_code(id_attr(item))) { |t| t << item.text }
      xml_li << item.content
    else
      xml_li.p(**attr_code(id_attr(item))) { |t| t << item.text }
    end
  end
end

#list_caption(node, out) ⇒ Object



131
132
133
# File 'lib/metanorma/converter/lists.rb', line 131

def list_caption(node, out)
  block_title(node, out)
end

#ol_attrs(node) ⇒ Object

node.attributes == node.style only if style explicitly set as a positional attribute



62
63
64
65
66
67
68
69
70
# File 'lib/metanorma/converter/lists.rb', line 62

def ol_attrs(node)
  attr_code(id_attr(node).merge(keep_attrs(node)
    .merge(type: olist_style(node.style),
           start: node.attr("start"),
           display: node.attr("display"),
           class: node.attr("class"),
           "display-directives": node.attr("display-directives"),
           "explicit-type": olist_style(node.attributes[1]))))
end

#olist(node) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/metanorma/converter/lists.rb', line 72

def olist(node)
  noko do |xml|
    xml.ol **ol_attrs(node) do |xml_ol|
      list_caption(node, xml_ol)
      node.items.each { |item| li(xml_ol, item) }
    end
  end
end

#olist_style(style) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/metanorma/converter/lists.rb', line 50

def olist_style(style)
  style = style&.to_s
  return "alphabet" if style == "loweralpha"
  return "roman" if style == "lowerroman"
  return "roman_upper" if style == "upperroman"
  return "alphabet_upper" if style == "upperalpha"

  style
end

#ul_attrs(node) ⇒ Object



24
25
26
27
28
29
# File 'lib/metanorma/converter/lists.rb', line 24

def ul_attrs(node)
  attr_code(id_attr(node).merge(keep_attrs(node)
    .merge(display: node.attr("display"),
           class: node.attr("class"),
           "display-directives": node.attr("display-directives"))))
end

#ul_li(xml_ul, item) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/metanorma/converter/lists.rb', line 15

def ul_li(xml_ul, item)
  xml_ul.li **ul_li_attrs(item) do |xml_li|
    xml_li.p(**attr_code(id_attr(item))) { |t| t << item.text }
    if item.blocks?
      xml_li << item.content
    end
  end
end

#ul_li_attrs(node) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/metanorma/converter/lists.rb', line 31

def ul_li_attrs(node)
  c = node.attr?("checked")
  attr_code(
    uncheckedcheckbox: node.attr?("checkbox") ? !c : nil,
    checkedcheckbox: node.attr?("checkbox") ? c : nil,
  )
end

#ulist(node) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/metanorma/converter/lists.rb', line 39

def ulist(node)
  return reference(node) if in_norm_ref? || in_biblio?

  noko do |xml|
    xml.ul **ul_attrs(node) do |xml_ul|
      list_caption(node, xml_ul)
      node.items.each { |item| ul_li(xml_ul, item) }
    end
  end
end