metanorma-bipm 0.0.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +62 -0
  3. data/README.adoc +7 -114
  4. data/lib/asciidoctor/bipm/basicdoc.rng +50 -3
  5. data/lib/asciidoctor/bipm/bipm.rng +193 -23
  6. data/lib/asciidoctor/bipm/boilerplate-en.xml +2 -3
  7. data/lib/asciidoctor/bipm/boilerplate-fr.xml +3 -4
  8. data/lib/asciidoctor/bipm/converter.rb +130 -18
  9. data/lib/asciidoctor/bipm/isodoc.rng +36 -43
  10. data/lib/isodoc/bipm/base_convert.rb +60 -0
  11. data/lib/isodoc/bipm/bipm.brochure.xsl +2548 -760
  12. data/lib/isodoc/bipm/bipm.guide.xsl +7738 -0
  13. data/lib/isodoc/bipm/bipm.mise-en-pratique.xsl +7738 -0
  14. data/lib/isodoc/bipm/bipm.rapport.xsl +7738 -0
  15. data/lib/isodoc/bipm/html/html_bipm_titlepage.html +35 -4
  16. data/lib/isodoc/bipm/html/htmlstyle.css +56 -62
  17. data/lib/isodoc/bipm/html/htmlstyle.scss +53 -77
  18. data/lib/isodoc/bipm/html/si-aspect/A_e.png +0 -0
  19. data/lib/isodoc/bipm/html/si-aspect/A_e_deltanu.png +0 -0
  20. data/lib/isodoc/bipm/html/si-aspect/K_k.png +0 -0
  21. data/lib/isodoc/bipm/html/si-aspect/K_k_deltanu_h.png +0 -0
  22. data/lib/isodoc/bipm/html/si-aspect/cd_Kcd.png +0 -0
  23. data/lib/isodoc/bipm/html/si-aspect/cd_Kcd_h_deltanu.png +0 -0
  24. data/lib/isodoc/bipm/html/si-aspect/full.png +0 -0
  25. data/lib/isodoc/bipm/html/si-aspect/kg_h.png +0 -0
  26. data/lib/isodoc/bipm/html/si-aspect/kg_h_c_deltanu.png +0 -0
  27. data/lib/isodoc/bipm/html/si-aspect/m_c.png +0 -0
  28. data/lib/isodoc/bipm/html/si-aspect/m_c_deltanu.png +0 -0
  29. data/lib/isodoc/bipm/html/si-aspect/mol_NA.png +0 -0
  30. data/lib/isodoc/bipm/html/si-aspect/s_deltanu.png +0 -0
  31. data/lib/isodoc/bipm/html_convert.rb +32 -0
  32. data/lib/isodoc/bipm/i18n-en.yaml +9 -0
  33. data/lib/isodoc/bipm/i18n-fr.yaml +22 -4
  34. data/lib/isodoc/bipm/index.rb +136 -0
  35. data/lib/isodoc/bipm/metadata.rb +34 -10
  36. data/lib/isodoc/bipm/pdf_convert.rb +13 -2
  37. data/lib/isodoc/bipm/presentation_xml_convert.rb +103 -7
  38. data/lib/isodoc/bipm/xref.rb +138 -3
  39. data/lib/metanorma/bipm.rb +7 -0
  40. data/lib/metanorma/bipm/processor.rb +11 -0
  41. data/lib/metanorma/bipm/version.rb +1 -1
  42. data/metanorma-bipm.gemspec +1 -2
  43. data/metanorma.yml +42 -1
  44. metadata +22 -21
  45. data/.github/workflows/macos.yml +0 -38
  46. data/.github/workflows/ubuntu.yml +0 -56
  47. data/.github/workflows/windows.yml +0 -40
@@ -1 +1,10 @@
1
1
  annex: Appendix
2
+ appendix: Annex
3
+ see: see
4
+ see_also: see also
5
+ clause: Chapter
6
+ subclause: Section
7
+ formula: Equation
8
+ inequality: Inequality
9
+ bibliography: References
10
+ index: Index
@@ -1,4 +1,22 @@
1
1
  annex: Annexe
