Class: IsoDoc::PresentationXMLConvert

Inherits:
Convert show all
Defined in:
lib/isodoc/presentation_xml_convert.rb,
lib/isodoc/presentation_function/math.rb,
lib/isodoc/presentation_function/block.rb,
lib/isodoc/presentation_function/image.rb,
lib/isodoc/presentation_function/terms.rb,
lib/isodoc/presentation_function/inline.rb,
lib/isodoc/presentation_function/bibdata.rb,
lib/isodoc/presentation_function/section.rb

Constant Summary collapse

MATHML =
{ "m" => "http://www.w3.org/1998/Math/MathML" }.freeze

Constants included from Function::Utils

Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::NOKOHEAD, Function::Utils::NOTE_CONTAINER_ANCESTOR

Constants included from Function::Table

Function::Table::SW

Constants included from Function::Section

Function::Section::TERM_CLAUSE

Constants included from Function::Lists

Function::Lists::OL_STYLE

Constants included from Function::Cleanup

Function::Cleanup::FIGURE_WITH_FOOTNOTES

Constants included from Function::Blocks

Function::Blocks::EXAMPLE_TBL_ATTR, Function::Blocks::EXAMPLE_TD_ATTR

Instance Attribute Summary

Attributes inherited from Convert

#i18n, #meta, #options, #xrefs

Instance Method Summary collapse

Methods inherited from Convert

#bibitem_lookup, #convert, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #fonts_options, #generate_css, #html_doc_path, #i18n_init, #l10n, #localpath, #metadata_init, #middle_clause, #populate_css, #precompiled_style_or_original, #scss_fontheader, #target_pdf, #tmpimagedir_suffix, #xref_init

Methods included from ClassUtils

#case_strict, #case_with_markup, #date_range, #liquid, #ns

Methods included from Function::Utils

#attr_code, #cleanup_entities, #date_range, #emf?, #empty2nil, #external_path, #extract_delims, #from_xhtml, #get_clause_id, #get_note_container_id, #header_strip, #header_strip_elem?, #image_localfile, #insert_tab, #labelled_ancestor, #liquid, #noko, #ns, #populate_template, #save_dataimage, #sentence_join, #to_xhtml, #to_xhtml_fragment, #to_xhtml_prep

Methods included from Function::ToWordHtml

#body_attr, #boilerplate, #define_head, #in_sourcecode, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #middle, #note?, #parse, #rel_tmpimagedir, #set_termdomain, #tmpimagedir

Methods included from Function::Terms

#admitted_term_parse, #definition_parse, #deprecated_term_parse, #modification_parse, #para_then_remainder, #term_parse, #termdef_parse, #termdocsource_parse, #termnote_delim, #termnote_parse, #termref_parse

Methods included from Function::Table

#colgroup, #make_tr_attr, #table_attrs, #table_parse, #table_title_parse, #tbody_parse, #tcaption, #tfoot_parse, #thead_parse, #tr_parse

Methods included from Function::Section

#abstract, #acknowledgements, #annex_attrs, #annex_name, #clause_attrs, #clause_name, #clause_parse, #clause_parse_subtitle, #clause_parse_title, #clause_parse_title1, #clause_title_depth, #clausedelim, #clausedelimspace, #copyright_parse, #feedback_parse, #foreword, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preface, #preface_block, #scope, #symbols_abbrevs, #symbols_parse, #terms_defs, #terms_parse, #variant_title

Methods included from Function::References

#bibitem_ref_code, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #bracket_if_num, #date_note_process, #docid_l10n, #docid_prefix, #implicit_reference, #is_standard, #iso_bibitem_entry_attrs, #iso_title, #nonstd_bibitem, #norm_ref, #norm_ref_xpath, #omit_docid_prefix, #pref_ref_code, #prefix_bracketed_ref, #ref_entry_code, #reference_format, #render_identifier, #std_bibitem_entry

Methods included from Function::Lists

