Module: IsoDoc::Unece::BaseConvert
- Included in:
- HtmlConvert, PdfConvert, WordConvert
- Defined in:
- lib/isodoc/unece/base_convert.rb
Constant Summary collapse
- MIDDLE_CLAUSE =
"//clause[parent::sections]".freeze
Instance Method Summary collapse
- #admonition_name_parse(node, div, name) ⇒ Object
- #admonition_parse(node, out) ⇒ Object
- #annex_leaf_section(clause, num, lvl) ⇒ Object
- #annex_levelnumber(num, lvl) ⇒ Object
- #annex_name(annex, name, div) ⇒ Object
- #annex_name_lbl(clause, num) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #back_anchor_names(docxml) ⇒ Object
- #clause_names(docxml, sect_num) ⇒ Object
- #fileloc(loc) ⇒ Object
- #hierarchical_admonition_names(clause, num) ⇒ Object
- #hierarchical_asset_names(clause, num) ⇒ Object
- #i18n_init(lang, script) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
- #inline_header_title(out, node, c1) ⇒ Object
- #leaf_section(clause, lvl) ⇒ Object
- #levelnumber(num, lvl) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #section_names(clause, num, lvl) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #sequential_admonition_names(clause) ⇒ Object
- #sequential_asset_names(clause) ⇒ Object
Instance Method Details
#admonition_name_parse(node, div, name) ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/isodoc/unece/base_convert.rb', line 184 def admonition_name_parse(node, div, name) div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p| lbl = anchor(node['id'], :label) lbl.nil? or p << l10n("#{@admonition_lbl} #{lbl}") name and !lbl.nil? and p << " — " name and name.children.each { |n| parse(n, div) } end end |
#admonition_parse(node, out) ⇒ Object
193 194 195 196 197 198 199 200 201 |
# File 'lib/isodoc/unece/base_convert.rb', line 193 def admonition_parse(node, out) name = node.at(ns("./name")) out.div **{ class: "Admonition" } do |t| admonition_name_parse(node, t, name) if name node.children.each do |n| parse(n, t) unless n.name == "name" end end end |
#annex_leaf_section(clause, num, lvl) ⇒ Object
75 76 77 78 |
# File 'lib/isodoc/unece/base_convert.rb', line 75 def annex_leaf_section(clause, num, lvl) @paranumber += 1 @anchors[clause["id"]] = {label: @paranumber.to_s, xref: "paragraph #{num}.#{@paranumber}", level: lvl, type: "paragraph" } end |
#annex_levelnumber(num, lvl) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/isodoc/unece/base_convert.rb', line 62 def annex_levelnumber(num, lvl) case lvl % 3 when 0 then RomanNumerals.to_roman(num) when 1 then ("A".ord + num - 1).chr when 2 then num.to_s end end |
#annex_name(annex, name, div) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/isodoc/unece/base_convert.rb', line 13 def annex_name(annex, name, div) div.h1 **{ class: "Annex" } do |t| t << "#{anchor(annex['id'], :label)}" t.br t.b do |b| name&.children&.each { |c2| parse(c2, b) } end end end |
#annex_name_lbl(clause, num) ⇒ Object
110 111 112 |
# File 'lib/isodoc/unece/base_convert.rb', line 110 def annex_name_lbl(clause, num) l10n("<b>#{@annex_lbl} #{num}</b>") end |
#annex_names(clause, num) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/isodoc/unece/base_convert.rb', line 114 def annex_names(clause, num) hierarchical_asset_names(clause, num) unless clause.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) annex_leaf_section(clause, num, 1) and return end @anchors[clause["id"]] = { label: annex_name_lbl(clause, num), type: "clause", xref: "#{@annex_lbl} #{num}", level: 1 } i = 1 clause.xpath(ns("./clause")).each do |c| annex_names1(c, "#{num}.#{annex_levelnumber(i, 2)}", 2) i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) end end |
#annex_names1(clause, num, level) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/isodoc/unece/base_convert.rb', line 128 def annex_names1(clause, num, level) unless clause.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) annex_leaf_section(clause, num, level) and return end /\.(?<leafnum>[^.]+$)/ =~ num @anchors[clause["id"]] = { label: leafnum, xref: "#{@annex_lbl} #{num}", level: level, type: "clause" } i = 1 clause.xpath(ns("./clause | ./references")).each do |c| annex_names1(c, "#{num}.#{annex_levelnumber(i, level + 1)}", level + 1) i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) end end |
#back_anchor_names(docxml) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/isodoc/unece/base_convert.rb', line 142 def back_anchor_names(docxml) docxml.xpath(ns("//annex")).each_with_index do |c, i| @paranumber = 0 annex_names(c, RomanNumerals.to_roman(i + 1)) end docxml.xpath(ns("//bibliography/clause |"\ "//bibliography/references")).each do |b| preface_names(b) end docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref| reference_names(ref) end end |
#clause_names(docxml, sect_num) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/isodoc/unece/base_convert.rb', line 46 def clause_names(docxml, sect_num) q = "//clause[parent::sections]" @paranumber = 0 docxml.xpath(ns(q)).each_with_index do |c, i| section_names(c, (i + sect_num), 1) end end |
#fileloc(loc) ⇒ Object
29 30 31 |
# File 'lib/isodoc/unece/base_convert.rb', line 29 def fileloc(loc) File.join(File.dirname(__FILE__), loc) end |
#hierarchical_admonition_names(clause, num) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/isodoc/unece/base_convert.rb', line 165 def hierarchical_admonition_names(clause, num) i = 0 clause.xpath(ns(".//admonition")).each do |t| i += 1 unless t["unnumbered"] next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct("#{num}.#{i}", nil, @admonition_lbl, "box", t["unnumbered"]) end end |
#hierarchical_asset_names(clause, num) ⇒ Object
179 180 181 182 |
# File 'lib/isodoc/unece/base_convert.rb', line 179 def hierarchical_asset_names(clause, num) super hierarchical_admonition_names(clause, num) end |
#i18n_init(lang, script) ⇒ Object
23 24 25 26 27 |
# File 'lib/isodoc/unece/base_convert.rb', line 23 def i18n_init(lang, script) super @admonition_lbl = "Box" @abstract_lbl = "Summary" end |
#initial_anchor_names(d) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/isodoc/unece/base_convert.rb', line 35 def initial_anchor_names(d) preface_names(d.at(ns("//abstract"))) preface_names(d.at(ns("//foreword"))) preface_names(d.at(ns("//introduction"))) sequential_asset_names(d.xpath(ns("//foreword | //introduction"))) middle_section_asset_names(d) clause_names(d, 0) termnote_anchor_names(d) termexample_anchor_names(d) end |
#inline_header_title(out, node, c1) ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/isodoc/unece/base_convert.rb', line 203 def inline_header_title(out, node, c1) title = c1&.content || "" out.span **{ class: "zzMoveToFollowing" } do |s| if lbl = anchor(node['id'], :label) s << "#{lbl}. " unless @suppressheadingnumbers insert_tab(s, 1) end s << "#{title} " end end |
#leaf_section(clause, lvl) ⇒ Object
70 71 72 73 |
# File 'lib/isodoc/unece/base_convert.rb', line 70 def leaf_section(clause, lvl) @paranumber += 1 @anchors[clause["id"]] = {label: @paranumber.to_s, xref: "paragraph #{@paranumber}", level: lvl, type: "paragraph" } end |
#levelnumber(num, lvl) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/isodoc/unece/base_convert.rb', line 54 def levelnumber(num, lvl) case lvl % 3 when 1 then RomanNumerals.to_roman(num) when 2 then ("A".ord + num - 1).chr when 0 then num.to_s end end |
#metadata_init(lang, script, labels) ⇒ Object
8 9 10 11 |
# File 'lib/isodoc/unece/base_convert.rb', line 8 def (lang, script, labels) @meta = Metadata.new(lang, script, labels) @meta.set(:toc, @toc) end |
#section_names(clause, num, lvl) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/isodoc/unece/base_convert.rb', line 80 def section_names(clause, num, lvl) return num if clause.nil? clause.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) or leaf_section(clause, lvl) && return num = num + 1 lbl = levelnumber(num, 1) @anchors[clause["id"]] = { label: lbl, xref: l10n("#{@clause_lbl} #{lbl}"), level: lvl, type: "clause" } i = 1 clause.xpath(ns("./clause | ./term | ./terms | ./definitions | ./references")).each do |c| section_names1(c, "#{lbl}.#{levelnumber(i, lvl + 1)}", lvl + 1) i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) end num end |
#section_names1(clause, num, level) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/isodoc/unece/base_convert.rb', line 96 def section_names1(clause, num, level) unless clause.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) leaf_section(clause, level) and return end /\.(?<leafnum>[^.]+$)/ =~ num @anchors[clause["id"]] = { label: leafnum, level: level, xref: l10n("#{@clause_lbl} #{num}"), type: "clause" } i = 1 clause.xpath(ns("./clause | ./terms | ./term | ./definitions | ./references")).each do |c| section_names1(c, "#{num}.#{levelnumber(i, level + 1)}", level + 1) i += 1 if c.at(ns("./clause | ./term | ./terms | ./definitions | ./references")) end end |
#sequential_admonition_names(clause) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/isodoc/unece/base_convert.rb', line 156 def sequential_admonition_names(clause) i = 0 clause.xpath(ns(".//admonition")).each do |t| i += 1 unless t["unnumbered"] next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct(i.to_s, nil, @admonition_lbl, "box", t["unnumbered"]) end end |
#sequential_asset_names(clause) ⇒ Object
174 175 176 177 |
# File 'lib/isodoc/unece/base_convert.rb', line 174 def sequential_asset_names(clause) super sequential_admonition_names(clause) end |