class IsoDoc::PresentationXMLConvert
Constants
- MATHML
Public Class Methods
new(options)
click to toggle source
Calls superclass method
IsoDoc::Convert::new
# File lib/isodoc/presentation_xml_convert.rb, line 9 def initialize(options) @format = :presentation @suffix = "presentation.xml" super end
Public Instance Methods
address_precompose(bib)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 19 def address_precompose(bib) bib.xpath(ns("//bibdata//address")).each do |b| next if b.at(ns("./formattedAddress")) x = address_precompose1(b) b.children = "<formattedAddress>#{x}</formattedAddress>" end end
address_precompose1(addr)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 28 def address_precompose1(addr) ret = [] addr.xpath(ns("./street")).each { |s| ret << s.children.to_xml } a = addr.at(ns("./city")) and ret << a.children.to_xml addr.xpath(ns("./state")).each { |s| ret << s.children.to_xml } a = addr.at(ns("./country")) and ret << a.children.to_xml a = addr.at(ns("./postcode")) and ret[-1] += " #{a.children.to_xml}" ret.join("<br/>") end
amend(docxml)
click to toggle source
we use this to eliminate the semantic amend blocks from rendering
# File lib/isodoc/presentation_function/block.rb, line 195 def amend(docxml) docxml.xpath(ns("//amend")).each do |f| amend1(f) end end
amend1(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 201 def amend1(elem) elem.xpath(ns("./autonumber")).each(&:remove) elem.xpath(ns("./newcontent")).each { |a| a.name = "quote" } elem.xpath(ns("./description")).each { |a| a.replace(a.children) } elem.replace(elem.children) end
anchor_linkend(node, linkend)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 9 def anchor_linkend(node, linkend) if node["citeas"].nil? && node["bibitemid"] return @xrefs.anchor(node["bibitemid"], :xref) || "???" elsif node["target"] && node["droploc"] return @xrefs.anchor(node["target"], :value) || @xrefs.anchor(node["target"], :label) || @xrefs.anchor(node["target"], :xref) || "???" elsif node["target"] && !/.#./.match(node["target"]) linkend = anchor_linkend1(node) end linkend || "???" end
anchor_linkend1(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 23 def anchor_linkend1(node) linkend = @xrefs.anchor(node["target"], :xref) container = @xrefs.anchor(node["target"], :container, false) (container && get_note_container_id(node) != container && @xrefs.get[node["target"]]) and linkend = prefix_container(container, linkend, node["target"]) capitalise_xref(node, linkend) end
annex(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 22 def annex(docxml) docxml.xpath(ns("//annex")).each do |f| annex1(f) end end
annex1(elem)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 28 def annex1(elem) lbl = @xrefs.anchor(elem["id"], :label) if t = elem.at(ns("./title")) t.children = "<strong>#{t.children.to_xml}</strong>" end prefix_name(elem, "<br/><br/>", lbl, "title") end
asciimath_dup(node)
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 74 def asciimath_dup(node) return if @suppressasciimathdup a = MathML2AsciiMath.m2a(node.to_xml) node.next = "<!-- #{a} -->" end
bibdata(docxml)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 3 def bibdata(docxml) docid_prefixes(docxml) a = bibdata_current(docxml) or return address_precompose(a) bibdata_i18n(a) a.next = "<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join('')}"\ "</localized-strings>" end
bibdata_current(docxml)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 38 def bibdata_current(docxml) a = docxml.at(ns("//bibdata")) or return a.xpath(ns("./language")).each do |l| l.text == @lang and l["current"] = "true" end a.xpath(ns("./script")).each do |l| l.text == @script and l["current"] = "true" end a end
bibdata_i18n(bib)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 49 def bibdata_i18n(bib) hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype") hash_translate(bib, @i18n.get["stage_dict"], "./status/stage") hash_translate(bib, @i18n.get["substage_dict"], "./status/substage") end
blank?(elem)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 99 def blank?(elem) elem.nil? || elem.respond_to?(:empty?) && elem.empty? end
block(docxml)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 42 def block(docxml) amend docxml table docxml figure docxml sourcecode docxml formula docxml example docxml termexample docxml note docxml termnote docxml termdefinition docxml permission docxml requirement docxml recommendation docxml end
capitalise_xref(node, linkend)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 32 def capitalise_xref(node, linkend) return linkend unless %w(Latn Cyrl Grek).include? @script return linkend&.capitalize if node["case"] == "capital" return linkend&.downcase if node["case"] == "lowercase" return linkend if linkend[0, 1].match?(/\p{Upper}/) capitalise_xref1(node, linkend) end
capitalise_xref1(node, linkend)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 41 def capitalise_xref1(node, linkend) prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") & node.xpath("./preceding::text()") if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join) linkend&.capitalize else linkend end end
clause(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 3 def clause(docxml) docxml.xpath(ns("//clause | "\ "//terms | //definitions | //references")) .each do |f| clause1(f) end end
clause1(elem)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 11 def clause1(elem) level = @xrefs.anchor(elem["id"], :level, false) || "1" t = elem.at(ns("./title")) and t["depth"] = level return if !elem.ancestors("boilerplate").empty? || @suppressheadingnumbers || elem["unnumbered"] lbl = @xrefs.anchor(elem["id"], :label, elem.parent.name != "sections") or return prefix_name(elem, "<tab/>", "#{lbl}#{clausedelim}", "title") end
clausetitle(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 89 def clausetitle(docxml) docxml.xpath(ns("//variant-title[@type = 'toc']")).each(&:remove) end
concept(docxml)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 160 def concept(docxml) docxml.xpath(ns("//concept")).each { |f| concept1(f) } end
concept1(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 164 def concept1(node) xref = node&.at(ns("./xref/@target"))&.text or return concept_render(node, ital: node["ital"] || "true", ref: node["ref"] || "true", linkref: node["linkref"] || "true", linkmention: node["linkmention"] || "false") if node.at(ns("//definitions//dt[@id = '#{xref}']")) concept_render(node, ital: node["ital"] || "false", ref: node["ref"] || "false", linkref: node["linkref"] || "true", linkmention: node["linkmention"] || "false") else concept_render(node, ital: node["ital"] || "true", ref: node["ref"] || "true", linkref: node["linkref"] || "true", linkmention: node["linkmention"] || "false") end end
concept1_ref(_node, ref, opts)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 201 def concept1_ref(_node, ref, opts) ref.nil? and return return ref.remove if opts[:ref] == "false" r = concept1_ref_content(ref) ref = r.at("./descendant-or-self::xmlns:xref | "\ "./descendant-or-self::xmlns:eref | "\ "./descendant-or-self::xmlns:termref") %w(xref eref).include? ref&.name and get_linkend(ref) if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name) ref.replace(ref.children) end end
concept1_ref_content(ref)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 215 def concept1_ref_content(ref) if non_locality_elems(ref).select do |c| !c.text? || /\S/.match(c) end.empty? ref.replace(@i18n.term_defined_in.sub(/%/, ref.to_xml)) else ref.replace("[#{ref.to_xml}]") end end
concept_render(node, opts)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 182 def concept_render(node, opts) node&.at(ns("./refterm"))&.remove r = node.at(ns("./renderterm")) ref = node.at(ns("./xref | ./eref | ./termref")) ref && opts[:ref] != "false" and r&.next = " " opts[:ital] == "true" and r&.name = "em" if opts[:linkmention] == "true" && !r.nil? && !ref.nil? ref2 = ref.clone r2 = r.clone r.replace(ref2).children = r2 end concept1_ref(node, ref, opts) if opts[:ital] == "false" r = node.at(ns(".//renderterm")) r&.replace(r&.children) end node.replace(node.children) end
conversions(docxml)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 23 def conversions(docxml) bibdata docxml @xrefs.parse docxml section docxml block docxml inline docxml end
convert1(docxml, filename, dir)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 15 def convert1(docxml, filename, dir) @xrefs.parse docxml info docxml, nil conversions(docxml) docxml.root["type"] = "presentation" docxml.to_xml end
decorate_fraction_part(fract, locale)
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 48 def decorate_fraction_part(fract, locale) result = [] twitter_cldr_reader_symbols = twitter_cldr_reader(locale) fract = fract.slice(0..(twitter_cldr_reader_symbols[:precision] || -1)) fr_group_digits = twitter_cldr_reader_symbols[:fraction_group_digits] || 1 until fract.empty? result.push(fract.slice!(0, fr_group_digits)) end result.join(twitter_cldr_reader_symbols[:fraction_group].to_s) end
display_order(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 75 def display_order(docxml) i = 0 i = display_order_xpath(docxml, "//preface/*", i) i = display_order_at(docxml, "//clause[@type = 'scope']", i) i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i) i = display_order_at(docxml, "//sections/terms | "\ "//sections/clause[descendant::terms]", i) i = display_order_at(docxml, "//sections/definitions", i) i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i) i = display_order_xpath(docxml, "//annex", i) i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i) display_order_xpath(docxml, "//indexsect", i) end
display_order_at(docxml, xpath, idx)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 59 def display_order_at(docxml, xpath, idx) return idx unless c = docxml.at(ns(xpath)) idx += 1 c["displayorder"] = idx idx end
display_order_xpath(docxml, xpath, idx)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 67 def display_order_xpath(docxml, xpath, idx) docxml.xpath(ns(xpath)).each do |c| idx += 1 c["displayorder"] = idx end idx end
docid_prefixes(docxml)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 13 def docid_prefixes(docxml) docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i| i.children = @xrefs.klass.docid_prefix(i["type"], i.text) end end
eref(docxml)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 144 def eref(docxml) docxml.xpath(ns("//eref")).each { |f| xref1(f) } end
eref_localities(refs, target, node)
click to toggle source
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>
# File lib/isodoc/presentation_function/inline.rb, line 77 def eref_localities(refs, target, node) ret = "" refs.each_with_index do |r, i| delim = "," delim = ";" if r.name == "localityStack" && i.positive? ret = eref_locality_stack(r, i, target, delim, ret, node) end ret end
eref_localities0(ref, _idx, target, delim, node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 99 def eref_localities0(ref, _idx, target, delim, node) if ref["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}") else eref_localities1(target, ref["type"], ref.at(ns("./referenceFrom")), ref.at(ns("./referenceTo")), delim, node, @lang) end end
eref_localities1(target, type, from, upto, delim, node, lang = "en")
click to toggle source
TODO: move to localization file
# File lib/isodoc/presentation_function/inline.rb, line 117 def eref_localities1(target, type, from, upto, delim, node, lang = "en") return "" if type == "anchor" lang == "zh" and return l10n(eref_localities1_zh(target, type, from, upto, node, delim)) ret = delim ret += eref_locality_populate(type, node) ret += " #{from.text}" if from ret += "–#{upto.text}" if upto l10n(ret) end
eref_localities1_zh(_target, type, from, upto, node, delim)
click to toggle source
TODO: move to localization file
# File lib/isodoc/presentation_function/inline.rb, line 108 def eref_localities1_zh(_target, type, from, upto, node, delim) ret = "#{delim} 第#{from.text}" if from ret += "–#{upto.text}" if upto loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize) ret += " #{loc}" unless node["droploc"] == "true" ret end
eref_locality_populate(type, node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 129 def eref_locality_populate(type, node) return "" if node["droploc"] == "true" loc = @i18n.locality[type] || type.sub(/^locality:/, "") loc = case node["case"] when "lowercase" then loc.downcase else Metanorma::Utils.strict_capitalize_first(loc) end " #{loc}" end
eref_locality_stack(ref, idx, target, delim, ret, node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 87 def eref_locality_stack(ref, idx, target, delim, ret, node) if ref.name == "localityStack" ref.elements.each_with_index do |rr, j| ret += eref_localities0(rr, j, target, delim, node) delim = "," end else ret += eref_localities0(ref, idx, target, delim, node) end ret end
example(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 83 def example(docxml) docxml.xpath(ns("//example")).each do |f| example1(f) end end
example1(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 95 def example1(elem) n = @xrefs.get[elem["id"]] lbl = if n.nil? || n[:label].nil? || n[:label].empty? @i18n.example else l10n("#{@i18n.example} #{n[:label]}") end prefix_name(elem, " — ", lbl, "name") end
figure(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 11 def figure(docxml) docxml.xpath(ns("//image")).each { |f| svg_extract(f) } docxml.xpath(ns("//figure")).each { |f| figure1(f) } docxml.xpath(ns("//svgmap")).each do |s| if f = s.at(ns("./figure")) then s.replace(f) else s.remove end end end
figure1(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 32 def figure1(elem) return sourcecode1(elem) if elem["class"] == "pseudocode" || elem["type"] == "pseudocode" return if labelled_ancestor(elem) && elem.ancestors("figure").empty? || elem.at(ns("./figure")) && !elem.at(ns("./name")) lbl = @xrefs.anchor(elem["id"], :label, false) or return prefix_name(elem, " — ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name") end
formula(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 71 def formula(docxml) docxml.xpath(ns("//formula")).each do |f| formula1(f) end end
formula1(elem)
click to toggle source
introduce name element
# File lib/isodoc/presentation_function/block.rb, line 78 def formula1(elem) lbl = @xrefs.anchor(elem["id"], :label, false) prefix_name(elem, "", lbl, "name") end
get_linkend(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 64 def get_linkend(node) c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) } return unless c1.empty? link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"])) link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link, node) non_locality_elems(node).each(&:remove) node.add_child(link) end
hash_translate(bibdata, hash, xpath, lang = @lang)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 55 def hash_translate(bibdata, hash, xpath, lang = @lang) x = bibdata.at(ns(xpath)) or return x["language"] = "" hash.is_a? Hash or return hash[x.text] or return x.next = x.dup x.next["language"] = lang x.next.children = hash[x.text] end
i18n_safe(key)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 70 def i18n_safe(key) key.to_s.gsub(/\s|\./, "_") end
i18n_tag(key, value)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 65 def i18n_tag(key, value) "<localized-string key='#{key}' language='#{@lang}'>#{value}"\ "</localized-string>" end
i8n_name(hash, pref)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 74 def i8n_name(hash, pref) if hash.is_a? Hash then i8n_name1(hash, pref) elsif hash.is_a? Array hash.reject { |a| blank?(a) }.each_with_object([]) .with_index do |(v1, g), i| i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x } end else [i18n_tag(pref, hash)] end end
i8n_name1(hash, pref)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 85 def i8n_name1(hash, pref) hash.reject { |_k, v| blank?(v) }.each_with_object([]) do |(k, v), g| if v.is_a? Hash then i8n_name(v, i18n_safe(k)).each { |x| g << x } elsif v.is_a? Array v.reject { |a| blank?(a) }.each_with_index do |v1, i| i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x } end else g << i18n_tag("#{pref}#{pref.empty? ? '' : '.'}#{i18n_safe(k)}", v) end end end
index(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 55 def index(docxml) docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove) end
inline(docxml)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 58 def inline(docxml) concept docxml xref docxml eref docxml origin docxml quotesource docxml mathml docxml variant docxml end
localize_maths(node, locale)
click to toggle source
symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
# File lib/isodoc/presentation_function/math.rb, line 18 def localize_maths(node, locale) node.xpath(".//m:mn", MATHML).each do |x| num = BigDecimal(x.text) precision = /\./.match?(x.text) ? x.text.sub(/^.*\./, "").size : 0 x.children = localized_number(num, locale, precision) end end
localized_number(num, locale, precision)
click to toggle source
By itself twitter-cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually
# File lib/isodoc/presentation_function/math.rb, line 28 def localized_number(num, locale, precision) localized = localized_number1(num, locale, precision) twitter_cldr_reader_symbols = twitter_cldr_reader(locale) return localized unless twitter_cldr_reader_symbols[:decimal] integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal]) return localized if fraction.nil? || fraction.length.zero? [integer, decorate_fraction_part(fraction, locale)] .join(twitter_cldr_reader_symbols[:decimal]) end
localized_number1(num, locale, precision)
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 40 def localized_number1(num, locale, precision) if precision.zero? num.localize(locale).to_s else num.localize(locale).to_decimal.to_s(precision: precision) end end
lower2cap(text)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 5 def lower2cap(text) return text if /^[[:upper:]][[:upper:]]/.match?(text) text.capitalize end
mathml(docxml)
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 9 def mathml(docxml) locale = twitter_cldr_localiser docxml.xpath("//m:math", MATHML).each do |f| mathml1(f, locale) end end
mathml1(node, locale)
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 81 def mathml1(node, locale) asciimath_dup(node) localize_maths(node, locale) return unless node.elements.size == 1 && node.elements.first.name == "mn" if node.parent.name == "stem" node.parent.replace(node.at("./m:mn", MATHML).children) else node.replace(node.at("./m:mn", MATHML).children) end end
nearest_block_parent(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 50 def nearest_block_parent(node) until %w(p title td th name formula li dt dd sourcecode pre) .include?(node.name) node = node.parent end node end
non_locality_elems(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 58 def non_locality_elems(node) node.children.reject do |c| %w{locality localityStack}.include? c.name end end
note(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 105 def note(docxml) docxml.xpath(ns("//note")).each do |f| note1(f) end end
note1(elem)
click to toggle source
introduce name element
# File lib/isodoc/presentation_function/block.rb, line 112 def note1(elem) return if elem.parent.name == "bibitem" n = @xrefs.get[elem["id"]] lbl = if n.nil? || n[:label].nil? || n[:label].empty? @i18n.note else l10n("#{@i18n.note} #{n[:label]}") end prefix_name(elem, "", lbl, "name") end
origin(docxml)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 148 def origin(docxml) docxml.xpath(ns("//origin[not(termref)]")).each { |f| xref1(f) } end
permission(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 166 def permission(docxml) docxml.xpath(ns("//permission")).each do |f| recommendation1(f, lower2cap(@i18n.permission)) end end
postprocess(result, filename, _dir)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 68 def postprocess(result, filename, _dir) toXML(result, filename) @files_to_delete.each { |f| FileUtils.rm_rf f } end
prefix_container(container, linkend, _target)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 5 def prefix_container(container, linkend, _target) l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}") end
prefix_name(node, delim, number, elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 43 def prefix_name(node, delim, number, elem) return if number.nil? || number.empty? unless name = node.at(ns("./#{elem}")) node.children.empty? and node.add_child("<#{elem}></#{elem}>") or node.children.first.previous = "<#{elem}></#{elem}>" name = node.children.first end if name.children.empty? then name.add_child(number) else (name.children.first.previous = "#{number}#{delim}") end end
quotesource(docxml)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 152 def quotesource(docxml) docxml.xpath(ns("//quote/source")).each { |f| xref1(f) } end
recommendation(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 154 def recommendation(docxml) docxml.xpath(ns("//recommendation")).each do |f| recommendation1(f, lower2cap(@i18n.recommendation)) end end
recommendation1(elem, type)
click to toggle source
introduce name element
# File lib/isodoc/presentation_function/block.rb, line 173 def recommendation1(elem, type) n = @xrefs.anchor(elem["id"], :label, false) lbl = (n.nil? ? type : l10n("#{type} #{n}")) prefix_name(elem, "", lbl, "name") end
references(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 47 def references(docxml); end
requirement(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 160 def requirement(docxml) docxml.xpath(ns("//requirement")).each do |f| recommendation1(f, lower2cap(@i18n.requirement)) end end
section(docxml)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 31 def section(docxml) clause docxml annex docxml term docxml references docxml index docxml clausetitle docxml toc docxml display_order docxml end
sourcecode(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 56 def sourcecode(docxml) docxml.xpath(ns("//sourcecode")).each do |f| sourcecode1(f) end end
sourcecode1(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 62 def sourcecode1(elem) return if labelled_ancestor(elem) return unless elem.ancestors("example").empty? lbl = @xrefs.anchor(elem["id"], :label, false) or return prefix_name(elem, " — ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name") end
svg_extract(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 21 def svg_extract(elem) return unless %r{^data:image/svg\+xml;base64,}.match?(elem["src"]) svg = Base64.strict_decode64(elem["src"] .sub(%r{^data:image/svg\+xml;base64,}, "")) x = Nokogiri::XML.fragment(svg.sub(/<\?xml[^>]*>/, "")) do |config| config.huge end elem.replace(x) end
table(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 179 def table(docxml) docxml.xpath(ns("//table")).each do |f| table1(f) end end
table1(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 185 def table1(elem) return if labelled_ancestor(elem) return if elem["unnumbered"] && !elem.at(ns("./name")) n = @xrefs.anchor(elem["id"], :label, false) prefix_name(elem, " — ", l10n("#{lower2cap @i18n.table} #{n}"), "name") end
term(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 36 def term(docxml) docxml.xpath(ns("//term")).each do |f| term1(f) end end
term1(elem)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 42 def term1(elem) lbl = @xrefs.get[elem["id"]][:label] or return prefix_name(elem, "", "#{lbl}#{clausedelim}", "name") end
termdefinition(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 136 def termdefinition(docxml) docxml.xpath(ns("//term[definition]")).each do |f| termdefinition1(f) end end
termdefinition1(elem)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 142 def termdefinition1(elem) return unless elem.xpath(ns("./definition")).size > 1 d = elem.at(ns("./definition")) d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first elem.xpath(ns("./definition")).each do |f| f = f.replace("<li>#{f.children.to_xml}</li>").first d << f end d.wrap("<definition></definition>") end
termexample(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 89 def termexample(docxml) docxml.xpath(ns("//termexample")).each do |f| example1(f) end end
termnote(docxml)
click to toggle source
# File lib/isodoc/presentation_function/block.rb, line 124 def termnote(docxml) docxml.xpath(ns("//termnote")).each do |f| termnote1(f) end end
termnote1(elem)
click to toggle source
introduce name element
# File lib/isodoc/presentation_function/block.rb, line 131 def termnote1(elem) lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???") prefix_name(elem, "", lower2cap(lbl), "name") end
toXML(result, filename)
click to toggle source
# File lib/isodoc/presentation_xml_convert.rb, line 73 def toXML(result, filename) File.open(filename, "w:UTF-8") { |f| f.write(result) } end
toc(docxml)
click to toggle source
# File lib/isodoc/presentation_function/section.rb, line 93 def toc(docxml) docxml.xpath(ns("//toc//xref[text()]")).each do |x| lbl = @xrefs.get[x["target"]][:label] or next x.children.first.previous = "#{lbl}<tab/>" end end
trim_hash(hash)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 103 def trim_hash(hash) loop do h_new = trim_hash1(hash) break hash if hash == h_new hash = h_new end end
trim_hash1(hash)
click to toggle source
# File lib/isodoc/presentation_function/bibdata.rb, line 112 def trim_hash1(hash) return hash unless hash.is_a? Hash hash.each_with_object({}) do |(k, v), g| next if blank?(v) g[k] = if v.is_a? Hash then trim_hash1(hash[k]) elsif v.is_a? Array hash[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) } else v end end end
twitter_cldr_localiser()
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 68 def twitter_cldr_localiser locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en twitter_cldr_reader(locale) locale end
twitter_cldr_localiser_symbols()
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 59 def twitter_cldr_localiser_symbols {} end
twitter_cldr_reader(locale)
click to toggle source
# File lib/isodoc/presentation_function/math.rb, line 63 def twitter_cldr_reader(locale) num = TwitterCldr::DataReaders::NumberDataReader.new(locale) num.symbols.merge!(twitter_cldr_localiser_symbols) end
variant(docxml)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 225 def variant(docxml) docxml.xpath(ns("//variant")).each { |f| variant1(f) } docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove) docxml.xpath(ns("//variant")).each do |v| next unless v&.next&.name == "variant" v.next = "/" end docxml.xpath(ns("//variant")).each { |f| f.replace(f.children) } end
variant1(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 236 def variant1(node) if (!node["lang"] || node["lang"] == @lang) && (!node["script"] || node["script"] == @script) elsif found_matching_variant_sibling(node) node["remove"] = "true" end end
xref(docxml)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 140 def xref(docxml) docxml.xpath(ns("//xref")).each { |f| xref1(f) } end
xref1(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 156 def xref1(node) get_linkend(node) end
Private Instance Methods
found_matching_variant_sibling(node)
click to toggle source
# File lib/isodoc/presentation_function/inline.rb, line 246 def found_matching_variant_sibling(node) prev = node.xpath("./preceding-sibling::xmlns:variant") foll = node.xpath("./following-sibling::xmlns:variant") found = false (prev + foll).each do |n| found = true if n["lang"] == @lang && (!n["script"] || n["script"] == @script) end found end