2
+ appendix: Appendice
3
+ see: voir
4
+ see_also: voir aussi
5
+ clause: chapître
6
+ subclause: section
7
+ formula: équation
8
+ inequality: inégalité
9
+ bibliography: Références
10
+ note_xref: note
11
+ termnote: note % à l’article
12
+ list: liste
13
+ figure: figure
14
+ table: tableau
15
+ requirement: exigence
16
+ recommendation: recommandation
17
+ permission: autorisation
18
+ example_xref: exemple
19
+ index: Index
2
20
  doctype_dict:
3
21
  brochure: brochure
4
22
  mise-en-pratique: mise-en-pratique
@@ -12,7 +30,7 @@ doctype_dict:
12
30
  cipm-mra: cipm-mra
13
31
  resolution: résolution
14
32
  stage_dict:
15
- draft-proposal: projet-de-proposition
16
- draft-development: projet-de-développement
17
- in-force: en-vigeur
18
- retired: retiré
33
+ draft-proposal: projet-de-proposition
34
+ draft-development: projet-de-développement
35
+ in-force: en-vigeur
36
+ retired: retiré
@@ -0,0 +1,136 @@
1
+ require "twitter_cldr"
2
+ require "sterile"
3
+
4
+ module IsoDoc
5
+ module BIPM
6
+ class PresentationXMLConvert < IsoDoc::Generic::PresentationXMLConvert
7
+ def add_id
8
+ %(id="_#{UUIDTools::UUID.random_create}")
9
+ end
10
+
11
+ def index(docxml)
12
+ return unless docxml.at(ns("//index"))
13
+ i = docxml.root.add_child "<clause type='index' #{add_id}><title>#{@i18n.index}</title></clause>"
14
+ index = sort_indexterms(docxml.xpath(ns("//index")), docxml.xpath(ns("//index-xref[@also = 'false']")),
15
+ docxml.xpath(ns("//index-xref[@also = 'true']")))
16
+ index1(docxml, i, index)
17
+ end
18
+
19
+ def index1(docxml, i, index)
20
+ index.keys.sort.each do |k|
21
+ c = i.first.add_child "<clause #{add_id}><title>#{k}</title><ul></ul></clause>"
22
+ words = index[k].keys.each_with_object({}) { |w, v| v[sortable(w).downcase] = w }
23
+ words.keys.localize(@lang.to_sym).sort.to_a.each do |w|
24
+ c.first.at(ns("./ul")).add_child index_entries(words, index[k], w)
25
+ end
26
+ end
27
+ @xrefs.bookmark_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
28
+ end
29
+
30
+ def sortable(s)
31
+ HTMLEntities.new.decode(Nokogiri::XML.fragment(s).text)
32
+ end
33
+
34
+ def index_entries_opt
35
+ { xref_lbl: ", ", see_lbl: ", #{see_lbl}", also_lbl: ", #{also_lbl}" }
36
+ end
37
+
38
+ def index_entries(words, index, primary)
39
+ ret = index_entries_head(words[primary], index.dig(words[primary], nil, nil), index_entries_opt)
40
+ words2 = index[words[primary]]&.keys&.reject { |k| k.nil?}&.each_with_object({}) { |w, v| v[w.downcase] = w }
41
+ unless words2.empty?
42
+ ret += "<ul>"
43
+ words2.keys.localize(@lang.to_sym).sort.to_a.each do |w|
44
+ ret += index_entries2(words2, index[words[primary]], w)
45
+ end
46
+ ret += "</ul>"
47
+ end
48
+ ret + "</li>"
49
+ end
50
+
51
+ def index_entries2(words, index, secondary)
52
+ ret = index_entries_head(words[secondary], index.dig(words[secondary], nil), index_entries_opt)
53
+ words3 = index[words[secondary]]&.keys&.reject { |k| k.nil?}&.each_with_object({}) { |w, v| v[w.downcase] = w }
54
+ unless words3.empty?
55
+ ret += "<ul>"
56
+ words3.keys.localize(@lang.to_sym).sort.to_a.each do |w|
57
+ ret += (index_entries_head(words3[w], index[words[secondary]][words3[w]], index_entries_opt) + "</li>")
58
+ end
59
+ ret += "</ul>"
60
+ end
61
+ ret + "</li>"
62
+ end
63
+
64
+ def index_entries_head(head, entries, opt)
65
+ ret = "<li>#{head}"
66
+ xref = entries&.dig(:xref)&.join(", ")
67
+ see_sort = entries&.dig(:see)&.each_with_object({}) { |w, v| v[sortable(w).downcase] = w }
68
+ see = see_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map { |k| see_sort[k] }&.join(", ")
69
+ also_sort = entries&.dig(:also)&.each_with_object({}) { |w, v| v[sortable(w).downcase] = w }
70
+ also = also_sort&.keys&.localize(@lang.to_sym)&.sort&.to_a&.map { |k| also_sort[k] }&.join(", ")
71
+ ret += "#{opt[:xref_lbl]} #{xref}" if xref
72
+ ret += "#{opt[:see_lbl]} #{see}" if see
73
+ ret += "#{opt[:also_lbl]} #{also}" if also
74
+ ret
75
+ end
76
+
77
+ def see_lbl
78
+ @lang == "en" ? @i18n.see : "<em>#{@i18n.see}</em>"
79
+ end
80
+
81
+ def also_lbl
82
+ @lang == "en" ? @i18n.see_also : "<em>#{@i18n.see_also}</em>"
83
+ end
84
+
85
+ def sort_indexterms(terms, see, also)
86
+ index = extract_indexterms(terms)
87
+ index = extract_indexsee(index, see, :see)
88
+ index = extract_indexsee(index, also, :also)
89
+ index.keys.sort.each_with_object({}) do |k, v|
90
+ v[sortable(k)[0].upcase.transliterate] ||= {}
91
+ v[sortable(k)[0].upcase.transliterate][k] = index[k]
92
+ end
93
+ end
94
+
95
+ def extract_indexsee(v, terms, label)
96
+ terms.each_with_object(v) do |t, v|
97
+ term = t&.at(ns("./primary"))&.children&.to_xml
98
+ term2 = t&.at(ns("./secondary"))&.children&.to_xml
99
+ term3 = t&.at(ns("./tertiary"))&.children&.to_xml
100
+ v[term] ||= {}
101
+ v[term][term2] ||= {}
102
+ v[term][term2][term3] ||= {}
103
+ v[term][term2][term3][label] ||= []
104
+ v[term][term2][term3][label] << t&.at(ns("./target"))&.children&.to_xml
105
+ t.remove
106
+ end
107
+ end
108
+
109
+ def xml_encode_attr(s)
110
+ HTMLEntities.new.encode(s, :basic, :hexadecimal).gsub(/\&#x([^;]+);/) { |x| "&#x#{$1.upcase};" }
111
+ end
112
+
113
+ # attributes are decoded into UTF-8, elements in extract_indexsee are still in entities
114
+ def extract_indexterms(terms)
115
+ terms.each_with_object({}) do |t, v|
116
+ term = t&.at(ns("./primary"))&.children&.to_xml
117
+ term2 = t&.at(ns("./secondary"))&.children&.to_xml
118
+ term3 = t&.at(ns("./tertiary"))&.children&.to_xml
119
+ index2bookmark(t)
120
+ v[term] ||= {}
121
+ v[term][term2] ||= {}
122
+ v[term][term2][term3] ||= {}
123
+ v[term][term2][term3][:xref] ||= []
124
+ to = t["to"] ? "to='#{t['to']}' " : ""
125
+ v[term][term2][term3][:xref] << "<xref target='#{t['id']}' #{to}pagenumber='true'/>"
126
+ end
127
+ end
128
+
129
+ def index2bookmark(t)
130
+ t.name = "bookmark"
131
+ t.children.each { |x| x.remove }
132
+ t["id"] = "_#{UUIDTools::UUID.random_create}"
133
+ end
134
+ end
135
+ end
136
+ end
@@ -7,17 +7,34 @@ module IsoDoc
7
7
  Metanorma::BIPM.configuration
8
8
  end
9
9
 
10
+ SI_ASPECT = %w(A_e_deltanu A_e cd_Kcd_h_deltanu cd_Kcd full K_k_deltanu
11
+ K_k kg_h_c_deltanu kg_h m_c_deltanu m_c mol_NA s_deltanu).freeze
12
+
13
+ def initialize(lang, script, labels)
14
+ super
15
+ here = File.join(File.dirname(__FILE__), "html", "si-aspect")
16
+ si_paths = []
17
+ SI_ASPECT.each do |s|
18
+ si_paths << File.expand_path(File.join(here, "#{s}.png"))
19
+ end
20
+ set(:si_aspect_index, SI_ASPECT)
21
+ set(:si_aspect_paths, si_paths)
22
+ end
23
+
24
+ TITLE = "//bibdata/title".freeze
25
+
10
26
  def title(isoxml, _out)
11
- lang1 = @lang == "fr" ? "fr" : "en"
12
- lang2 = @lang == "fr" ? "en" : "fr"
27
+ lang1, lang2 = @lang == "fr" ? %w(fr en) : %w(en fr)
13
28
  set(:doctitle, @c.encode(isoxml&.at(
14
- ns("//bibdata/title[@type='main'][@language='#{lang1}']"))&.text || ""))
29
+ ns("#{TITLE}[@type='main'][@language='#{lang1}']"))&.text || ""))
15
30
  set(:docsubtitle, @c.encode(isoxml&.at(
16
- ns("//bibdata/title[@type='main'][@language='#{lang2}']"))&.text || ""))
17
- set(:appendixtitle, @c.encode(isoxml&.at(
18
- ns("//bibdata/title[@type='appendix'][@language='#{lang1}']"))&.text || ""))
19
- set(:appendixsubtitle, @c.encode(isoxml&.at(
20
- ns("//bibdata/title[@type='appendix'][@language='#{lang2}']"))&.text || ""))
31
+ ns("#{TITLE}[@type='main'][@language='#{lang2}']"))&.text || ""))
32
+ %w(appendix part subtitle).each do |e|
33
+ set("#{e}title".to_sym, @c.encode(isoxml&.at(
34
+ ns("#{TITLE}[@type='#{e}'][@language='#{lang1}']"))&.text || ""))
35
+ set("#{e}subtitle".to_sym, @c.encode(isoxml&.at(
36
+ ns("#{TITLE}[@type='#{e}'][@language='#{lang2}']"))&.text || ""))
37
+ end
21
38
  end
