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/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

#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

#date_range, #liquid, #ns

Methods included from Function::Utils

#attr_code, #date_range, #empty2nil, #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_title, #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

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_reference_format, #table_get_or_make_tfoot, #table_long_strings_cleanup, #table_note_cleanup, #termref_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, #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

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



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

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



165
166
167
168
169
# File 'lib/isodoc/presentation_function/block.rb', line 165

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

#amend1(f) ⇒ Object



171
172
173
174
175
176
# File 'lib/isodoc/presentation_function/block.rb', line 171

def amend1(f)
  f.xpath(ns("./autonumber")).each(&:remove)
  f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
  f.xpath(ns("./description")).each { |a| a.replace(a.children) }
  f.replace(f.children)
end

#anchor_linkend(node, linkend) ⇒ Object



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

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



21
22
23
24
25
26
27
28
# File 'lib/isodoc/presentation_function/inline.rb', line 21

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

#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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/isodoc/presentation_xml_convert.rb', line 40

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

#capitalise_xref(node, linkend) ⇒ Object



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

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



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

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

#concept(docxml) ⇒ Object



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

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

#concept1(node) ⇒ Object



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

def concept1(node)
  content = node.first_element_child.children.reject do |c|
    %w{locality localityStack}.include? c.name
  end.select { |c| !c.text? || /\S/.match(c) }
  n = if content.empty?
        @i18n.term_defined_in.sub(/%/, node.first_element_child.to_xml)
      else
        "<em>#{node.children.to_xml}</em>"
      end
  node.replace(n)
end

#conversions(docxml) ⇒ Object



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



15
16
17
18
19
20
21
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/isodoc/presentation_function/math.rb', line 47

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



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/isodoc/presentation_function/section.rb', line 76

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



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

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



68
69
70
71
72
73
74
# File 'lib/isodoc/presentation_function/section.rb', line 68

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

#eref(docxml) ⇒ Object



144
145
146
# 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) ⇒ Object

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



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

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



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

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



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/isodoc/presentation_function/inline.rb', line 115

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



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

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



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/isodoc/presentation_function/inline.rb', line 127

def eref_locality_populate(type, node)
  return "" if node["droploc"] == "true"

  loc = @i18n.locality[type] || type.sub(/^locality:/, "")
  loc = case node["case"]
        when "capital" then loc.capitalize
        when "lowercase" then loc.downcase
        else
          loc.capitalize
        end
  " #{loc}"
end

#eref_locality_stack(ref, idx, target, delim, ret, node) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/isodoc/presentation_function/inline.rb', line 85

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



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

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

#example1(f) ⇒ Object



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

def example1(f)
  n = @xrefs.get[f["id"]]
  lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example:
    l10n("#{@i18n.example} #{n[:label]}")
  prefix_name(f, "&nbsp;&mdash; ", lbl, "name")
end

#figure(docxml) ⇒ Object



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



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

def figure1(f)
  return sourcecode1(f) if f["class"] == "pseudocode" || f["type"] == "pseudocode"
  return if labelled_ancestor(f) && f.ancestors("figure").empty?
  return if f.at(ns("./figure")) and !f.at(ns("./name"))

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

#formula(docxml) ⇒ Object



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

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

#formula1(f) ⇒ Object

introduce name element



73
74
75
76
# File 'lib/isodoc/presentation_function/block.rb', line 73

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

#get_linkend(node) ⇒ Object



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

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



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

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

#inline(docxml) ⇒ Object



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

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

#localize_maths(node, locale) ⇒ Object

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



17
18
19
20
21
22
23
# File 'lib/isodoc/presentation_function/math.rb', line 17

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



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

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



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

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



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

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

  s.capitalize
end

#mathml(docxml) ⇒ Object



8
9
10
11
12
13
# File 'lib/isodoc/presentation_function/math.rb', line 8

def mathml(docxml)
  locale = twitter_cldr_localiser
  docxml.xpath("//m:math", MATHML).each do |f|
    mathml1(f, locale)
  end
end

#mathml1(node, locale) ⇒ Object



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

def mathml1(node, locale)
  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) ⇒ Object



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

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



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

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

#note(docxml) ⇒ Object



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

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

