Class: IsoDoc::ITU::PresentationXMLConvert

Inherits:
PresentationXMLConvert
  • Object
show all
Includes:
Init
Defined in:
lib/isodoc/itu/presentation_ref.rb,
lib/isodoc/itu/presentation_bibdata.rb,
lib/isodoc/itu/presentation_preface.rb,
lib/isodoc/itu/presentation_xml_convert.rb,
lib/isodoc/itu/presentation_contribution.rb

Instance Method Summary collapse

Methods included from Init

#bibrenderer, #fileloc, #i18n_init, #metadata_init, #xref_init

Constructor Details

#initialize(options) ⇒ PresentationXMLConvert

Returns a new instance of PresentationXMLConvert.



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

def initialize(options)
  @hierarchical_assets = options[:hierarchicalassets]
  super
end

Instance Method Details

#abstract_render(abstract) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/isodoc/itu/presentation_preface.rb', line 84

def abstract_render(abstract)
  abstract or return
  @doctype == "contribution" or return
  abstract.at(ns("./title"))&.remove
  abstract.children = <<~TABLE
    <table class="abstract" unnumbered="true" width="100%">
    <colgroup><col width="11.8%"/><col width="78.2%"/></colgroup>
    <tbody>
    <tr><th align="left" width="95"><p>#{colon_i18n(@i18n.abstract)}</p></th>
    <td>#{abstract.children.to_xml}</td></tr>
    </tbody></table>
  TABLE
end

#amendment_id(bib) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 79

def amendment_id(bib)
  %w(amendment corrigendum).each do |w|
    if dn = bib.at(ns("./ext/structuredidentifier/#{w}"))
      dn["language"] = ""
      dn.next = dn.dup
      dn.next["language"] = @lang
      dn.next.children = @i18n.l10n("#{@i18n.get[w]} #{dn.text}")
    end
  end
end

#annex1(elem) ⇒ Object



105
106
107
108
109
110
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 105

def annex1(elem)
  @doctype == "resolution" or return super
  elem.elements.first.previous = annex1_supertitle(elem)
  t = elem.at(ns("./title")) and
    t.children = "<strong>#{to_xml(t.children)}</strong>"
end

#annex1_supertitle(elem) ⇒ Object



112
113
114
115
116
117
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 112

def annex1_supertitle(elem)
  lbl = @xrefs.anchor(elem["id"], :label)
  res = elem.at(ns("//bibdata/title[@type = 'resolution']"))
  subhead = @i18n.l10n("(#{@i18n.get['to']} #{to_xml(res.children)})")
  "<p class='supertitle'>#{lbl}<br/>#{subhead}</p>"
end

#bibdata_dates(bib) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 11

def bibdata_dates(bib)
  bib.xpath(ns("./date")).each do |d|
    d.next = d.dup
    d.next["format"] = "ddMMMyyyy"
    d.next.children = ddMMMyyyy(d.text)
  end
end

#bibdata_i18n(bib) ⇒ Object



4
5
6
7
8
9
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 4

def bibdata_i18n(bib)
  super
  bibdata_dates(bib)
  bibdata_title(bib)
  amendment_id(bib)
end

#bibdata_title(bib) ⇒ Object



19
20
21
22
23
24
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 19

def bibdata_title(bib)
  case bib.at(ns("./ext/doctype"))&.text
  when "service-publication" then bibdata_title_service_population(bib)
  when "resolution" then bibdata_title_resolution(bib)
  end
end

#bibdata_title_resolution(bib) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 26

def bibdata_title_resolution(bib)
  place = bib.at(ns("./ext/meeting-place"))&.text
  year = bib.at(ns("./ext/meeting-date/from | ./ext/meeting-date/on"))
    &.text&.gsub(/-.*$/, "")
  text = bibdata_title_resolution_name(bib, place, year)
  bib.at(ns("./title")).next = <<~INS
    <title language="#{@lang}" format="text/plain" type="resolution">#{text}</title>
    <title language="#{@lang}" format="text/plain" type="resolution-placedate">#{place}, #{year}</title>
  INS
end

#bibdata_title_resolution_name(bib, place, year) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 37