#dl_attrs, #dl_parse, #dt_dd?, #dt_parse, #li_parse, #ol_attrs, #ol_depth, #ol_parse, #ol_style, #ul_attrs, #ul_parse

Methods included from Function::Inline

#add_parse, #bookmark_parse, #br_parse, #callout_parse, #del_parse, #em_parse, #eref_parse, #eref_target, #error_parse, #hr_parse, #image_parse, #image_title_parse, #index_parse, #index_xref_parse, #keyword_parse, #link_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #section_break, #smallcap_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #termrefelem_parse, #text_parse, #tt_parse, #underline_parse, #xref_parse

Methods included from Function::Form

#form_parse, #input_parse, #label_parse, #option_parse, #select_parse, #text_input, #textarea_parse

Methods included from Function::Cleanup

#admonition_cleanup, #break_up_long_strings, #break_up_long_strings1, #cleanup, #example_cleanup, #figure_aside_process, #figure_cleanup, #figure_get_or_make_dl, #footnote_cleanup, #footnote_reference_format, #inline_header_cleanup, #merge_fnref_into_fn_text, #new_fullcolspan_row, #passthrough_cleanup, #remove_bottom_border, #symbols_cleanup, #table_cleanup, #table_footnote_cleanup, #table_footnote_cleanup_propagate, #table_footnote_reference_format, #table_get_or_make_tfoot, #table_long_strings_cleanup, #table_note_cleanup, #textcleanup

Methods included from Function::Blocks

#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_parse, #admonition_parse, #annotation_parse, #example_div_attr, #example_div_parse, #example_label, #example_parse, #example_table_attr, #example_table_parse, #figure_attrs, #figure_key, #figure_name_parse, #figure_parse, #figure_parse1, #formula_attrs, #formula_parse, #formula_parse1, #formula_where, #keep_style, #middle_admonitions, #middle_title, #note_attrs, #note_delim, #note_p_parse, #note_parse, #note_parse1, #para_attrs, #para_class, #para_parse, #passthrough_parse, #permission_parse, #pre_parse, #pseudocode_attrs, #pseudocode_parse, #quote_attribution, #quote_parse, #recommendation_attr_keyvalue, #recommendation_attr_parse, #recommendation_attributes, #recommendation_attributes1, #recommendation_labels, #recommendation_name, #recommendation_parse, #reqt_attrs, #reqt_component_attrs, #reqt_metadata_node, #requirement_component_parse, #requirement_parse, #requirement_skip_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #svg_parse, #toc_parse

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



10
11
12
13
14
# File 'lib/isodoc/presentation_xml_convert.rb', line 10

def initialize(options)
  @format = :presentation
  @suffix = "presentation.xml"
  super
end

Instance Method Details

#address_precompose(bib) ⇒ Object



19
20
21
22
23
24
25
26
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
# 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) ⇒ Object

we use this to eliminate the semantic amend blocks from rendering



126
127
128
129
130
# File 'lib/isodoc/presentation_function/block.rb', line 126

def amend(docxml)
  docxml.xpath(ns("//amend")).each do |f|
    amend1(f)
  end
end

#amend1(elem) ⇒ Object



132
133
134
135
136
137
# File 'lib/isodoc/presentation_function/block.rb', line 132

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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/isodoc/presentation_function/inline.rb', line 14

def anchor_linkend(node, linkend)
  if node["citeas"].nil? && node["bibitemid"]
    return @xrefs.anchor(node["bibitemid"], :xref) || "???"
  elsif node["target"] && node["droploc"]
    return anchor_value(node["target"]) || "???"
  elsif node["target"] && !/.#./.match(node["target"])
    linkend = anchor_linkend1(node)
  end

  linkend || "???"
end

#anchor_linkend1(node) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/isodoc/presentation_function/inline.rb', line 26

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, anchor_value(node["target"]))
end

#anchor_value(id) ⇒ Object



9
10
11
12
# File 'lib/isodoc/presentation_function/inline.rb', line 9