#note1(f) ⇒ Object

introduce name element



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

def note1(f)
  return if f.parent.name == "bibitem"

  n = @xrefs.get[f["id"]]
  lbl = (@i18n.note if n.nil? || n[:label].nil? || n[:label].empty?) ?
    @i18n.note: l10n("#{@i18n.note} #{n[:label]}")
  prefix_name(f, "", lbl, "name")
end

#origin(docxml) ⇒ Object



148
149
150
# 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) ⇒ Object



137
138
139
140
141
# File 'lib/isodoc/presentation_function/block.rb', line 137

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

#postprocess(result, filename, _dir) ⇒ Object



65
66
67
68
# File 'lib/isodoc/presentation_xml_convert.rb', line 65

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

#prefix_container(container, linkend, _target) ⇒ Object



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

def prefix_container(container, linkend, _target)
  l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
end

#prefix_name(f, delim, number, elem) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/isodoc/presentation_function/block.rb', line 40

def prefix_name(f, delim, number, elem)
  return if number.nil? || number.empty?

  unless name = f.at(ns("./#{elem}"))
    f.children.empty? and f.add_child("<#{elem}></#{elem}>") or
      f.children.first.previous = "<#{elem}></#{elem}>"
      name = f.children.first
  end
  name.children.empty? ? name.add_child(number) :
    ( name.children.first.previous = "#{number}#{delim}" )
end

#quotesource(docxml) ⇒ Object



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

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

#recommendation(docxml) ⇒ Object



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

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

#recommendation1(f, type) ⇒ Object

introduce name element



144
145
146
147
148
# File 'lib/isodoc/presentation_function/block.rb', line 144

def recommendation1(f, type)
  n = @xrefs.anchor(f["id"], :label, false)
  lbl = (n.nil? ? type : l10n("#{type} #{n}"))
  prefix_name(f, "", lbl, "name")
end

#references(docxml) ⇒ Object



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

def references(docxml)
end

#requirement(docxml) ⇒ Object



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

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

#section(docxml) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/isodoc/presentation_xml_convert.rb', line 31

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

#sourcecode(docxml) ⇒ Object



52
53
54
55
56
# File 'lib/isodoc/presentation_function/block.rb', line 52

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

#sourcecode1(f) ⇒ Object



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

def sourcecode1(f)
  return if labelled_ancestor(f)
  return unless f.ancestors("example").empty?

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

#svg_extract(f) ⇒ Object



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

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

  svg = Base64.strict_decode64(f["src"]
    .sub(%r{^data:image/svg\+xml;base64,}, ""))
  f.replace(svg.sub(/<\?xml[^>]*>/, ""))
end

#table(docxml) ⇒ Object



150
151
152
153
154
# File 'lib/isodoc/presentation_function/block.rb', line 150

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

#table1(f) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/isodoc/presentation_function/block.rb', line 156

def table1(f)
  return if labelled_ancestor(f)
  return if f["unnumbered"] && !f.at(ns("./name"))

  n = @xrefs.anchor(f["id"], :label, false)
  prefix_name(f, "&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

#termexample(docxml) ⇒ Object



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

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

#termnote(docxml) ⇒ Object



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

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

#termnote1(f) ⇒ Object

introduce name element



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

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

#toXML(result, filename) ⇒ Object



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

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



67
68
69
70
71
# File 'lib/isodoc/presentation_function/math.rb', line 67

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



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

def twitter_cldr_localiser_symbols
  {}
end

#twitter_cldr_reader(locale) ⇒ Object



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

def twitter_cldr_reader(locale)
  num = TwitterCldr::DataReaders::NumberDataReader.new(locale)
  num.symbols.merge!(twitter_cldr_localiser_symbols)
end

#variant(docxml) ⇒ Object



176
177
178
179
180
181
182
183
184
185
# File 'lib/isodoc/presentation_function/inline.rb', line 176

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



187
188
189
190
191
192
193
# File 'lib/isodoc/presentation_function/inline.rb', line 187

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



140
141
142
# File 'lib/isodoc/presentation_function/inline.rb', line 140

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

#xref1(node) ⇒ Object



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

def xref1(node)
  get_linkend(node)
end