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
- #dl_attr(node) ⇒ Object
- #dl_parse(node, out) ⇒ Object
- #dt_dd?(n) ⇒ Boolean
- #dt_parse(dt, term) ⇒ Object
- #li_parse(node, out) ⇒ Object
-
#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).
- #ol_parse(node, out) ⇒ Object
- #ol_style(type) ⇒ Object
- #ul_parse(node, out) ⇒ Object
Instance Method Details
#dl_attr(node) ⇒ Object
65 66 67 |
# File 'lib/isodoc/function/lists.rb', line 65 def dl_attr(node) attr_code(id: node["id"]) end |
#dl_parse(node, out) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/isodoc/function/lists.rb', line 69 def dl_parse(node, out) out.dl **dl_attr(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
61 62 63 |
# File 'lib/isodoc/function/lists.rb', line 61 def dt_dd?(n) %w{dt dd}.include? n.name end |
#dt_parse(dt, term) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/isodoc/function/lists.rb', line 50 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
44 45 46 47 48 |
# File 'lib/isodoc/function/lists.rb', line 44 def li_parse(node, out) out.li **attr_code(id: node["id"]) do |li| node.children.each { |n| parse(n, li) } end 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)
27 28 29 30 31 32 33 34 35 |
# File 'lib/isodoc/function/lists.rb', line 27 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
37 38 39 40 41 42 |
# File 'lib/isodoc/function/lists.rb', line 37 def ol_parse(node, out) style = ol_depth(node) out.ol **attr_code(type: style, id: node["id"] ) do |ol| node.children.each { |n| parse(n, ol) } end end |
#ol_style(type) ⇒ Object
18 19 20 21 |
# File 'lib/isodoc/function/lists.rb', line 18 def ol_style(type) type = :alphabet unless type OL_STYLE[type.to_sym] end |
#ul_parse(node, out) ⇒ Object
4 5 6 7 8 |
# File 'lib/isodoc/function/lists.rb', line 4 def ul_parse(node, out) out.ul **attr_code(id: node["id"]) do |ul| node.children.each { |n| parse(n, ul) } end end |