def anchor_value(id)
  @xrefs.anchor(id, :value) || @xrefs.anchor(id, :label) ||
    @xrefs.anchor(id, :xref)
end

#annex(docxml) ⇒ Object



22
23
24
25
26
# 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) ⇒ Object



28
29
30
31
32
33
34
# 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) ⇒ Object



74
75
76
77
78
79
# 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) ⇒ Object



3
4
5
6
7
8
9
10
11
# 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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



49
50
51
52
53
# 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) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/isodoc/presentation_function/bibdata.rb', line 99

def blank?(elem)
  elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
end

#block(docxml) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/isodoc/presentation_xml_convert.rb', line 44

def block(docxml)
  amend docxml
  table docxml
  figure docxml
  sourcecode docxml
  formula docxml
  example docxml
  note docxml
  permission docxml
  requirement docxml
  recommendation docxml
end

#capitalise_xref(node, linkend, label) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/isodoc/presentation_function/inline.rb', line 35

def capitalise_xref(node, linkend, label)
  linktext = linkend.gsub(/<[^>]+>/, "")
  (label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
    linktext[0, 1].match?(/\p{Upper}/) and return linkend
  node["case"] and
    return Common::case_with_markup(linkend, node["case"], @script)

  capitalise_xref1(node, linkend)
end

#capitalise_xref1(node, linkend) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/isodoc/presentation_function/inline.rb', line 45

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)
    Common::case_with_markup(linkend, "capital", @script)
  else linkend
  end
end

#clause(docxml) ⇒ Object



3
4
5
6
7
8
9
# 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) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



89
90
91
# File 'lib/isodoc/presentation_function/section.rb', line 89

def clausetitle(docxml)
  docxml.xpath(ns("//variant-title[@type = 'toc']")).each(&:remove)
end

#concept(docxml) ⇒ Object



3
4
5
# File 'lib/isodoc/presentation_function/terms.rb', line 3

def concept(docxml)
  docxml.xpath(ns("//concept")).each { |f| concept1(f) }
end

#concept1(node) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/isodoc/presentation_function/terms.rb', line 7

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_linkmention(ref, renderterm, opts) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/isodoc/presentation_function/terms.rb', line 40

def concept1_linkmention(ref, renderterm, opts)
  if opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
    ref2 = ref.clone
    r2 = renderterm.clone
    renderterm.replace(ref2).children = r2
  end
end

#concept1_ref(_node, ref, opts) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/presentation_function/terms.rb', line 48

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) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/isodoc/presentation_function/terms.rb', line 62

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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/isodoc/presentation_function/terms.rb', line 25

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"
  concept1_linkmention(ref, r, opts)
  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) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/isodoc/presentation_xml_convert.rb', line 24

def conversions(docxml)
  bibdata docxml
  @xrefs.parse docxml
  section docxml
  block docxml
  terms docxml
  inline docxml
end

#convert1(docxml, filename, dir) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/isodoc/presentation_xml_convert.rb', line 16

def convert1(docxml, filename, dir)
  @xrefs.parse docxml
  info docxml, nil
  conversions(docxml)
  docxml.root["type"] = "presentation"
  docxml.to_xml.gsub(/&lt;/, "&#x3c;").gsub(/&gt;/, "&#x3e;")
end

#decorate_fraction_part(fract, locale) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# 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

#designation(docxml) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/isodoc/presentation_function/terms.rb', line 84

def designation(docxml)
  docxml.xpath(ns("//term")).each do |t|
    merge_second_preferred(t)
  end
  docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
    designation1(p)
  end
end

#designation1(desgn) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/isodoc/presentation_function/terms.rb', line 114

def designation1(desgn)
  s = desgn.at(ns("./termsource"))
  name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
                     "./graphical-symbol")) or return

  designation_annotate(desgn, name)
  s and desgn.next = s
end

#designation_annotate(desgn, name) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/isodoc/presentation_function/terms.rb', line 123