def bibdata_title_resolution_name(bib, place, year)
  ed = bib.at(ns("./edition"))&.text
  rev = ed && ed != "1" ? "#{@i18n.get['revision_abbreviation']} " : ""
  num = bib.at(ns("./docnumber"))
  @i18n.l10n("#{@i18n.get['doctype_dict']['resolution'].upcase} " \
                    "#{num&.text} (#{rev}#{place}, #{year})")
end

#bibdata_title_service_population(bib) ⇒ Object



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

def bibdata_title_service_population(bib)
  date = bib&.at(ns("./date[@type = 'published']"))&.text or return
  text = l10n(@i18n.get["position_on"].sub("%", ddmmmmyyyy(date)))
  ins = bib.at(ns("./title"))
  ins.next = <<~INS
    <title language="#{@lang}" format="text/plain" type="position-sp">#{text}</title>
  INS
end

#biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/isodoc/itu/presentation_ref.rb', line 88

def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib)
  ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
  /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
  ret += datefn
  ret.empty? and return ret
  ret.gsub("-", "&#x2011;").gsub(/ /, "&#xa0;")
end

#bibliography_bibitem_number1(bib, idx) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/itu/presentation_ref.rb', line 63

def bibliography_bibitem_number1(bib, idx)
  mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and
    /^\[?\d+\]?$/.match?(mn.text) and
    mn["type"] = "metanorma-ordinal"
  if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) &&
      !bibliography_bibitem_number_skip(bib)
    idx += 1
    mn.children = "[#{idx}]"
  end
  idx
end

#bibliography_bibitem_number_skip(bibitem) ⇒ Object



75
76
77
78
# File 'lib/isodoc/itu/presentation_ref.rb', line 75

def bibliography_bibitem_number_skip(bibitem)
  @xrefs.klass.implicit_reference(bibitem) ||
    bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end

#bibrender_formattedref(formattedref, _xml) ⇒ Object



11
12
13
14
15
# File 'lib/isodoc/itu/presentation_ref.rb', line 11

def bibrender_formattedref(formattedref, _xml)
  formattedref << "." unless /\.$/.match?(formattedref.text)
  id = reference_format_start(formattedref.parent) and
    formattedref.children.first.previous = id
end

#bibrender_relaton(xml, renderings) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/isodoc/itu/presentation_ref.rb', line 17

def bibrender_relaton(xml, renderings)
  f = renderings[xml["id"]][:formattedref]
  ids = reference_format_start(xml)
  f &&= "<formattedref>#{ids}#{f}</formattedref>"
  # retain date in order to generate reference tag
  keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag"
  xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
end

#block(docxml) ⇒ Object



192
193
194
195
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 192

def block(docxml)
  super
  dl docxml
end

#bold_and_upcase(xml) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/isodoc/itu/presentation_contribution.rb', line 43

def bold_and_upcase(xml)
  x = Nokogiri::XML("<root>#{xml}</root>")
  x.traverse do |e|
    e.text? or next
    e.replace("<strong>#{e.text.upcase}</strong>")
  end
  x.root.children.to_xml
end

#capitalise_unless_text_transform(elem) ⇒ Object



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

def capitalise_unless_text_transform(elem)
  css = nil
  elem.traverse_topdown do |n|
    n.name == "span" && /text-transform:/.match?(n["style"]) and
      css = n
    n.text? && /\S/.match?(n.text) or next
    css && n.ancestors.include?(css) or
      n.replace(::Metanorma::Utils.strict_capitalize_first(n.text))
    break
  end
end

#clause1(elem) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 90

def clause1(elem)
  clause1_super?(elem) and return super
  @suppressheadingnumbers || elem["unnumbered"] and return
  t = elem.at(ns("./title")) and t["depth"] = "1"
  lbl = @xrefs.anchor(elem["id"], :label, false) or return
  elem.previous =
    "<p keep-with-next='true' class='supertitle'>" \
    "#{@i18n.get['section'].upcase} #{lbl}</p>"
end

#clause1_super?(elem) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 100

def clause1_super?(elem)
  @doctype != "resolution" ||
    !%w(sections bibliography).include?(elem.parent.name)
end

#colon_i18n(text) ⇒ Object



39
40
41
# File 'lib/isodoc/itu/presentation_contribution.rb', line 39

def colon_i18n(text)
  @i18n.l10n("#{text}:")
