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



77
78
79
# File 'lib/isodoc/function/lists.rb', line 77

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

#dl_parse(node, out) ⇒ Object



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

def dl_parse(node, out)
  out.dl  **dl_attrs(node) do |v|
    node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
      v.dt **attr_code(id: dt["id"]) do |term|
        dt_parse(dt, term) 
      end
      v.dd  **attr_code(id: dd["id"]) do |listitem|
        dd.children.each { |n| parse(n, listitem) }
      end
    end
  end
  node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, out) }
end

#dt_dd?(n) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/isodoc/function/lists.rb', line 73

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

#dt_parse(dt, term) ⇒ Object



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

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

#li_parse(node, out) ⇒ Object



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

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

#ol_attrs(node) ⇒ Object



40
41
42
43
# File 'lib/isodoc/function/lists.rb', line 40

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)



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

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



45
46
47
48
49
# File 'lib/isodoc/function/lists.rb', line 45

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

#ol_style(type) ⇒ Object



21
22
23
24
# File 'lib/isodoc/function/lists.rb', line 21

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

#ul_attrs(node) ⇒ Object



3
4
5
# File 'lib/isodoc/function/lists.rb', line 3

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

#ul_parse(node, out) ⇒ Object



7
8
9
10
11
# File 'lib/isodoc/function/lists.rb', line 7

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