Module: IsoDoc::Iso::BaseConvert
- Included in:
- HtmlConvert, WordConvert
- Defined in:
- lib/isodoc/iso/base_convert.rb
Instance Method Summary collapse
- #annex_names(clause, num) ⇒ Object
- #annex_names1(clause, num, level) ⇒ Object
- #appendix_names(clause, num) ⇒ Object
- #clausedelim ⇒ Object
- #eref_localities1(target, type, from, to, lang = "en") ⇒ Object
- #eref_localities1_zh(target, type, from, to) ⇒ 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
- #foreword(isoxml, out) ⇒ Object
- #implicit_reference(b) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
- #introduction(isoxml, out) ⇒ Object
-
#introduction_names(clause) ⇒ Object
we can reference 0-number clauses in introduction.
- #load_yaml(lang, script) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #prefix_container(container, linkend, target) ⇒ Object
- #section_names1(clause, num, level) ⇒ Object
- #term_parse(node, out) ⇒ Object
- #termexamples_before_termnotes(node) ⇒ Object
Instance Method Details
#annex_names(clause, num) ⇒ Object
66 67 68 69 |
# File 'lib/isodoc/iso/base_convert.rb', line 66 def annex_names(clause, num) appendix_names(clause, num) super end |
#annex_names1(clause, num, level) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/isodoc/iso/base_convert.rb', line 89 def annex_names1(clause, num, level) @anchors[clause["id"]] = { label: num, xref: num, level: level } clause.xpath(ns("./clause")).each_with_index do |c, i| annex_names1(c, "#{num}.#{i + 1}", level + 1) end end |
#appendix_names(clause, num) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/isodoc/iso/base_convert.rb', line 71 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 |
#clausedelim ⇒ Object
170 171 172 |
# File 'lib/isodoc/iso/base_convert.rb', line 170 def clausedelim "" end |
#eref_localities1(target, type, from, to, lang = "en") ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/isodoc/iso/base_convert.rb', line 107 def eref_localities1(target, type, from, to, lang = "en") subsection = from&.text&.match(/\./) type = type.downcase return l10n(eref_localities1_zh(target, type, from, to)) if lang == "zh" ret = type == "list" ? "" : "," 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) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/isodoc/iso/base_convert.rb', line 96 def eref_localities1_zh(target, type, from, to) subsection = from&.text&.match(/\./) ret = type == "list" ? "" : "," 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
58 59 60 61 62 63 64 |
# File 'lib/isodoc/iso/base_convert.rb', line 58 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
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/isodoc/iso/base_convert.rb', line 125 def example_p_parse(node, div) div.p do |p| p.span **{ class: "example_label" } do |s| s << example_label(node) end 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
146 147 148 149 150 151 152 153 154 |
# File 'lib/isodoc/iso/base_convert.rb', line 146 def example_parse(node, out) out.div **{ id: node["id"], class: "example" } do |div| if node.first_element_child.name == "p" example_p_parse(node, div) else example_parse1(node, div) end end end |
#example_parse1(node, div) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/isodoc/iso/base_convert.rb', line 136 def example_parse1(node, div) div.p do |p| p.span **{ class: "example_label" } do |s| s << example_label(node) end insert_tab(p, 1) end node.children.each { |n| parse(n, div) } end |
#foreword(isoxml, out) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/isodoc/iso/base_convert.rb', line 35 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 |
#implicit_reference(b) ⇒ Object
12 13 14 15 |
# File 'lib/isodoc/iso/base_convert.rb', line 12 def implicit_reference(b) isocode = b.at(ns("./docidentifier")).text isocode == "IEV" end |
#initial_anchor_names(d) ⇒ Object
44 45 46 47 |
# File 'lib/isodoc/iso/base_convert.rb', line 44 def initial_anchor_names(d) super introduction_names(d.at(ns("//introduction"))) end |
#introduction(isoxml, out) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isodoc/iso/base_convert.rb', line 17 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| # div.h1 "Introduction", **attr_code(title_attr) clause_name(num, @introduction_lbl, div, title_attr) f.elements.each do |e| if e.name == "patent-notice" e.elements.each { |e1| parse(e1, div) } else parse(e, div) unless e.name == "title" end end end end |
#introduction_names(clause) ⇒ Object
we can reference 0-number clauses in introduction
50 51 52 53 54 55 |
# File 'lib/isodoc/iso/base_convert.rb', line 50 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 |
#load_yaml(lang, script) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/isodoc/iso/base_convert.rb', line 174 def load_yaml(lang, script) y = if @i18nyaml then YAML.load_file(@i18nyaml) elsif lang == "en" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) elsif lang == "fr" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-fr.yaml")) elsif lang == "zh" && script == "Hans" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) else YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) end super.merge(y) end |
#metadata_init(lang, script, labels) ⇒ Object
8 9 10 |
# File 'lib/isodoc/iso/base_convert.rb', line 8 def (lang, script, labels) @meta = Metadata.new(lang, script, labels) end |
#prefix_container(container, linkend, target) ⇒ Object
120 121 122 123 |
# File 'lib/isodoc/iso/base_convert.rb', line 120 def prefix_container(container, linkend, target) delim = anchor(target, :type) == "listitem" ? " " : ", " l10n(anchor(container, :xref) + delim + linkend) end |
#section_names1(clause, num, level) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/isodoc/iso/base_convert.rb', line 79 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")). each_with_index do |c, i| section_names1(c, "#{num}.#{i + 1}", level + 1) end end |
#term_parse(node, out) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/isodoc/iso/base_convert.rb', line 163 def term_parse(node, out) termexamples_before_termnotes(node) out.p **{ class: "Terms", style:"text-align:left;" } do |p| node.children.each { |c| parse(c, p) } end end |
#termexamples_before_termnotes(node) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/isodoc/iso/base_convert.rb', line 156 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 |