Class: IsoDoc::PresentationXMLConvert

Inherits:
Convert show all
Defined in:
lib/isodoc/presentation_xml_convert.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

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, #metadata_init, #middle_clause, #populate_css, #precompiled_style_or_original, #scss_fontheader, #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, #image_localfile, #insert_tab, #labelled_ancestor, #liquid, #noko, #ns, #populate_template, #save_dataimage, #sentence_join, #to_xhtml, #to_xhtml_fragment

Methods included from Function::ToWordHtml

#body_attr, #boilerplate, #define_head, #in_sourcecode, #info, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #middle, #middle_admonitions, #middle_title, #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, #format_ref, #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

#bookmark_parse, #br_parse, #callout_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::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, #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

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



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

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

Instance Method Details

#amend(docxml) ⇒ Object

we use this to eliminate the semantic amend blocks from rendering



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

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

#amend1(f) ⇒ Object



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

def amend1(f)
  f.xpath(ns("./autonumber")).each { |a| a.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



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



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

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"]]) &&
  linkend = prefix_container(container, linkend, node["target"])
  capitalise_xref(node, linkend)
end

#annex(docxml) ⇒ Object



21
22
23
24
25
# File 'lib/isodoc/presentation_function/section.rb', line 21

def annex(docxml)
  docxml.xpath(ns("//annex")).each do |f|
    annex1(f)
  end
end

#annex1(f) ⇒ Object



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

def annex1(f)
  lbl = @xrefs.anchor(f['id'], :label)
  if t = f.at(ns("./title"))
    t.children = "<strong>#{t.children.to_xml}</strong>"
  end
  prefix_name(f, "<br/><br/>", lbl, "title")
end

#bibdata(docxml) ⇒ Object



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

def bibdata(docxml)
  a = bibdata_current(docxml) or return
  bibdata_i18n(a)
  a.next =
    "<localized-strings>#{i8n_name(trim_hash(@i18n.get), "").join("")}"\
    "</localized-strings>"
end

#bibdata_current(docxml) ⇒ Object



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

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



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

def bibdata_i18n(b)
  hash_translate(b, @i18n.get["doctype_dict"], "./ext/doctype")
  hash_translate(b, @i18n.get["stage_dict"], "./status/stage")
  hash_translate(b, @i18n.get["substage_dict"], "./status/substage")
end

#blank?(v) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#block(docxml) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/isodoc/presentation_xml_convert.rb', line 37

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



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

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}/)
  prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
    node.xpath("./preceding::text()")
  (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ?
    linkend&.capitalize : linkend
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(f) ⇒ Object



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

def clause1(f)
  level = @xrefs.anchor(f['id'], :level, false) || "1"
  t = f.at(ns("./title")) and t["depth"] = level
  return if !f.ancestors("boilerplate").empty?
  return if @suppressheadingnumbers || f["unnumbered"]
  lbl = @xrefs.anchor(f['id'], :label,
                      f.parent.name != "sections") or return
  prefix_name(f, "<tab/>", "#{lbl}#{clausedelim}", "title")
end

#concept(docxml) ⇒ Object



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

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

#concept1(node) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/isodoc/presentation_function/inline.rb', line 143

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

#conversions(docxml) ⇒ Object



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

def conversions(docxml)
  bibdata docxml
  section docxml
  block docxml
  inline docxml
end

#convert1(docxml, filename, dir) ⇒ Object



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

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



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

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

#eref(docxml) ⇒ Object



123
124
125
# File 'lib/isodoc/presentation_function/inline.rb', line 123

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

#eref_localities(refs, target) ⇒ Object

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



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

def eref_localities(refs, target)
  ret = ""
  refs.each_with_index do |r, i|
    delim = ","
    delim = ";" if r.name == "localityStack" && i>0
    ret = eref_locality_stack(r, i, target, delim, ret)
  end
  ret
end

#eref_localities0(r, i, target, delim) ⇒ Object



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

def eref_localities0(r, i, target, delim)
  if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
  else
    eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
                     r.at(ns("./referenceTo")), delim, @lang)
  end