22
39
 
23
40
  def status_print(status)
@@ -30,11 +47,18 @@ module IsoDoc
30
47
 
31
48
  def docid(isoxml, _out)
32
49
  super
33
- label1 = @lang == "fr" ? "Annexe" : "Appendix"
34
- label2 = @lang == "fr" ? "Appendix" : "Annexe"
50
+ label1, label2 = @lang == "fr" ? %w(Annexe Appendix) : %w(Appendix Annexe)
35
51
  dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/appendix"))
36
52
  dn and set(:appendixid, @i18n.l10n("#{label1} #{dn&.text}"))
37
53
  dn and set(:appendixid_alt, @i18n.l10n("#{label2} #{dn&.text}"))
54
+ label1, label2 = @lang == "fr" ? %w(Partie Part) : %w(Part Partie)
55
+ dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/part"))
56
+ dn and set(:partid, @i18n.l10n("#{label1} #{dn&.text}"))
57
+ dn and set(:partid_alt, @i18n.l10n("#{label2} #{dn&.text}"))
58
+ end
59
+
60
+ def extract_person_names_affiliations(authors)
61
+ extract_person_affiliations(authors)
38
62
  end
39
63
  end
40
64
  end
@@ -10,12 +10,23 @@ module IsoDoc
10
10
  super