def designation_annotate(desgn, name)
  designation_boldface(desgn)
  designation_field(desgn, name)
  g = desgn.at(ns("./expression/grammar")) and
    name << ", #{designation_grammar(g).join(', ')}"
  designation_localization(desgn, name)
  designation_pronunciation(desgn, name)
  desgn.children = name.children
end

#designation_boldface(desgn) ⇒ Object



133
134
135
136
137
# File 'lib/isodoc/presentation_function/terms.rb', line 133

def designation_boldface(desgn)
  desgn.name == "preferred" or return
  name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
  name.children = "<strong>#{name.children}</strong>"
end

#designation_field(desgn, name) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/isodoc/presentation_function/terms.rb', line 139

def designation_field(desgn, name)
  f = desgn.xpath(ns("./field-of-application | ./usage-info"))
    &.map { |u| u.children.to_xml }&.join(", ")
  return nil if f&.empty?

  name << ", &#x3c;#{f}&#x3e;"
end

#designation_grammar(grammar) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/isodoc/presentation_function/terms.rb', line 147

def designation_grammar(grammar)
  ret = []
  grammar.xpath(ns("./gender | ./number")).each do |x|
    ret << @i18n.grammar_abbrevs[x.text]
  end
  %w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
    .each do |x|
    grammar.at(ns("./#{x}[text() = 'true']")) and
      ret << @i18n.grammar_abbrevs[x]
  end
  ret
end

#designation_localization(desgn, name) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/isodoc/presentation_function/terms.rb', line 160

def designation_localization(desgn, name)
  loc = [desgn&.at(ns("./expression/@language"))&.text,
         desgn&.at(ns("./expression/@script"))&.text,
         desgn&.at(ns("./@geographic-area"))&.text].compact
  return if loc.empty?

  name << ", #{loc.join(' ')}"
end

#designation_pronunciation(desgn, name) ⇒ Object



169
170
171
172
173
# File 'lib/isodoc/presentation_function/terms.rb', line 169

def designation_pronunciation(desgn, name)
  f = desgn.at(ns("./expression/pronunciation")) or return

  name << ", /#{f.children.to_xml}/"
end

#display_order(docxml) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# 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) ⇒ Object



59
60
61
62
63
64
65
# 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) ⇒ Object



67
68
69
70
71
72
73
# 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) ⇒ Object



13
14
15
16
17
# 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

#emf_encode(img) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/isodoc/presentation_function/image.rb', line 49

def emf_encode(img)
  img["mimetype"] = "image/svg+xml"
  unless %r{^data:image}.match?(img["src"])
    img["src"] = Metanorma::Utils::datauri(img["src"])
  end
  img.children = "<emf src='#{img['src']}'/>"
  img["src"] = ""
  img
end

#emf_to_svg(img) ⇒ Object



59
60
61
62
# File 'lib/isodoc/presentation_function/image.rb', line 59

def emf_to_svg(img)
  emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
  Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
end

#emf_to_svgfilename(uri) ⇒ Object



96
97
98
# File 'lib/isodoc/presentation_function/image.rb', line 96

def emf_to_svgfilename(uri)
  "#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.svg"
end

#eref(docxml) ⇒ Object



147
148
149
# File 'lib/isodoc/presentation_function/inline.rb', line 147

def eref(docxml)
  docxml.xpath(ns("//eref")).each { |f| xref1(f) }
end

#eref_localities(refs, target, node) ⇒ Object

so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>



81
82
83
84
85
86
87
88
89
# File 'lib/isodoc/presentation_function/inline.rb', line 81

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) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/isodoc/presentation_function/inline.rb', line 102

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") ⇒ Object

TODO: move to localization file



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/isodoc/presentation_function/inline.rb', line 120

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 += "&ndash;#{upto.text}" if upto
  l10n(ret)
end

#eref_localities1_zh(_target, type, from, upto, node, delim) ⇒ Object