end

#contrib_justification_contactsObject



90
91
92
93
94
# File 'lib/isodoc/itu/presentation_contribution.rb', line 90

def contrib_justification_contacts
  (0..@meta.get[:authors]&.size).each_with_object([]) do |i, ret|
    ret << contribution_justification_contact(i)
  end
end

#contribution_justification(doc) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/isodoc/itu/presentation_contribution.rb', line 115

def contribution_justification(doc)
  @doctype == "contribution" or return
  annex = doc.at(ns("//annex[@type = 'justification']")) or return
  auths, auths_tail = contribution_justification_auths
  annex.children = <<~TABLE
    <title>#{contribution_justification_title(doc)}</title>
    <table class="contribution-metadata" unnumbered="true" width="100%">
      <colgroup><col width="15.9%"/><col width="6.1%"/><col width="45.5%"/><col width="17.4%"/><col width="15.1%"/></colgroup>
      <tbody>
      <tr>
      <th align="left">#{colon_i18n(@i18n.questions)}</th><td>#{@meta.get[:questions]}</td>
      <th align="left">Proposed new ITU-T #{@meta.get[:subdoctype]}</th>
      <td colspan="2">#{@i18n.l10n("#{@meta.get[:meeting_place]}, #{@meta.get[:meeting_date]}")}</td>
      </tr>
      <tr><th align="left">Reference and title:</th>
      <td colspan="4">Draft new #{@meta.get[:subdoctype]} on “#{@meta.get[:doctitle_en]}”</td>
      </tr>
      <tr>
      <th align="left">Base text:</th><td colspan="2">#{extract_clause_data(annex, 'basetext')}</td>
      <th align="left">Timing:</th><td>#{@meta.get[:timing]}</td>
      </tr>
      <tr><th align="left" rowspan="#{auths.size - 1}">Editor(s):</th>
      <td colspan="2">#{auths[0]}</td>
      <th align="left" rowspan="#{auths.size - 1}">Approval process:</th>
      <td rowspan="#{auths.size - 1}">#{@meta.get[:approval_process]}</td>
      </tr>
      #{auths_tail}
      <tr><td colspan="5"><p><strong>Scope</strong> (defines the intent or object of the Recommendation and the aspects covered, thereby indicating the limits of its applicability):</p>#{extract_clause_data(annex, 'scope')}</td></tr>
      <tr><td colspan="5"><p><strong>Summary</strong> (provides a brief overview of the purpose and contents of the Recommendation, thus permitting readers to judge its usefulness for their work):</p>#{extract_clause_data(annex, 'summary')}</td></tr>
      <tr><td colspan="5"><p><strong>Relations to ITU-T Recommendations or to other standards</strong> (approved or under development):</p>#{extract_clause_data(annex, 'relatedstandards')}</td></tr>
      <tr><td colspan="5"><p><strong>Liaisons with other study groups or with other standards bodies:</strong></p>#{extract_clause_data(annex, 'liaisons')}</td></tr>
      <tr><td colspan="5"><p><strong>Supporting members that are committing to contributing actively to the work item:</strong></p>#{extract_clause_data(annex, 'supportingmembers')}</td></tr>
      </tbody>
    </table>
  TABLE
end

#contribution_justification_authsObject



107
108
109
110
111
112
113
# File 'lib/isodoc/itu/presentation_contribution.rb', line 107

def contribution_justification_auths
  auths = contrib_justification_contacts
  auths_tail = auths[1..auths.size].map do |x|
    "<tr><td colspan='2'>#{x}</td></td>"
  end.join("\n")
  [auths, auths_tail]
end

#contribution_justification_contact(idx) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/isodoc/itu/presentation_contribution.rb', line 80

def contribution_justification_contact(idx)
  @meta.get[:emails][idx] and
    e = ", #{@i18n.email}<tab/>#{@meta.get[:emails][idx]}"
  <<~CELL
    #{@meta.get[:authors][idx]}<br/>
    #{@meta.get[:affiliations][idx]}<br/>
    #{@meta.get[:addresses][idx]}#{e}
  CELL
end

#contribution_justification_title(_doc) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/isodoc/itu/presentation_contribution.rb', line 96