end

#eref_localities1(target, type, from, to, delim, lang = "en") ⇒ Object

TODO: move to localization file



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

def eref_localities1(target, type, from, to, delim, lang = "en")
  return "" if type == "anchor"
  lang == "zh" and
    return l10n(eref_localities1_zh(target, type, from, to, delim))
  ret = delim
  loc = @i18n.locality[type] || type.sub(/^locality:/, "").capitalize
  ret += " #{loc}"
  ret += " #{from.text}" if from
  ret += "&ndash;#{to.text}" if to
  l10n(ret)
end

#eref_localities1_zh(target, type, from, to, delim) ⇒ Object

TODO: move to localization file



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

def eref_localities1_zh(target, type, from, to, delim)
  ret = "#{delim}#{from.text}" if from
  ret += "&ndash;#{to.text}" if to
  loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
  ret += " #{loc}"
  ret
end

#eref_locality_stack(r, i, target, delim, ret) ⇒ Object



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

def eref_locality_stack(r, i, target, delim, ret)
  if r.name == "localityStack"
    r.elements.each_with_index do |rr, j|
      ret += eref_localities0(rr, j, target, delim)
      delim = ","
    end
  else
    ret += eref_localities0(r, i, target, delim)
  end
  ret
end

#example(docxml) ⇒ Object



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

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

#example1(f) ⇒ Object



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

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



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

def figure(docxml)
  docxml.xpath(ns("//figure")).each do |f|
    figure1(f)
  end
  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



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

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



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

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

#formula1(f) ⇒ Object

introduce name element



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

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

#found_matching_variant_sibling(node) ⇒ Object



241
242
243
244
245
246
247
248
249
250
# File 'lib/isodoc/presentation_function/inline.rb', line 241

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

#get_linkend(n) ⇒ Object



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

def get_linkend(n)
  contents = non_locality_elems(n).select { |c| !c.text? || /\S/.match(c) }
  return unless contents.empty?
  link = anchor_linkend(n, docid_l10n(n["target"] || n["citeas"]))
  link += eref_localities(n.xpath(ns("./locality | ./localityStack")), link)
  non_locality_elems(n).each { |n| n.remove }
  n.add_child(link)
end

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



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

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



42
43
44
# File 'lib/isodoc/presentation_function/bibdata.rb', line 42

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

#i18n_tag(k, v) ⇒ Object



38
39
40
# File 'lib/isodoc/presentation_function/bibdata.rb', line 38

def i18n_tag(k, v)
  "<localized-string key='#{k}' language='#{@lang}'>#{v}</localized-string>"
end

#i8n_name(h, pref) ⇒ Object



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

def i8n_name(h, pref)
  if h.is_a? Hash then i8n_name1(h, pref)
  elsif h.is_a? Array
    h.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, h)]
  end
end

#i8n_name1(h, pref) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/isodoc/presentation_function/bibdata.rb', line 57

def i8n_name1(h, pref)
  h.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



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

def index(docxml)
  docxml.xpath(ns("//index | //index-xref")).each do |f|
    f.remove
  end
end

#inline(docxml) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/presentation_xml_convert.rb', line 52

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

#localize_maths(f, locale) ⇒ Object

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



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

def localize_maths(f, locale)
  f.xpath(".//m:mn", MATHML).each do |x|
    num = /\./.match(x.text) ? x.text.to_f : x.text.to_i
    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 twiiter cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually



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