TODO: move to localization file



111
112
113
114
115
116
117
# File 'lib/isodoc/presentation_function/inline.rb', line 111

def eref_localities1_zh(_target, type, from, upto, node, delim)
  ret = "#{delim}#{from.text}" if from
  ret += "&ndash;#{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) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/isodoc/presentation_function/inline.rb', line 132

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) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/isodoc/presentation_function/inline.rb', line 91

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) ⇒ Object



50
51
52
53
54
# File 'lib/isodoc/presentation_function/block.rb', line 50

def example(docxml)
  docxml.xpath(ns("//example")).each do |f|
    example1(f)
  end
end

#example1(elem) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/isodoc/presentation_function/block.rb', line 56

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, "&nbsp;&mdash; ", lbl, "name")
end

#figure(docxml) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/isodoc/presentation_function/image.rb', line 6

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
  docxml.xpath(ns("//image")).each { |f| svg_emf_double(f) }
end

#figure1(elem) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/isodoc/presentation_function/image.rb', line 29

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, "&nbsp;&mdash; ",
              l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
end

#formula(docxml) ⇒ Object



38
39
40
41
42
# File 'lib/isodoc/presentation_function/block.rb', line 38

def formula(docxml)
  docxml.xpath(ns("//formula")).each do |f|
    formula1(f)
  end
end

#formula1(elem) ⇒ Object

introduce name element



45
46
47
48
# File 'lib/isodoc/presentation_function/block.rb', line 45

def formula1(elem)
  lbl = @xrefs.anchor(elem["id"], :label, false)
  prefix_name(elem, "", lbl, "name")
end

#get_linkend(node) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/isodoc/presentation_function/inline.rb', line 68

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(cleanup_entities(link))
end

#hash_translate(bibdata, hash, xpath, lang = @lang) ⇒ Object



55
56
57
58
59
60
61
62
63
# 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) ⇒ Object



70
71
72
# File 'lib/isodoc/presentation_function/bibdata.rb', line 70

def i18n_safe(key)
  key.to_s.gsub(/\s|\./, "_")
end

#i18n_tag(key, value) ⇒ Object



65
66
67
68
# 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) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object



55
56
57
# File 'lib/isodoc/presentation_function/section.rb', line 55

def index(docxml)
  docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
end

#inkscape_installed?Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
110
# File 'lib/isodoc/presentation_function/image.rb', line 100

def inkscape_installed?
  cmd = "inkscape"
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end

#inline(docxml) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/isodoc/presentation_xml_convert.rb', line 57

def inline(docxml)
  xref docxml
  eref docxml
  origin docxml
  quotesource docxml
  mathml docxml
  variant docxml
end

#localize_maths(node, locale) ⇒ Object

symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols



18
19
20
21
22
23
24
# 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) ⇒ Object

By itself twitter-cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually



28
29
30
31
32
33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
43
44
45
46
# 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) ⇒ Object



5
6
7
8
9
# File 'lib/isodoc/presentation_function/block.rb', line 5

def lower2cap(text)
  return text if /^[[:upper:]][[:upper:]]/.match?(text)

  text.capitalize
end

#mathml(docxml) ⇒ Object



9
10
11
12
13
14
# 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) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# 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

#merge_preferred_eligible?(first, second) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
# File 'lib/isodoc/presentation_function/terms.rb', line 105

def merge_preferred_eligible?(first, second)
  firstex = first.at(ns("./expression")) || {}
  secondex = second.at(ns("./expression")) || {}
  first["geographic-area"] == second["geographic-area"] &&
    firstex["language"] == secondex["language"] &&
    !first.at(ns("./pronunciation | ./grammar")) &&
    !second.at(ns("./pronunciation | ./grammar"))
end

#merge_second_preferred(term) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/isodoc/presentation_function/terms.rb', line 93