def contribution_justification_title(_doc)
  n = @meta.get[:docnumber]
  if @meta.get[:subdoctype] == "recommendation"
    "A.1 justification for proposed draft new Recommendation #{n}"
  else
    s = @meta.get[:subdoctype]
    "A.13 justification for proposed draft new #{s} "\
      "#{n}#{@meta.get[:doctitle_en]}"
  end
end

#contribution_table(_doc) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/isodoc/itu/presentation_contribution.rb', line 10

def contribution_table(_doc)
  @doctype == "contribution" or return
  bureau = bold_and_upcase(@meta.get[:bureau_full])
  <<~TABLE
    <clause unnumbered="true" type="contribution-metadata">
    <table class="contribution-metadata" unnumbered="true" width="100%">
    <colgroup><col width="11.8%"/><col width="41.2%"/><col width="47.0%"/></colgroup>
    <thead>
    <tr><th rowspan="3"><image height="56" width="56" src="#{@meta.get[:logo_small]}"/></th>
    <td rowspan="3"><p style="font-size:8pt;margin-top:6pt;margin-bottom:0pt;">#{@i18n.international_telecommunication_union.upcase}</p>
    <p class="bureau_big" style="font-size:13pt;margin-top:6pt;margin-bottom:0pt;">#{bureau}</p>
    <p style="font-size:10pt;margin-top:6pt;margin-bottom:0pt;">#{@i18n.studyperiod.sub('%', @meta.get[:study_group_period]).upcase}</p></th>
    <th align="right"><p style="font-size:16pt;">#{@meta.get[:docnumber]}</p></th></tr>
    <tr><th align="right"><p  style="font-size:14pt;">#{@meta.get[:group].upcase}</p></th></tr>
    <tr>
    <th align="right"><p style="font-size:14pt;">#{@i18n.l10n("#{@i18n.original}: #{@i18n.current_language}")}</p></th>
    </tr></thead>
    <tbody>
    <tr><th align="left" width="95">#{colon_i18n(@i18n.questions)}</th><td>#{@meta.get[:questions]}</td>
    <td align="right">#{@i18n.l10n("#{@meta.get[:meeting_place]}, #{@meta.get[:meeting_date]}")}</td></tr>
    <tr><th align="center" colspan="3">#{@i18n.get['doctype_dict']['contribution'].upcase}</th></tr>
    <tr><th align="left" width="95">#{colon_i18n(@i18n.document_source)}</th><td colspan="2">#{@meta.get[:source]}</td></tr>
    <tr><th align="left" width="95">#{colon_i18n(@i18n.title)}</th><td colspan="2">#{@meta.get[:doctitle_en]}</td></tr>
    #{contribution_table_contacts}
    </tbody></table>
    </clause>
  TABLE
end

#contribution_table_contact(idx) ⇒ Object



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

def contribution_table_contact(idx)
  @meta.get[:emails][idx] and
    e = "<br/>#{@i18n.email}<tab/>#{@meta.get[:emails][idx]}"
  <<~CELL
    <td>#{@meta.get[:authors][idx]}<br/>
    #{@meta.get[:affiliations][idx]}<br/>
    #{@meta.get[:addresses][idx]}</td>
    <td>#{@i18n.tel_abbrev}<tab/>#{@meta.get[:phones][idx]}#{e}</td>
  CELL
end

#contribution_table_contactsObject



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

def contribution_table_contacts
  n = (0..@meta.get[:authors]&.size).each_with_object([]) do |i, ret|
    ret << contribution_table_contact(i)
  end
  n.map do |x|
    lbl = colon_i18n(@i18n.contact)
    "<tr><th align='left' width='95'>#{lbl}</th>#{x}</tr>"
  end.join("\n")
end

#contribution_table_insert_pt(docxml) ⇒ Object



4
5
6
7
8
# File 'lib/isodoc/itu/presentation_contribution.rb', line 4

def contribution_table_insert_pt(docxml)
  docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
    .add_previous_sibling("<preface> </preface>").first
  docxml.at(ns("//preface")).children.first.before(" ").previous
end

#ddmmmmyyyy(date) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 71

def ddmmmmyyyy(date)
  @lang == "zh" and return ddMMMyyyy(date)
  d = date.split("-")
  d[1] &&= @meta.months[d[1].to_sym]
  d[2] &&= d[2].sub(/^0/, "")
  l10n(d.reverse.join(" "))