def localized_number(num, locale, precision)
  localized = precision == 0 ? num.localize(locale).to_s :
    num.localize(locale).to_decimal.to_s(:precision => 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

#lower2cap(s) ⇒ Object



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

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

#mathml(docxml) ⇒ Object



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

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

#mathml1(f, locale) ⇒ Object



211
212
213
214
215
216
217
218
219
# File 'lib/isodoc/presentation_function/inline.rb', line 211

def mathml1(f, locale)
  localize_maths(f, locale)
  return unless f.elements.size == 1 && f.elements.first.name == "mn"
  if f.parent.name == "stem"
    f.parent.replace(f.at("./m:mn", MATHML).children)
  else
    f.replace(f.at("./m:mn", MATHML).children)
  end
end

#nearest_block_parent(node) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/isodoc/presentation_function/inline.rb', line 42

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



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

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

#note(docxml) ⇒ Object



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

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

#note1(f) ⇒ Object

introduce name element



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

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



127
128
129
# File 'lib/isodoc/presentation_function/inline.rb', line 127

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

#permission(docxml) ⇒ Object



123
124
125
126
127
# File 'lib/isodoc/presentation_function/block.rb', line 123

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

#postprocess(result, filename, dir) ⇒ Object



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

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(f, delim, number, elem) ⇒ Object



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

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



131
132
133
# File 'lib/isodoc/presentation_function/inline.rb', line 131

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

#recommendation(docxml) ⇒ Object



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

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

#recommendation1(f, type) ⇒ Object

introduce name element



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

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



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

def references(docxml)
end

#requirement(docxml) ⇒ Object



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

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

#section(docxml) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/isodoc/presentation_xml_convert.rb', line 29

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

#sourcecode(docxml) ⇒ Object



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

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

#sourcecode1(f) ⇒ Object



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

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

#table(docxml) ⇒ Object



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

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

#table1(f) ⇒ Object



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

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



35
36
37
38
39
# File 'lib/isodoc/presentation_function/section.rb', line 35

def term(docxml)
  docxml.xpath(ns("//term")).each do |f|
    term1(f)
  end
end

#term1(f) ⇒ Object



41
42
43
44
# File 'lib/isodoc/presentation_function/section.rb', line 41

def term1(f)
  lbl = @xrefs.get[f["id"]][:label] or return
  prefix_name(f, "", "#{lbl}#{clausedelim}", "name")
end

#termexample(docxml) ⇒ Object



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

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

#termnote(docxml) ⇒ Object



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

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

#termnote1(f) ⇒ Object

introduce name element



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

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

#toXML(result, filename) ⇒ Object



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

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

#trim_hash(h) ⇒ Object



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

def trim_hash(h)
  loop do
    h_new = trim_hash1(h)
    break h if h==h_new
    h = h_new
  end
end

#trim_hash1(h) ⇒ Object



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

def trim_hash1(h)
  return h unless h.is_a? Hash
  h.each_with_object({}) do |(k,v), g|
    next if blank?(v)
    g[k] = if v.is_a? Hash then trim_hash1(h[k])
           elsif v.is_a? Array
             h[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) }
           else
             v
           end
  end
end

#twitter_cldr_localiserObject



205
206
207
208
209
# File 'lib/isodoc/presentation_function/inline.rb', line 205

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



196
197
198
# File 'lib/isodoc/presentation_function/inline.rb', line 196

def twitter_cldr_localiser_symbols
  {}
end

#twitter_cldr_reader(locale) ⇒ Object



200
201
202
203
# File 'lib/isodoc/presentation_function/inline.rb', line 200

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

#variant(docxml) ⇒ Object



221
222
223
224
225
226
227
228
229
# File 'lib/isodoc/presentation_function/inline.rb', line 221

def variant(docxml)
  docxml.xpath(ns("//variant")).each { |f| variant1(f) }
  docxml.xpath(ns("//variant[@remove = 'true']")).each { |f| f.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



231
232
233
234
235
236
237
238
239
# File 'lib/isodoc/presentation_function/inline.rb', line 231

def variant1(node)
  if (!node["lang"] || node["lang"] == @lang) &&
      (!node["script"] || node["script"] == @script)
  elsif found_matching_variant_sibling(node)
    node["remove"] = "true"
  else
    #return unless !node.at("./preceding-sibling::xmlns:variant")
  end
end

#xref(docxml) ⇒ Object



119
120
121
# File 'lib/isodoc/presentation_function/inline.rb', line 119

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

#xref1(f) ⇒ Object



135
136
137
# File 'lib/isodoc/presentation_function/inline.rb', line 135

def xref1(f)
  get_linkend(f)
end