11
11
  end
12
12
 
13
+ def configuration
14
+ Metanorma::BIPM.configuration
15
+ end
16
+
13
17
  def pdf_stylesheet(docxml)
14
- "bipm.brochure.xsl"
18
+ doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text
19
+ doctype = "brochure" unless %w(guide mise-en-pratique rapport).
20
+ include? doctype
21
+ "bipm.#{doctype}.xsl"
15
22
  end
16
23
 
17
24
  def pdf_options(docxml)
18
- if docxml.root.name == "metanorma-collection"
25
+ if docxml.root.name == "metanorma-collection" &&
26
+ docxml.at("//m:bipm-standard/m:bibdata/m:language[@current = 'true'][. = 'fr']",
27
+ "m" => configuration.document_namespace) &&
28
+ docxml.at("//m:bipm-standard/m:bibdata/m:language[@current = 'true'][. = 'en']",
29
+ "m" => configuration.document_namespace)
19
30
  "--split-by-language"
20
31
  else
21
32
  super
@@ -1,6 +1,7 @@
1
1
  require "isodoc"
2
2
  require "metanorma-generic"
3
3
  require_relative "init"
4
+ require_relative "index"
4
5
 
5
6
  module IsoDoc
6
7
  module BIPM
@@ -9,19 +10,114 @@ module IsoDoc
9
10
  return if labelled_ancestor(f)
