Module: IsoDoc::Iso::BaseConvert
- Included in:
- HtmlConvert, WordConvert
- Defined in:
- lib/isodoc/iso/sections.rb,
lib/isodoc/iso/base_convert.rb
Instance Method Summary collapse
- #anchor_names(docxml) ⇒ Object
- #annex(isoxml, out) ⇒ Object
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #appendix_names(clause, num) ⇒ Object
- #clause_parse_title(node, div, c1, out) ⇒ Object
- #clausedelim ⇒ Object
- #cleanup(docxml) ⇒ Object
- #convert1(docxml, filename, dir) ⇒ Object
- #eref_localities1(target, type, from, to, delim, lang = "en") ⇒ Object
- #eref_localities1_zh(target, type, from, to, delim) ⇒ Object
-
#error_parse(node, out) ⇒ Object
terms not defined in standoc.
- #example_p_parse(node, div) ⇒ Object
- #example_parse(node, out) ⇒ Object
- #example_parse1(node, div) ⇒ Object
- #example_span_label(node, div, name) ⇒ Object
- #foreword(isoxml, out) ⇒ Object
- #hierarchical_formula_names(clause, num) ⇒ Object
- #implicit_reference(b) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
- #insertall_after_here(node, insert, name) ⇒ Object
- #introduction(isoxml, out) ⇒ Object
-
#introduction_names(clause) ⇒ Object
we can reference 0-number clauses in introduction.
- #metadata_init(lang, script, labels) ⇒ Object
- #middle_title(out) ⇒ Object
- #middle_title_amd(out) ⇒ Object
- #middle_title_main(out) ⇒ Object
- #node_begins_with_para(node) ⇒ Object
- #prefix_container(container, linkend, target) ⇒ Object
- #reference_names(ref) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #table_footnote_reference_format(a) ⇒ Object
- #table_th_center(docxml) ⇒ Object
- #termdef_parse(node, out) ⇒ Object
- #termexamples_before_termnotes(node) ⇒ Object
Instance Method Details
#anchor_names(docxml) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isodoc/iso/base_convert.rb', line 23 def anchor_names(docxml) if @amd back_anchor_names(docxml) note_anchor_names(docxml.xpath(ns("//annex//table | //annex//figure"))) note_anchor_names(docxml.xpath(ns("//annex"))) example_anchor_names(docxml.xpath(ns("//annex"))) list_anchor_names(docxml.xpath(ns("//annex"))) else super end end |
#annex(isoxml, out) ⇒ Object
32 33 34 35 36 |
# File 'lib/isodoc/iso/sections.rb', line 32 def annex(isoxml, out) @amd and @suppressheadingnumbers = @oldsuppressheadingnumbers super @amd and @suppressheadingnumbers = true end |
#annex_names(clause, num) ⇒ Object
61 62 63 64 |
# File 'lib/isodoc/iso/base_convert.rb', line 61 def annex_names(clause, num) appendix_names(clause, num) super end |
#annex_names1(clause, num, level) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/isodoc/iso/base_convert.rb', line 84 def annex_names1(clause, num, level) @anchors[clause["id"]] = { label: num, xref: num, level: level } clause.xpath(ns("./clause | ./references")).each_with_index do |c, i| annex_names1(c, "#{num}.#{i + 1}", level + 1) end end |
#appendix_names(clause, num) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/isodoc/iso/base_convert.rb', line 66 def appendix_names(clause, num) clause.xpath(ns("./appendix")).each_with_index do |c, i| @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl, "clause") @anchors[c["id"]][:level] = 2 @anchors[c["id"]][:container] = clause["id"] end end |
#clause_parse_title(node, div, c1, out) ⇒ Object
60 61 62 63 |
# File 'lib/isodoc/iso/sections.rb', line 60 def clause_parse_title(node, div, c1, out) return inline_header_title(out, node, c1) if c1.nil? super end |
#clausedelim ⇒ Object
191 192 193 |
# File 'lib/isodoc/iso/base_convert.rb', line 191 def clausedelim "" end |
#cleanup(docxml) ⇒ Object
205 206 207 208 209 |
# File 'lib/isodoc/iso/base_convert.rb', line 205 def cleanup(docxml) super table_th_center(docxml) docxml end |
#convert1(docxml, filename, dir) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/isodoc/iso/base_convert.rb', line 13 def convert1(docxml, filename, dir) doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text @amd = %w(amendment technical-corrigendum).include? doctype if @amd @oldsuppressheadingnumbers = @suppressheadingnumbers @suppressheadingnumbers = true end super end |
#eref_localities1(target, type, from, to, delim, lang = "en") ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/isodoc/iso/base_convert.rb', line 103 def eref_localities1(target, type, from, to, delim, lang = "en") subsection = from&.text&.match(/\./) type = type.downcase return l10n(eref_localities1_zh(target, type, from, to, delim)) if lang == "zh" ret = (delim == ";") ? ";" : (type == "list") ? "" : delim loc = @locality[type] || type.sub(/^locality:/, "").capitalize ret += " #{loc}" unless subsection && type == "clause" || type == "list" || target.match(/^IEV$|^IEC 60050-/) ret += " #{from.text}" if from ret += "–#{to.text}" if to ret += ")" if type == "list" l10n(ret) end |
#eref_localities1_zh(target, type, from, to, delim) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/isodoc/iso/base_convert.rb', line 91 def eref_localities1_zh(target, type, from, to, delim) subsection = from&.text&.match(/\./) ret = (delim == ";") ? ";" : (type == "list") ? "" : delim ret += " 第#{from.text}" if from ret += "–#{to}" if to loc = (@locality[type] || type.sub(/^locality:/, "").capitalize ) ret += " #{loc}" unless subsection && type == "clause" || type == "list" || target.match(/^IEV$|^IEC 60050-/) ret += ")" if type == "list" ret end |
#error_parse(node, out) ⇒ Object
terms not defined in standoc
53 54 55 56 57 58 59 |
# File 'lib/isodoc/iso/base_convert.rb', line 53 def error_parse(node, out) case node.name when "appendix" then clause_parse(node, out) else super end end |
#example_p_parse(node, div) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/isodoc/iso/base_convert.rb', line 133 def example_p_parse(node, div) name = node&.at(ns("./name"))&.remove div.p do |p| example_span_label(node, p, name) insert_tab(p, 1) node.first_element_child.children.each { |n| parse(n, p) } end node.element_children[1..-1].each { |n| parse(n, div) } end |
#example_parse(node, out) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/isodoc/iso/base_convert.rb', line 160 def example_parse(node, out) out.div **{ id: node["id"], class: "example" } do |div| if node_begins_with_para(node) example_p_parse(node, div) else example_parse1(node, div) end end end |
#example_parse1(node, div) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/isodoc/iso/base_convert.rb', line 143 def example_parse1(node, div) div.p do |p| example_span_label(node, p, node.at(ns("./name"))) insert_tab(p, 1) end node.children.each { |n| parse(n, div) unless n.name == "name" } end |
#example_span_label(node, div, name) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/isodoc/iso/base_convert.rb', line 122 def example_span_label(node, div, name) n = get_anchors[node["id"]] div.span **{ class: "example_label" } do |p| lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl : l10n("#{@example_lbl} #{n[:label]}") p << lbl name and !lbl.nil? and p << " — " name and name.children.each { |n| parse(n, div) } end end |
#foreword(isoxml, out) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/isodoc/iso/sections.rb', line 51 def foreword(isoxml, out) f = isoxml.at(ns("//foreword")) || return page_break(out) out.div **attr_code(id: f["id"]) do |s| s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl } f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#hierarchical_formula_names(clause, num) ⇒ Object
218 219 220 221 222 223 224 225 226 227 |
# File 'lib/isodoc/iso/base_convert.rb', line 218 def hierarchical_formula_names(clause, num) c = IsoDoc::Function::XrefGen::Counter.new clause.xpath(ns(".//formula")).each do |t| next if t["id"].nil? || t["id"].empty? @anchors[t["id"]] = anchor_struct("#{num}#{hiersep}#{c.increment(t).print}", t, t["inequality"] ? @inequality_lbl : @formula_lbl, "formula", t["unnumbered"]) end end |
#implicit_reference(b) ⇒ Object
35 36 37 |
# File 'lib/isodoc/iso/base_convert.rb', line 35 def implicit_reference(b) b&.at(ns("./docidentifier"))&.text == "IEV" end |
#initial_anchor_names(d) ⇒ Object
39 40 41 42 |
# File 'lib/isodoc/iso/base_convert.rb', line 39 def initial_anchor_names(d) super introduction_names(d.at(ns("//introduction"))) end |
#insertall_after_here(node, insert, name) ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'lib/isodoc/iso/base_convert.rb', line 170 def insertall_after_here(node, insert, name) node.children.each do |n| next unless n.name == name insert.next = n.remove insert = n end insert end |
#introduction(isoxml, out) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/isodoc/iso/sections.rb', line 38 def introduction(isoxml, out) f = isoxml.at(ns("//introduction")) || return num = f.at(ns(".//clause")) ? "0" : nil title_attr = { class: "IntroTitle" } page_break(out) out.div **{ class: "Section3", id: f["id"] } do |div| clause_name(num, @introduction_lbl, div, title_attr) f.elements.each do |e| parse(e, div) unless e.name == "title" end end end |
#introduction_names(clause) ⇒ Object
we can reference 0-number clauses in introduction
45 46 47 48 49 50 |
# File 'lib/isodoc/iso/base_convert.rb', line 45 def introduction_names(clause) return if clause.nil? clause.xpath(ns("./clause")).each_with_index do |c, i| section_names1(c, "0.#{i + 1}", 2) end end |
#metadata_init(lang, script, labels) ⇒ Object
9 10 11 |
# File 'lib/isodoc/iso/base_convert.rb', line 9 def (lang, script, labels) @meta = Metadata.new(lang, script, labels) end |
#middle_title(out) ⇒ Object
4 5 6 7 |
# File 'lib/isodoc/iso/sections.rb', line 4 def middle_title(out) middle_title_main(out) middle_title_amd(out) end |
#middle_title_amd(out) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/isodoc/iso/sections.rb', line 22 def middle_title_amd(out) a = @meta.get[:doctitleamdlabel] and out.p(**{ class: "zzSTDTitle2" }) do |p| p << a a = @meta.get[:doctitleamd] and p << ": #{a}" end a = @meta.get[:doctitlecorrlabel] and out.p(**{ class: "zzSTDTitle2" }) do |p| p << a end end |
#middle_title_main(out) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/isodoc/iso/sections.rb', line 9 def middle_title_main(out) out.p(**{ class: "zzSTDTitle1" }) do |p| p << @meta.get[:doctitleintro] p << " — " if @meta.get[:doctitleintro] && @meta.get[:doctitlemain] p << @meta.get[:doctitlemain] p << " — " if @meta.get[:doctitlemain] && @meta.get[:doctitlepart] end a = @meta.get[:doctitlepart] and out.p(**{ class: "zzSTDTitle2" }) do |p| b = @meta.get[:doctitlepartlabel] and p << "#{b}: " p << "<br/><b>#{a}</b>" end end |
#node_begins_with_para(node) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/isodoc/iso/base_convert.rb', line 151 def node_begins_with_para(node) node.elements.each do |e| next if e.name == "name" return true if e.name == "p" return false end false end |
#prefix_container(container, linkend, target) ⇒ Object
117 118 119 120 |
# File 'lib/isodoc/iso/base_convert.rb', line 117 def prefix_container(container, linkend, target) delim = anchor(target, :type) == "listitem" ? " " : ", " l10n(anchor(container, :xref) + delim + linkend) end |
#reference_names(ref) ⇒ Object
195 196 197 198 199 |
# File 'lib/isodoc/iso/base_convert.rb', line 195 def reference_names(ref) super @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref]. sub(/ \(All Parts\)/i, "") } end |
#section_names1(clause, num, level) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/isodoc/iso/base_convert.rb', line 74 def section_names1(clause, num, level) @anchors[clause["id"]] = { label: num, level: level, xref: num } # subclauses are not prefixed with "Clause" clause.xpath(ns("./clause | ./terms | ./term | ./definitions | ./references")). each_with_index do |c, i| section_names1(c, "#{num}.#{i + 1}", level + 1) end end |
#table_footnote_reference_format(a) ⇒ Object
201 202 203 |
# File 'lib/isodoc/iso/base_convert.rb', line 201 def table_footnote_reference_format(a) a.content = a.content + ")" end |
#table_th_center(docxml) ⇒ Object
211 212 213 214 215 216 |
# File 'lib/isodoc/iso/base_convert.rb', line 211 def table_th_center(docxml) docxml.xpath("//thead//th | //thead//td").each do |th| th["align"] = "center" th["valign"] = "middle" end end |
#termdef_parse(node, out) ⇒ Object
186 187 188 189 |
# File 'lib/isodoc/iso/base_convert.rb', line 186 def termdef_parse(node, out) termexamples_before_termnotes(node) super end |
#termexamples_before_termnotes(node) ⇒ Object
179 180 181 182 183 184 |
# File 'lib/isodoc/iso/base_convert.rb', line 179 def termexamples_before_termnotes(node) return unless node.at(ns("./termnote")) && node.at(ns("./termexample")) return unless insert = node.at(ns("./definition")) insert = insertall_after_here(node, insert, "termexample") insert = insertall_after_here(node, insert, "termnote") end |