end

#ddMMMyyyy(date) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/itu/presentation_bibdata.rb', line 54

def ddMMMyyyy(date)
  d = date.split("-").map { |x| x.sub(/^0/, "") }
  case @lang
  when "zh"
    d[0] += "" if d[0]
    d[1] += "" if d[1]
    d[2] += "" if d[2]
    d.join
  when "ar"
    d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d[1]
    d.join(".")
  else
    d[1] = ::RomanNumerals.to_roman(d[1].to_i).upcase if d[1]
    d.reverse.join(".")
  end
end

#dl(xml) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 197

def dl(xml)
  (xml.xpath(ns("//dl")) -
   xml.xpath(ns("//table//dl | //figure//dl | //formula//dl")))
    .each do |d|
      dl1(d)
    end
end

#dl1(dlist) ⇒ Object



205
206
207
208
209
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 205

def dl1(dlist)
  ins = dlist.at(ns("./dt"))
  ins.previous =
    '<colgroup><col width="20%"/><col width="80%"/></colgroup>'
end

#doctype_title(id, bib) ⇒ Object



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

def doctype_title(id, bib)
  type = bib.at(ns("./ext/doctype"))&.text || "recommendation"
  if type == "recommendation" &&
      /^(?<prefix>ITU-[A-Z][  ][A-Z])[  .-]Sup[a-z]*\.[  ]?(?<num>\d+)$/ =~ id
    "#{prefix}-series Recommendations – Supplement #{num}"
  else
    d = id.sub(/^\[/, "").sub(/\]$/, "")
    "#{titlecase(type)} #{d}"
  end
end

#editor_table_entries(eds, ed_lbl, mail_lbl) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/isodoc/itu/presentation_preface.rb', line 52

def editor_table_entries(eds, ed_lbl, mail_lbl)
  eds.each_with_index.with_object([]) do |(n, i), m|
    mail = ""
    n[:email] and
      mail = "#{mail_lbl}<link target='mailto:#{n[:email]}'>" \
             "#{n[:email]}</link>"
    aff = n[:affiliation].empty? ? "" : "<br/>#{n[:affiliation]}"
    th = "<th>#{i.zero? ? ed_lbl : ''}</th>"
    m << "<tr>#{th}<td>#{n[:name]}#{aff}</td><td>#{mail}</td></tr>"
  end.join("\n")
end

#editors_clause(eds) ⇒ Object



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

def editors_clause(eds)
  ed_lbl = @i18n.inflect(@i18n.get["editor_full"],
                         number: eds.size > 1 ? "pl" : "sg")
  ed_lbl &&= l10n("#{ed_lbl.capitalize}:")
  mail_lbl = l10n("#{@i18n.get['email']}: ")
  ret = <<~SUBMITTING
    <clause id="_#{UUIDTools::UUID.random_create}" type="editors">
    <table id="_#{UUIDTools::UUID.random_create}" unnumbered="true"><tbody>
  SUBMITTING
  ret += editor_table_entries(eds, ed_lbl, mail_lbl)
  "#{ret}</tbody></table></clause>"
end

#editors_insert_pt(docxml) ⇒ Object



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

def editors_insert_pt(docxml)
  docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
    .add_previous_sibling("<preface> </preface>").first
  ins = docxml.at(ns("//preface/acknolwedgements")) and return ins
  docxml.at(ns("//preface")).children[-1]
end

#eref(docxml) ⇒ Object



29
30
31
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 29

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

#eref1(elem) ⇒ Object



41
42
43
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 41

def eref1(elem)
  get_eref_linkend(elem)
end

#extract_clause_data(clause, type) ⇒ Object



73
74
75
76
77
78
# File 'lib/isodoc/itu/presentation_contribution.rb', line 73

def extract_clause_data(clause, type)
  x = clause.at(ns("./clause[@type = '#{type}']")) or return
  ret = x.dup
  ret.at(ns("./title"))&.remove
  ret.children.to_xml
end

#extract_editors(doc) ⇒ Object



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