def merge_second_preferred(term)
  pref = nil
  term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i|
    if i.zero? then pref = p
    elsif merge_preferred_eligible?(pref, p)
      pref.at(ns("./expression/name")) <<
        l10n("; #{p.at(ns('./expression/name')).children.to_xml}")
      p.remove
    end
  end
end

#multidef(elem) ⇒ Object



204
205
206
207
208
209
210
211
212
# File 'lib/isodoc/presentation_function/terms.rb', line 204

def multidef(elem)
  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

#nearest_block_parent(node) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/isodoc/presentation_function/inline.rb', line 54

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) ⇒ Object



62
63
64
65
66
# File 'lib/isodoc/presentation_function/inline.rb', line 62

def non_locality_elems(node)
  node.children.reject do |c|
    %w{locality localityStack}.include? c.name
  end
end

#note(docxml) ⇒ Object



66
67
68
69
70
# File 'lib/isodoc/presentation_function/block.rb', line 66

def note(docxml)
  docxml.xpath(ns("//note")).each do |f|
    note1(f)
  end
end

#note1(elem) ⇒ Object

introduce name element



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/isodoc/presentation_function/block.rb', line 73

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) ⇒ Object



151
152
153
# File 'lib/isodoc/presentation_function/inline.rb', line 151

def origin(docxml)
  docxml.xpath(ns("//origin[not(termref)]")).each { |f| xref1(f) }
end

#permission(docxml) ⇒ Object



97
98
99
100
101
# File 'lib/isodoc/presentation_function/block.rb', line 97

def permission(docxml)
  docxml.xpath(ns("//permission")).each do |f|
    recommendation1(f, lower2cap(@i18n.permission))
  end
end

#postprocess(result, filename, _dir) ⇒ Object



76
77
78
79
# File 'lib/isodoc/presentation_xml_convert.rb', line 76

def postprocess(result, filename, _dir)
  toXML(result, filename)
  @files_to_delete.each { |f| FileUtils.rm_rf f }
end

#prefix_container(container, linkend, _target) ⇒ Object



5
6
7
# 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) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/isodoc/presentation_function/block.rb', line 11

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(cleanup_entities(number))
  else (name.children.first.previous = "#{number}#{delim}")
  end
end

#quotesource(docxml) ⇒ Object



155
156
157
# File 'lib/isodoc/presentation_function/inline.rb', line 155

def quotesource(docxml)
  docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
end

#recommendation(docxml) ⇒ Object



85
86
87
88
89
# File 'lib/isodoc/presentation_function/block.rb', line 85

def recommendation(docxml)
  docxml.xpath(ns("//recommendation")).each do |f|
    recommendation1(f, lower2cap(@i18n.recommendation))
  end
end

#recommendation1(elem, type) ⇒ Object

introduce name element



104
105
106
107
108
# File 'lib/isodoc/presentation_function/block.rb', line 104

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) ⇒ Object



47
# File 'lib/isodoc/presentation_function/section.rb', line 47

def references(docxml); end


72
73
74
# File 'lib/isodoc/presentation_function/terms.rb', line 72

def related(docxml)
  docxml.xpath(ns("//related")).each { |f| related1(f) }
end

#related1(node) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/isodoc/presentation_function/terms.rb', line 76

