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_attrs(node) ⇒ Object
- #dl_parse(node, out) ⇒ Object
- #dl_parse1(dlist, dterm, ddef) ⇒ Object
- #dl_parse_notes(node, out) ⇒ Object
- #dt_dd?(node) ⇒ Boolean
- #dt_parse(dterm, term) ⇒ Object
- #li_checkbox(node) ⇒ Object
- #li_parse(node, out) ⇒ Object
- #list_title_parse(node, out) ⇒ Object
- #ol_attrs(node) ⇒ Object
-
#ol_depthx(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) Fallback, this is now being done in Presentation XML KILL.
- #ol_parse(node, out) ⇒ Object
- #ol_style(type) ⇒ Object
- #ul_attrs(node) ⇒ Object
- #ul_parse(node, out) ⇒ Object
Instance Method Details
#dl_attrs(node) ⇒ Object
102 103 104 |
# File 'lib/isodoc/function/lists.rb', line 102 def dl_attrs(node) attr_code(id: node["id"], style: keep_style(node), class: node["class"]) end |
#dl_parse(node, out) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/isodoc/function/lists.rb', line 106 def dl_parse(node, out) out.div **attr_code(class: "figdl") do |div| list_title_parse(node, div) div.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 dl_parse_notes(node, div) end end |
#dl_parse1(dlist, dterm, ddef) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/function/lists.rb', line 123 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 |
#dl_parse_notes(node, out) ⇒ Object
118 119 120 121 |
# File 'lib/isodoc/function/lists.rb', line 118 def dl_parse_notes(node, out) node.elements.reject { |n| dt_dd?(n) || n.name == "fmt-name" } .each { |n| parse(n, out) } end |
#dt_dd?(node) ⇒ Boolean
98 99 100 |
# File 'lib/isodoc/function/lists.rb', line 98 def dt_dd?(node) %w{dt dd}.include? node.name end |
#dt_parse(dterm, term) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/function/lists.rb', line 88 def dt_parse(dterm, term) if dterm.elements.empty? term.p do |p| dterm.children.each { |n| parse(n, p) } end else dterm.children.each { |n| parse(n, term) } end end |
#li_checkbox(node) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/isodoc/function/lists.rb', line 67 def li_checkbox(node) if node["uncheckedcheckbox"] == "true" '<span class="zzMoveToFollowing">' \ '<input type="checkbox" checked="checked"/></span>' elsif node["checkedcheckbox"] == "true" '<span class="zzMoveToFollowing">' \ '<input type="checkbox"/></span>' else "" end end |
#li_parse(node, out) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/isodoc/function/lists.rb', line 78 def li_parse(node, out) out.li **attr_code(id: node["id"]) do |li| li << li_checkbox(node) node.children.each do |n| n.name == "fmt-name" and next parse(n, li) end 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("./fmt-name")) or return out.p class: "ListTitle" do |p| name.children&.each { |n| parse(n, p) } end end |
#ol_attrs(node) ⇒ Object
52 53 54 55 56 |
# File 'lib/isodoc/function/lists.rb', line 52 def ol_attrs(node) { # type: node["type"] ? ol_style(node["type"].to_sym) : ol_depth(node), type: ol_style(node["type"]&.to_sym), id: node["id"], style: keep_style(node) } end |
#ol_depthx(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) Fallback, this is now being done in Presentation XML KILL
42 43 44 45 46 47 48 49 50 |
# File 'lib/isodoc/function/lists.rb', line 42 def ol_depthx(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
58 59 60 61 62 63 64 65 |
# File 'lib/isodoc/function/lists.rb', line 58 def ol_parse(node, out) out.div **attr_code(class: "ol_wrap") do |div| list_title_parse(node, div) div.ol **attr_code(ol_attrs(node)) do |ol| node.children.each { |n| n.name == "fmt-name" or parse(n, ol) } end end end |
#ol_style(type) ⇒ Object
32 33 34 35 |
# File 'lib/isodoc/function/lists.rb', line 32 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 21 22 |
# File 'lib/isodoc/function/lists.rb', line 15 def ul_parse(node, out) out.div **attr_code(class: "ul_wrap") do |div| list_title_parse(node, div) div.ul **attr_code(ul_attrs(node)) do |ul| node.children.each { |n| n.name == "fmt-name" or parse(n, ul) } end end end |