Module: IsoDoc::Function::Lists

Included in:
Common
Defined in:
lib/isodoc/function/lists.rb

Constant Summary collapse

OL_STYLE =
{
  arabic: "1",
  roman: "i",
  alphabet: "a",
  roman_upper: "I",
  alphabet_upper: "A",
}.freeze

Instance Method Summary collapse

Instance Method Details

#dl_attrs(node) ⇒ Object



89
90
91
# File 'lib/isodoc/function/lists.rb', line 89

def dl_attrs(node)
  attr_code(id: node["id"], style: keep_style(node), class: node["class"])
end

#dl_parse(node, out) ⇒ Object



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

def dl_parse(node, out)
  list_title_parse(node, out)
  out.dl **dl_attrs(node) do |v|
    node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
      dl_parse1(v, dt, dd)
    end
  end
  node.elements.reject { |n| dt_dd?(n) || n.name == "name" }
    .each { |n| parse(n, out) }
end

#dl_parse1(dlist, dterm, ddef) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/isodoc/function/lists.rb', line 104

def dl_parse1(dlist, dterm, ddef)
  dlist.dt **attr_code(id: dterm["id"]) do |term|
    dt_parse(dterm, term)
  end
  dlist.dd **attr_code(id: ddef["id"]) do |listitem|
    ddef.children.each { |n| parse(n, listitem) }
  end
end

#dt_dd?(node) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/isodoc/function/lists.rb', line 85

def dt_dd?(node)
  %w{dt dd}.include? node.name
end

#dt_parse(dterm, term) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/isodoc/function/lists.rb', line 74

def dt_parse(dterm, term)
  if dterm.elements.empty?
    # term.p **attr_code(class: note? ? "Note" : nil) do |p|
    term.p do |p|
      p << dterm.text
    end
  else
    dterm.children.each { |n| parse(n, term) }
  end
end

#li_parse(node, out) ⇒ Object



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

def li_parse(node, out)
  out.li **attr_code(id: node["id"]) do |li|
    if node["uncheckedcheckbox"] == "true"
      li << '<span class="zzMoveToFollowing">'\
            '<input type="checkbox" checked="checked"/></span>'
    elsif node["checkedcheckbox"] == "true"
      li << '<span class="zzMoveToFollowing">'\
            '<input type="checkbox"/></span>'
    end
    node.children.each { |n| parse(n, li) }
  end
end

#list_title_parse(node, out) ⇒ Object



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

def list_title_parse(node, out)
  name = node.at(ns("./name")) or return
  out.p **{ class: "ListTitle" } do |p|
    name&.children&.each { |n| parse(n, p) }
  end
end

#ol_attrs(node) ⇒ Object



49
50
51
52
# File 'lib/isodoc/function/lists.rb', line 49

def ol_attrs(node)
  { type: node["type"] ? ol_style(node["type"].to_sym) : ol_depth(node),
    id: node["id"], style: keep_style(node) }
end

#ol_depth(node) ⇒ Object

We don’t really want users to specify type of ordered list; we will use a fixed hierarchy as practiced by ISO (though not fully spelled out): a) 1) i) A) I)



39
40
41
42
43
44
45
46
47
# File 'lib/isodoc/function/lists.rb', line 39

def ol_depth(node)
  depth = node.ancestors("ul, ol").size + 1
  type = :alphabet
  type = :arabic if [2, 7].include? depth
  type = :roman if [3, 8].include? depth
  type = :alphabet_upper if [4, 9].include? depth
  type = :roman_upper if [5, 10].include? depth
  ol_style(type)
end

#ol_parse(node, out) ⇒ Object



54
55
56
57
58
59
# File 'lib/isodoc/function/lists.rb', line 54

def ol_parse(node, out)
  list_title_parse(node, out)
  out.ol **attr_code(ol_attrs(node)) do |ol|
    node.children.each { |n| n.name == "name" or parse(n, ol) }
  end
end

#ol_style(type) ⇒ Object



30
31
32
33
# File 'lib/isodoc/function/lists.rb', line 30

def ol_style(type)
  type ||= :alphabet
  OL_STYLE[type.to_sym]
end

#ul_attrs(node) ⇒ Object



11
12
13
# File 'lib/isodoc/function/lists.rb', line 11

def ul_attrs(node)
  { id: node["id"], style: keep_style(node) }
end

#ul_parse(node, out) ⇒ Object



15
16
17
18
19
20
# File 'lib/isodoc/function/lists.rb', line 15

def ul_parse(node, out)
  list_title_parse(node, out)
  out.ul **attr_code(ul_attrs(node)) do |ul|
    node.children.each { |n| n.name == "name" or parse(n, ul) }
  end
end