Module: IsoDoc::ITU::BaseConvert
- Included in:
- HtmlConvert, PdfConvert, WordConvert
- Defined in:
- lib/isodoc/itu/base_convert.rb
Constant Summary collapse
- FRONT_CLAUSE =
"//*[parent::preface]"\ "[not(local-name() = 'abstract')]".freeze
Instance Method Summary collapse
- #annex_name(annex, name, div) ⇒ Object
- #biblio_list(f, div, bibliography) ⇒ Object
- #cleanup(docxml) ⇒ Object
- #eref_parse(node, out) ⇒ Object
- #fileloc(loc) ⇒ Object
- #get_eref_linkend(node) ⇒ Object
- #i18n_init(lang, script) ⇒ Object
- #info(isoxml, out) ⇒ Object
- #initial_anchor_names(d) ⇒ Object
- #load_yaml(lang, script) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #middle_title(out) ⇒ Object
- #noniso_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
- #norm_ref(isoxml, out, num) ⇒ Object
- #norm_ref_preface(f, div) ⇒ Object
- #preface(isoxml, out) ⇒ Object
- #split_bibitems(f) ⇒ Object
- #term_cleanup(docxml) ⇒ Object
- #term_defs_boilerplate(div, source, term, preface) ⇒ Object
- #termdef_parse(node, out) ⇒ Object
- #termdef_parse1(node, div, term, defn, source) ⇒ Object
- #terms_defs(node, out, num) ⇒ Object
- #terms_defs_title(node) ⇒ Object
- #terms_parse(node, out) ⇒ Object
Instance Method Details
#annex_name(annex, name, div) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/isodoc/itu/base_convert.rb', line 37 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 |
#biblio_list(f, div, bibliography) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/isodoc/itu/base_convert.rb', line 129 def biblio_list(f, div, bibliography) bibitems = split_bibitems(f) bibitems.each_with_index do |b, i| noniso_bibitem_entry(div, b, (i + 1), bibliography) end end |
#cleanup(docxml) ⇒ Object
55 56 57 58 |
# File 'lib/isodoc/itu/base_convert.rb', line 55 def cleanup(docxml) super term_cleanup(docxml) end |
#eref_parse(node, out) ⇒ Object
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/isodoc/itu/base_convert.rb', line 206 def eref_parse(node, out) linkend = get_eref_linkend(node) if node["type"] == "footnote" out.sup do |s| s.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend } end else out.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend } end end |
#fileloc(loc) ⇒ Object
51 52 53 |
# File 'lib/isodoc/itu/base_convert.rb', line 51 def fileloc(loc) File.join(File.dirname(__FILE__), loc) end |
#get_eref_linkend(node) ⇒ Object
198 199 200 201 202 203 204 |
# File 'lib/isodoc/itu/base_convert.rb', line 198 def get_eref_linkend(node) link = "[#{anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))}]" link += eref_localities(node.xpath(ns("./locality")), link) contents = node.children.select { |c| c.name != "locality" } return link if contents.nil? || contents.empty? Nokogiri::XML::NodeSet.new(node.document, contents).to_xml end |
#i18n_init(lang, script) ⇒ Object
47 48 49 |
# File 'lib/isodoc/itu/base_convert.rb', line 47 def i18n_init(lang, script) super end |
#info(isoxml, out) ⇒ Object
69 70 71 72 73 |
# File 'lib/isodoc/itu/base_convert.rb', line 69 def info(isoxml, out) @meta.keywords isoxml, out @meta.ip_notice_received isoxml, out super end |
#initial_anchor_names(d) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/isodoc/itu/base_convert.rb', line 75 def initial_anchor_names(d) d.xpath("//xmlns:preface/child::*").each do |c| preface_names(c) end sequential_asset_names(d.xpath("//xmlns:preface/child::*")) n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1) n = section_names(d.at(ns("//bibliography/clause[title = 'References'] | "\ "//bibliography/references[title = 'References']")), n, 1) n = section_names(d.at(ns("//sections/terms | "\ "//sections/clause[descendant::terms]")), n, 1) n = section_names(d.at(ns("//sections/definitions")), n, 1) clause_names(d, n) middle_section_asset_names(d) termnote_anchor_names(d) termexample_anchor_names(d) end |
#load_yaml(lang, script) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/itu/base_convert.rb', line 8 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")) else YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) end super.merge(y) end |
#metadata_init(lang, script, labels) ⇒ Object
18 19 20 |
# File 'lib/isodoc/itu/base_convert.rb', line 18 def (lang, script, labels) @meta = Metadata.new(lang, script, labels) end |
#middle_title(out) ⇒ Object
217 218 219 220 221 222 |
# File 'lib/isodoc/itu/base_convert.rb', line 217 def middle_title(out) out.p(**{ class: "zzSTDTitle1" }) do |p| id = @meta.get[:docidentifier] and p << "Recommendation #{id}" end out.p(**{ class: "zzSTDTitle2" }) { |p| p << @meta.get[:doctitle] } end |
#noniso_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/isodoc/itu/base_convert.rb', line 119 def noniso_bibitem_entry(list, b, ordinal, biblio) return if implicit_reference(b) list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref| ref << "[#{iso_bibitem_ref_code(b)}]" date_note_process(b, ref) insert_tab(ref, 1) reference_format(b, ref) end end |
#norm_ref(isoxml, out, num) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/isodoc/itu/base_convert.rb', line 92 def norm_ref(isoxml, out, num) q = "//bibliography/references[title = 'References']" f = isoxml.at(ns(q)) or return num out.div do |div| num = num + 1 clause_name(num, @normref_lbl, div, nil) norm_ref_preface(f, div) biblio_list(f, div, false) end num end |
#norm_ref_preface(f, div) ⇒ Object
104 105 106 |
# File 'lib/isodoc/itu/base_convert.rb', line 104 def norm_ref_preface(f, div) div.p "The following ITU-T Recommendations and other references contain provisions which, through reference in this text, constitute provisions of this Recommendation. At the time of publication, the editions indicated were valid. All Recommendations and other references are subject to revision; users of this Recommendation are therefore encouraged to investigate the possibility of applying the most recent edition of the Recommendations and other references listed below. A list of the currently valid ITU-T Recommendations is regularly published. The reference to a document within this Recommendation does not give it, as a stand-alone document, the status of a Recommendation." end |
#preface(isoxml, out) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/isodoc/itu/base_convert.rb', line 25 def preface(isoxml, out) isoxml.xpath(ns(FRONT_CLAUSE)).each do |c| title = c&.at(ns("./title")) out.div **attr_code(id: c["id"]) do |s| clause_name(nil, title&.content, s, class: "IntroTitle") c.elements.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, s) end end end end |
#split_bibitems(f) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/isodoc/itu/base_convert.rb', line 111 def split_bibitems(f) bibitem = [] f.xpath(ns("./bibitem")).each do |x| bibitem << x end bibitem end |
#term_cleanup(docxml) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/isodoc/itu/base_convert.rb', line 60 def term_cleanup(docxml) docxml.xpath("//p[@class = 'Terms']").each do |d| h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]") h2.add_child(" ") h2.add_child(d.remove) end docxml end |
#term_defs_boilerplate(div, source, term, preface) ⇒ Object
108 109 |
# File 'lib/isodoc/itu/base_convert.rb', line 108 def term_defs_boilerplate(div, source, term, preface) end |
#termdef_parse(node, out) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/isodoc/itu/base_convert.rb', line 184 def termdef_parse(node, out) term = node.at(ns("./preferred")) defn = node.at(ns("./definition")) source = node.at(ns("./termsource/origin/@citeas")) out.div **attr_code(id: node["id"]) do |div| termdef_parse1(node, div, term, defn, source) set_termdomain("") node.children.each do |n| next if %w(preferred definition termsource title).include? n.name parse(n, out) end end end |
#termdef_parse1(node, div, term, defn, source) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/isodoc/itu/base_convert.rb', line 171 def termdef_parse1(node, div, term, defn, source) div.p **{ class: "TermNum", id: node["id"] } do |p| p.b do |b| b << anchor(node["id"], :label) insert_tab(b, 1) term.children.each { |n| parse(n, b) } end source and p << " [#{source.value}]" p << ": " defn and defn.children.each { |n| parse(n, p) } end end |
#terms_defs(node, out, num) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/isodoc/itu/base_convert.rb', line 141 def terms_defs(node, out, num) f = node.at(ns(IsoDoc::Convert::TERM_CLAUSE)) or return num out.div **attr_code(id: f["id"]) do |div| num = num + 1 clause_name(num, terms_defs_title(f), div, nil) if f.at(ns("./clause | ./terms | ./term")).nil? then out.p "None." else f.children.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, div) end end end num end |
#terms_defs_title(node) ⇒ Object
136 137 138 139 |
# File 'lib/isodoc/itu/base_convert.rb', line 136 def terms_defs_title(node) t = node.at(ns("./title")) and return t.text super end |
#terms_parse(node, out) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/isodoc/itu/base_convert.rb', line 156 def terms_parse(node, out) out.div **attr_code(id: node["id"]) do |div| clause_parse_title(node, div, node.at(ns("./title")), out) title = node.at(ns("./title"))&.text&.downcase title == "terms defined elsewhere" and out.p @labels["elsewhere_terms"] title == "terms defined in this recommendation" and out.p @labels["here_terms"] if node.at(ns("./clause | ./term")).nil? then out.p "None." else node.children.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, div) end end end end |