10
11
  return if f["unnumbered"] && !f.at(ns("./name"))
11
12
  n = @xrefs.anchor(f['id'], :label, false)
12
- prefix_name(f, ".<tab/>", l10n("#{@i18n.table} #{n}"), "name")
13
+ prefix_name(f, ".<tab/>", l10n("#{@i18n.table.capitalize} #{n}"), "name")
13
14
  end
14
15
 
15
16
  def annex1(f)
16
- lbl = @xrefs.anchor(f['id'], :label)
17
- if t = f.at(ns("./title"))
18
- t.children = "<strong>#{t.children.to_xml}</strong>"
17
+ return if f["unnumbered"] == "true"
18
+ lbl = @xrefs.anchor(f['id'], :label)
19
+ if t = f.at(ns("./title"))
20
+ t.children = "<strong>#{t.children.to_xml}</strong>"
21
+ end
22
+ prefix_name(f, ".<tab/>", lbl, "title")
23
+ end
24
+
25
+ def clause1(f)
26
+ return if f["unnumbered"] == "true"
27
+ return if f.at(("./ancestor::*[@unnumbered = 'true']"))
28
+ super
29
+ end
30
+
31
+ def conversions(docxml)
32
+ super
33
+ doccontrol docxml
34
+ end
35
+
36
+ def doccontrol docxml
37
+ return unless docxml.at(ns("//bibdata/relation[@type = 'supersedes']"))
38
+ clause = <<~END
39
+ <doccontrol>
40
+ <title>Document Control</title>
41
+ <table unnumbered="true"><tbody>
42
+ <tr><td>Authors:</td><td/><td>#{list_authors(docxml)}</td></tr>
43
+ <tr>#{list_draft(docxml, 1)&.map { |x| "<td>#{x}</td>" }&.join }
44
+ <td>#{list_cochairs(docxml)}</td></tr>
45
+ <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join }
46
+ <td>#{list_chairs(docxml)}</td></tr>
47
+ #{list_drafts(docxml)}
48
+ </tbody></table></doccontrol>
49
+ END
50
+ docxml.root << clause
51
+ end
52
+
53
+ def list_drafts(xml)
54
+ ret = ""
55
+ i = 3
56
+ while a = list_draft(xml, i)
57
+ ret += "<tr>#{list_draft(xml, i).map { |x| "<td>#{x}</td>" }.join }"\
58
+ "<td/></tr>"
59
+ i += 1
60
+ end
61
+ ret
62
+ end
63
+
64
+ def list_draft(xml, i)
65
+ return unless d =
66
+ xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{i}]/bibitem"))
67
+ date = d&.at(ns("./date"))&.text
68
+ draft = d&.at(ns("./version/draft"))&.text and
69
+ draft = "Draft #{draft}"
70
+ edn = d&.at(ns("./edition"))&.text and
71
+ edn = "Edition #{edn}"
72
+ [date, [draft, edn].join(" ")]
73
+ end
74
+
75
+ def list_authors(xml)
76
+ ret = list_people(
77
+ xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person")
78
+ @i18n.multiple_and(ret, @i18n.get["and"])
79
+ end
80
+
81
+ COCHAIR = "xmlns:role[contains(text(),'co-chair')]".freeze
82
+ CHAIR = "[xmlns:role[contains(text(),'chair')]"\
83
+ "[not(contains(text(),'co-chair'))]]".freeze
84
+
85
+ def list_cochairs(xml)
86
+ ret = list_people(xml, "//bibdata/contributor[#{COCHAIR}]/person")
87
+ role = xml&.at(ns("//bibdata/contributor[#{COCHAIR}]/role"))&.text
88
+ label = ret.size > 1 && role ? "#{role}s" : role
89
+ "#{label}: #{@i18n.multiple_and(ret, @i18n.get["and"])}"
90
+ end
91
+
92
+ def list_chairs(xml)
93
+ ret = list_people(xml, "//bibdata/contributor#{CHAIR}/person")
94
+ role = xml&.at(ns("//bibdata/contributor#{CHAIR}/role"))&.text
95
+ label = ret.size > 1 && role ? "#{role}s" : role
96
+ "#{label}: #{@i18n.multiple_and(ret, @i18n.get["and"])}"
97
+ end
98
+
99
+ def list_people(xml, xpath)
100
+ ret = []
101
+ xml.xpath(ns(xpath)).each do |p|
102
+ name = p&.at(ns("./name/completename"))&.text
103
+ aff = p&.at(ns("./affiliation/organization/abbreviation"))&.text ||
104
+ p&.at(ns("./affiliation/organization/name"))&.text
105
+ c = name || ""
106
+ aff and c += " (#{aff})"
107
+ ret << c
108
+ end
109
+ ret
110
+ end
111
+
112
+ def twitter_cldr_localiser_symbols
113
+ { group: "&#x202F;", fraction_group: "&#x202F;", fraction_group_digits: 3 }
114
+ end
115
+
116
+ def mathml1(f, locale)
117
+ localize_maths(f, locale)
19
118
  end
20
- prefix_name(f, ".<tab/>", lbl, "title")
21
- end
22
119
 
23
120
  include Init
24
121
  end
25
122
  end
26
123
  end
27
-
@@ -1,15 +1,150 @@
1
1
  module IsoDoc
2
2
  module BIPM
3
3
  class Xref < IsoDoc::Xref
4
+ def initialize(lang, script, klass, i18n, options = {})
5
+ super
6
+ end
7
+
8
+ def clause_names(docxml, sect_num)
9
+ sect_num = 0
10
+ docxml.xpath(ns("//sections/clause[not(@unnumbered = 'true')] | "\
11
+ "//sections/terms[not(@unnumbered = 'true')] | "\
12
+ "//sections/definitions[not(@unnumbered = 'true')]")).
13
+ each_with_index do |c, i|
14
+ section_names(c, (i + sect_num), 1)
15
+ end
16
+ docxml.xpath(ns("//sections/clause[@unnumbered = 'true'] | "\
17
+ "//sections/terms[@unnumbered = 'true'] | "\
18
+ "//sections/definitions[@unnumbered = 'true']")).
19
+ each do |c|
20
+ unnumbered_section_names(c, 1)
21
+ end
22
+ end
23
+
24
+ NUMBERED_SUBCLAUSES = "./clause[not(@unnumbered = 'true')] | "\
25
+ "./references[not(@unnumbered = 'true')] | "\
26
+ "./term[not(@unnumbered = 'true')] | "\
27
+ "./terms[not(@unnumbered = 'true')] | "\
28
+ "./definitions[not(@unnumbered = 'true')]".freeze
29
+
30
+ UNNUMBERED_SUBCLAUSES = "./clause[@unnumbered = 'true'] | "\
31
+ "./references[@unnumbered = 'true'] | "\
32
+ "./term[@unnumbered = 'true'] | "\
33
+ "./terms[@unnumbered = 'true'] | "\
34
+ "./definitions[@unnumbered = 'true']".freeze
35
+
36
+ def section_names(clause, num, lvl)
37
+ return num if clause.nil?
38
+ num = num + 1
39
+ @anchors[clause["id"]] =
40
+ { label: num.to_s, xref: l10n("#{@labels["clause"]} #{num}"),
41
+ level: lvl, type: "clause" }
42
+ clause.xpath(ns(NUMBERED_SUBCLAUSES)).each_with_index do |c, i|
43
+ section_names1(c, "#{num}.#{i + 1}", lvl + 1)
44
+ end
45
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each_with_index do |c, i|
46
+ unnumbered_section_names1(c, lvl + 1)
47
+ end
48
+ num
49
+ end
50
+
51
+ def unnumbered_section_names(clause, lvl)
52
+ return if clause.nil?
53
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
54
+ @anchors[clause["id"]] =
55
+ { label: lbl, xref: l10n(%{"#{lbl}"}), level: lvl, type: "clause" }
56
+ clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i|
57
+ unnumbered_section_names1(c, lvl + 1)
58
+ end
59
+ end
60
+
61
+ def section_names1(clause, num, level)
62
+ @anchors[clause["id"]] =
63
+ { label: num, level: level, xref: l10n("#{@labels["subclause"]} #{num}"),
64
+ type: "clause" }
65
+ clause.xpath(ns(NUMBERED_SUBCLAUSES)).each_with_index do |c, i|
66
+ section_names1(c, "#{num}.#{i + 1}", level + 1)
67
+ end
68
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each_with_index do |c, i|
69
+ unnumbered_section_names1(c, lvl + 1)
70
+ end
71
+ end
72
+
73
+ def unnumbered_section_names1(clause, level)
74
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
75
+ @anchors[clause["id"]] =
76
+ { label: lbl, xref: l10n(%{"#{lbl}"}), level: level, type: "clause" }
77
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
78
+ unnumbered_section_names1(c, level + 1)
79
+ end
80
+ end
81
+
4
82
  def back_anchor_names(docxml)
5
83
  super
6
- docxml.xpath(ns("//annex")).each_with_index do |c, i|
7
- annex_names(c, (i+1).to_s)
84
+ @annexlbl = docxml.at(ns("//bibdata/ext/structuredidentifier/appendix")) ?
85
+ @labels["appendix"] : @labels["annex"]
86
+ docxml.xpath(ns("//annex[not(@unnumbered = 'true')]")).
87
+ each_with_index { |c, i| annex_names(c, (i+1).to_s) }
88
+ docxml.xpath(ns("//annex[@unnumbered = 'true']")).
89
+ each { |c| unnumbered_annex_names(c) }
90
+ end
91
+
92
+ def annex_names(clause, num)
93
+ @anchors[clause["id"]] =
94
+ { label: annex_name_lbl(clause, num), type: "clause", value: num.to_s,
95
+ xref: l10n("#{@annexlbl} #{num}"), level: 1 }
96
+ if a = single_annex_special_section(clause)
97
+ annex_names1(a, "#{num}", 1)
98
+ else
99
+ clause.xpath(ns(NUMBERED_SUBCLAUSES)).each_with_index do |c, i|
100
+ annex_names1(c, "#{num}.#{i + 1}", 2)
101
+ end
102
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
103
+ unnumbered_annex_names1(c, 2)
104
+ end
105
+ end
106
+ hierarchical_asset_names(clause, num)
107
+ end
108
+
109
+ def unnumbered_annex_names(clause)
110
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
111
+ @anchors[clause["id"]] =
112
+ { label: lbl, type: "clause", value: "",
113
+ xref: l10n(%{"#{lbl}"}), level: 1 }
114
+ if a = single_annex_special_section(clause)
115
+ annex_names1(a, "#{num}", 1)
116
+ else
117
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
118
+ unnumbered_annex_names1(c, 2)
119
+ end
120
+ end
121
+ hierarchical_asset_names(clause, lbl)
122
+ end
123
+
124
+ def annex_names1(clause, num, level)
125
+ @anchors[clause["id"]] =
126
+ { label: num, xref: l10n("#{@annexlbl} #{num}"),
127
+ level: level, type: "clause" }
128
+ clause.xpath(ns(NUMBERED_SUBCLAUSES)).each_with_index do |c, i|
129
+ annex_names1(c, "#{num}.#{i + 1}", level + 1)
130
+ end
131
+ clause.xpath(ns(UNNUMBERED_SUBCLAUSES)).each do |c|
132
+ unnumbered_annex_names1(c, level + 1)
133
+ end
134
+ end
135
+
136
+ def unnumbered_annex_names1(clause, level)
137
+ lbl = clause&.at(ns("./title"))&.text || "[#{clause["id"]}]"
138
+ @anchors[clause["id"]] =
139
+ { label: lbl, xref: l10n(%{"#{lbl}"}),
140
+ level: level, type: "clause" }
141
+ clause.xpath(ns(SUBCLAUSES)).each do |c|
142
+ unnumbered_annex_names1(c, level + 1)
8
143
  end
9
144
  end
10
145
 
11
146
  def annex_name_lbl(clause, num)
12
- l10n("<strong>#{@labels["annex"]} #{num}</strong>")
147
+ l10n("<strong>#{@annexlbl} #{num}</strong>")
13
148
  end
14
149
  end
15
150
  end