def extract_editors(doc)
  e = doc.xpath(ns("//bibdata/contributor[role/@type = 'editor']/person"))
  e.empty? and return
  { names: @meta.extract_person_names(e),
    affiliations: @meta.extract_person_affiliations(e),
    emails: e.reduce([]) { |ret, p| ret << p.at(ns("./email"))&.text } }
end

#get_eref_linkend(node) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 69

def get_eref_linkend(node)
  non_locality_elems(node).select do |c|
    !c.text? || /\S/.match(c)
  end.empty? or return
  link = anchor_linkend(node,
                        docid_l10n(node["target"] || node["citeas"]))
  link && !/^\[.*\]$/.match(link) and link = "[#{link}]"
  link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
                          link, node)
  non_locality_elems(node).each(&:remove)
  node.add_child(link)
end

#insert_editors_clause(doc) ⇒ Object



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

def insert_editors_clause(doc)
  ret = extract_editors(doc) or return
  eds = ret[:names].each_with_object([]).with_index do |(_x, acc), i|
    acc << { name: ret[:names][i], affiliation: ret[:affiliations][i],
             email: ret[:emails][i] }
  end
  editors_clause(eds)
end

#insert_preface_sections(docxml) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/isodoc/itu/presentation_preface.rb', line 4

def insert_preface_sections(docxml)
  if @doctype == "contribution"
    contribution_justification(docxml)
    x = contribution_table(docxml) and
      contribution_table_insert_pt(docxml).next = x
  else
    x = insert_editors_clause(docxml) and
      editors_insert_pt(docxml).next = x
  end
end

#keywords(_docxml) ⇒ Object



98
99
100
101
102
103
# File 'lib/isodoc/itu/presentation_preface.rb', line 98

def keywords(_docxml)
  kw = @meta.get[:keywords]
  kw.nil? || kw.empty? || @doctype == "contribution" and return
  "<clause type='keyword'><title>#{@i18n.keywords}</title>" \
    "<p>#{@i18n.l10n(kw.join(', '))}.</p>"
end

#keywords_abstract_swap(abstract, keywords, docxml) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/isodoc/itu/presentation_preface.rb', line 74

def keywords_abstract_swap(abstract, keywords, docxml)
  @doctype == "contribution" and return
  k = keywords or return
  if abstract then abstract.next = k
  else
    p = contribution_table_insert_pt(docxml)
    p.next = k
  end
end

#middle_title(isoxml) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 131

def middle_title(isoxml)
  s = isoxml.at(ns("//sections")) or return
  titfn = isoxml.at(ns("//note[@type = 'title-footnote']"))
  case @doctype
  when "resolution"
    middle_title_resolution(isoxml, s.children.first)
  when "contribution"
  else
    middle_title_recommendation(isoxml, s.children.first)
  end
  titfn and renumber_footnotes(isoxml)
end

#middle_title_recommendation(isoxml, out) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 169

def middle_title_recommendation(isoxml, out)
  ret = ""
  type = @meta.get[:doctype]
  @meta.get[:unpublished] && @meta.get[:draft_new_doctype] and
    type = @meta.get[:draft_new_doctype]
  id = @meta.get[:docnumber] and
    ret += "<<p class='zzSTDTitle1'>#{type} #{id}</p>"
  t = @meta.get[:doctitle] and
    ret += "<p class='zzSTDTitle2'>#{t}"
  ret += "#{title_footnotes(isoxml)}</p>"
  s = @meta.get[:docsubtitle] and ret += "<p class='zzSTDTitle3'>#{s}</p>"
  out.previous = ret
end

#middle_title_resolution(isoxml, out) ⇒ Object



152
153
154
155
156
157
158
159
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 152

def middle_title_resolution(isoxml, out)
  res = isoxml.at(ns("//bibdata/title[@type = 'resolution']"))
  out.previous =
    "<p class='zzSTDTitle1' align='center'>#{res.children.to_xml}</p>"
  t = @meta.get[:doctitle] and
    out.previous = "<p class='zzSTDTitle2'>#{t}</p>"
  middle_title_resolution_subtitle(isoxml, out)
end

#middle_title_resolution_subtitle(isoxml, out) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 161