def related1(node)
  p = node.at(ns("./preferred"))
  ref = node.at(ns("./xref | ./eref | ./termref"))
  label = @i18n.relatedterms[node["type"]].upcase
  node.replace(l10n("<p><strong>#{label}:</strong> "\
                    "<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
end

#requirement(docxml) ⇒ Object



91
92
93
94
95
# File 'lib/isodoc/presentation_function/block.rb', line 91

def requirement(docxml)
  docxml.xpath(ns("//requirement")).each do |f|
    recommendation1(f, lower2cap(@i18n.requirement))
  end
end

#section(docxml) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/isodoc/presentation_xml_convert.rb', line 33

def section(docxml)
  clause docxml
  annex docxml
  term docxml
  references docxml
  index docxml
  clausetitle docxml
  toc docxml
  display_order docxml
end

#sourcecode(docxml) ⇒ Object



24
25
26
27
28
# File 'lib/isodoc/presentation_function/block.rb', line 24

def sourcecode(docxml)
  docxml.xpath(ns("//sourcecode")).each do |f|
    sourcecode1(f)
  end
end

#sourcecode1(elem) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/isodoc/presentation_function/block.rb', line 30

def sourcecode1(elem)
  return if labelled_ancestor(elem)

  lbl = @xrefs.anchor(elem["id"], :label, false) or return
  prefix_name(elem, "&nbsp;&mdash; ",
              l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
end

#svg_emf_double(img) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/isodoc/presentation_function/image.rb', line 40

def svg_emf_double(img)
  if emf?(img["mimetype"])
    img = emf_encode(img)
    img.children.first.previous = emf_to_svg(img)
  elsif img["mimetype"] == "image/svg+xml"
    src = svg_to_emf(img) and img << "<emf src='#{src}'/>"
  end
end

#svg_extract(elem) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/isodoc/presentation_function/image.rb', line 17

def svg_extract(elem)
  return unless %r{^data:image/svg\+xml;}.match?(elem["src"])

  svg = Base64.strict_decode64(elem["src"]
    .sub(%r{^data:image/svg\+xml;(charset=[^;]+;)?base64,}, ""))
  x = Nokogiri::XML.fragment(svg.sub(/<\?xml[^>]*>/, "")) do |config|
    config.huge
  end
  elem["src"] = ""
  elem.children = x
end

#svg_to_emf(node) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/isodoc/presentation_function/image.rb', line 64

def svg_to_emf(node)
  uri = svg_to_emf_uri(node)
  ret = svg_to_emf_filename(uri)
  File.exists?(ret) and return ret
  exe = inkscape_installed? or return nil
  uri = Metanorma::Utils::external_path uri
  exe = Metanorma::Utils::external_path exe
  system(%(#{exe} --export-type="emf" #{uri})) and
    return Metanorma::Utils::datauri(ret)

  warn %(Fail on #{exe} --export-type="emf" #{uri})

  nil
end

#svg_to_emf_filename(uri) ⇒ Object



92
93
94
# File 'lib/isodoc/presentation_function/image.rb', line 92

def svg_to_emf_filename(uri)
  "#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.emf"
end

#svg_to_emf_uri(node) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/isodoc/presentation_function/image.rb', line 79

def svg_to_emf_uri(node)
  uri = if node&.elements&.first&.name == "svg"
          a = Base64.strict_encode64(node.children.to_xml)
          "data:image/svg+xml;base64,#{a}"
        else node["src"]
        end
  if %r{^data:}.match?(uri)
    uri = save_dataimage(uri)
    @tempfile_cache << uri
  end
  uri
end

#table(docxml) ⇒ Object



110
111
112
113
114
# File 'lib/isodoc/presentation_function/block.rb', line 110

def table(docxml)
  docxml.xpath(ns("//table")).each do |f|
    table1(f)
  end
end

#table1(elem) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/isodoc/presentation_function/block.rb', line 116

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, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.table} #{n}"),
              "name")
end

#term(docxml) ⇒ Object



36
37
38
39
40
# 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) ⇒ Object



42
43
44
45
# 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) ⇒ Object



193
194
195
196
197
# File 'lib/isodoc/presentation_function/terms.rb', line 193

def termdefinition(docxml)
  docxml.xpath(ns("//term[definition]")).each do |f|
    termdefinition1(f)
  end
end

#termdefinition1(elem) ⇒ Object



199
200
201
202
# File 'lib/isodoc/presentation_function/terms.rb', line 199

def termdefinition1(elem)
  unwrap_definition(elem)
  multidef(elem) if elem.xpath(ns("./definition")).size > 1
end

#termexample(docxml) ⇒ Object



175
176
177
178
179
# File 'lib/isodoc/presentation_function/terms.rb', line 175

def termexample(docxml)
  docxml.xpath(ns("//termexample")).each do |f|
    example1(f)
  end
end

#termnote(docxml) ⇒ Object



181
182
183
184
185
# File 'lib/isodoc/presentation_function/terms.rb', line 181

def termnote(docxml)
  docxml.xpath(ns("//termnote")).each do |f|
    termnote1(f)
  end
end

#termnote1(elem) ⇒ Object

introduce name element



188
189
190
191
# File 'lib/isodoc/presentation_function/terms.rb', line 188

def termnote1(elem)
  lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
  prefix_name(elem, "", lower2cap(lbl), "name")
end

#terms(docxml) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/isodoc/presentation_xml_convert.rb', line 66

def terms(docxml)
  termexample docxml
  termnote docxml
  termdefinition docxml
  designation docxml
  termsource docxml
  concept docxml
  related docxml
end

#termsource(docxml) ⇒ Object



223
224
225
226
227
228
229
230
# File 'lib/isodoc/presentation_function/terms.rb', line 223

def termsource(docxml)
  docxml.xpath(ns("//termsource/modification")).each do |f|
    termsource_modification(f)
  end
  docxml.xpath(ns("//termsource")).each do |f|
    termsource1(f)
  end
end

#termsource1(elem) ⇒ Object



232
233
234
235
236
237
# File 'lib/isodoc/presentation_function/terms.rb', line 232

def termsource1(elem)
  while elem&.next_element&.name == "termsource"
    elem << "; #{elem.next_element.remove.children.to_xml}"
  end
  elem.children = l10n("[#{@i18n.source}: #{elem.children.to_xml.strip}]")
end

#termsource_modification(mod) ⇒ Object



239
240
241
242
243
244
245
# File 'lib/isodoc/presentation_function/terms.rb', line 239

def termsource_modification(mod)
  mod.previous_element.next = ", #{@i18n.modified}"
  mod.text.strip.empty? or mod.previous = " &#x2013; "
  mod.elements.size == 1 and
    mod.elements[0].replace(mod.elements[0].children)
  mod.replace(mod.children)
end

#toc(docxml) ⇒ Object



93
94
95
96
97
98
# 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

#toXML(result, filename) ⇒ Object



81
82
83
# File 'lib/isodoc/presentation_xml_convert.rb', line 81

def toXML(result, filename)
  File.open(filename, "w:UTF-8") { |f| f.write(result) }
end

#trim_hash(hash) ⇒ Object



103
104
105
106
107
108
109
110
# 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) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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_localiserObject



68
69
70
71
72
# 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_symbolsObject



59
60
61
# File 'lib/isodoc/presentation_function/math.rb', line 59

def twitter_cldr_localiser_symbols
  {}
end

#twitter_cldr_reader(locale) ⇒ Object



63
64
65
66
# 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

#unwrap_definition(elem) ⇒ Object



214
215
216
217
218
219
220
221
# File 'lib/isodoc/presentation_function/terms.rb', line 214

def unwrap_definition(elem)
  elem.xpath(ns("./definition")).each do |d|
    %w(verbal-definition non-verbal-representation).each do |e|
      v = d&.at(ns("./#{e}"))
      v&.replace(v.children)
    end
  end
end

#variant(docxml) ⇒ Object



163
164
165
166
167
168
169
170
171
172
# File 'lib/isodoc/presentation_function/inline.rb', line 163

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) ⇒ Object



174
175
176
177
178
179
180
# File 'lib/isodoc/presentation_function/inline.rb', line 174

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) ⇒ Object



143
144
145
# File 'lib/isodoc/presentation_function/inline.rb', line 143

def xref(docxml)
  docxml.xpath(ns("//xref")).each { |f| xref1(f) }
end

#xref1(node) ⇒ Object



159
160
161
# File 'lib/isodoc/presentation_function/inline.rb', line 159

def xref1(node)
  get_linkend(node)
end