def middle_title_resolution_subtitle(isoxml, out)
  ret = "<p align='center' class='zzSTDTitle2'><em>("
  d = isoxml.at(ns("//bibdata/title[@type = 'resolution-placedate']"))
  ret += "#{d.children.to_xml.strip}</em>)"
  ret += "#{title_footnotes(isoxml)}</p>"
  out.previous = ret
end

#multi_bibitem_ref_code(bib) ⇒ Object



26
27
28
29
30
# File 'lib/isodoc/itu/presentation_ref.rb', line 26

def multi_bibitem_ref_code(bib)
  id = pref_ref_code_parse(bib)
  id.nil? and return []
  id.sort_by { |i| /^ITU/.match?(i) ? 0 : 1 }
end

#norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/isodoc/itu/presentation_ref.rb', line 80

def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
  ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
  /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
  ret += datefn
  ret.empty? and return ret
  ret.gsub("-", "&#x2011;").gsub(/ /, "&#xa0;")
end

#note1(elem) ⇒ Object



45
46
47
48
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 45

def note1(elem)
  elem["type"] == "title-footnote" and return
  super
end

#ol_depth(node) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 119

def ol_depth(node)
  node["class"] == "steps" ||
    node.at(".//ancestor::xmlns:ol[@class = 'steps']") or return super
  depth = node.ancestors("ul, ol").size + 1
  type = :arabic
  type = :alphabet if [2, 7].include? depth
  type = :roman if [3, 8].include? depth
  type = :alphabet_upper if [4, 9].include? depth
  type = :roman_upper if [5, 10].include? depth
  type
end

#origin(docxml) ⇒ Object



33
34
35
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 33

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

#quotesource(docxml) ⇒ Object



37
38
39
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 37

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

#rearrange_clauses(docxml) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/isodoc/itu/presentation_preface.rb', line 64

def rearrange_clauses(docxml)
  super
  insert_preface_sections(docxml)
  a = docxml.at(ns("//preface/abstract"))
  keywords_abstract_swap(a, keywords(docxml), docxml)
  c = docxml.at(ns("//preface/clause[@type='contribution-metadata']")) and
    a and c.next = a
  abstract_render(a)
end

#reference_format_start(bib) ⇒ Object



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

def reference_format_start(bib)
  id = multi_bibitem_ref_code(bib)
  id1 = render_multi_identifiers(id, bib)
  out = id1
  date = bib.at(ns("./date[@type = 'published']/on | " \
    "./date[@type = 'published']/from")) and
    out << " (#{date.text.sub(/-.*$/, '')})"
  out += ", " if date || !id1.empty?
  out
end

#render_multi_identifiers(ids, bib) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/isodoc/itu/presentation_ref.rb', line 32

def render_multi_identifiers(ids, bib)
  ids.map do |id|
    if /^ITU/.match?(id) then doctype_title(id, bib)
    else
      id.sub(/^\[/, "").sub(/\]$/, "")
    end
  end.join("&#xA0;| ")
end

#renumber_footnotes(isoxml) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 144

def renumber_footnotes(isoxml)
  (isoxml.xpath(ns("//fn")) -
   isoxml.xpath(ns("//table//fn | //figure//fn")))
    .each_with_index do |fn, i|
      fn["reference"] = (i + 1).to_s
    end
end

#table1(elem) ⇒ Object



50
51
52
53
54
55
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 50

def table1(elem)
  elem.xpath(ns("./name | ./thead/tr/th")).each do |n|
    capitalise_unless_text_transform(n)
  end
  super
end

#title_footnotes(isoxml) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 183

def title_footnotes(isoxml)
  ret = ""
  isoxml.xpath(ns("//note[@type = 'title-footnote']"))
    .each_with_index do |f, i|
      ret += "<fn reference='H#{i}'>#{f.remove.children.to_xml}</fn>"
    end
  ret
end

#titlecase(str) ⇒ Object



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

def titlecase(str)
  str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
end

#toc_title(docxml) ⇒ Object



105
106
107
108
# File 'lib/isodoc/itu/presentation_preface.rb', line 105

def toc_title(docxml)
  %w(resolution contribution).include?(@doctype) and return
  super
end

#twitter_cldr_localiser_symbolsObject



86
87
88
# File 'lib/isodoc/itu/presentation_xml_convert.rb', line 86

def twitter_cldr_localiser_symbols
  { group: "'" }
end