metanorma-bipm 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,10 @@
1
1
  annex: Appendix
2
2
  appendix: Annex
3
3
  see: see
4
+ see_also: see also
4
5
  clause: Chapter
5
6
  subclause: Section
6
7
  formula: Equation
7
8
  inequality: Inequality
8
9
  bibliography: References
10
+ index: Index
@@ -1,6 +1,7 @@
1
1
  annex: Annexe
2
2
  appendix: Appendice
3
3
  see: voir
4
+ see_also: voir aussi
4
5
  clause: chapître
5
6
  subclause: section
6
7
  formula: équation
@@ -15,6 +16,7 @@ requirement: exigence
15
16
  recommendation: recommandation
16
17
  permission: autorisation
17
18
  example_xref: exemple
19
+ index: Index
18
20
  doctype_dict:
19
21
  brochure: brochure
20
22
  mise-en-pratique: mise-en-pratique
@@ -28,7 +30,7 @@ doctype_dict:
28
30
  cipm-mra: cipm-mra
29
31
  resolution: résolution
30
32
  stage_dict:
31
- draft-proposal: projet-de-proposition
32
- draft-development: projet-de-développement
33
- in-force: en-vigeur
34
- 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
@@ -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
@@ -113,7 +114,7 @@ module IsoDoc
113
114
  end
114
115
 
115
116
  def mathml1(f, locale)
116
- localize_maths(f, locale)
117
+ localize_maths(f, locale)
117
118
  end
118
119
 
119
120
  include Init
@@ -14,6 +14,17 @@ module Metanorma
14
14
  ).tap { |hs| hs.delete(:doc) }
15
15
  end
16
16
 
17
+ def fonts_manifest
18
+ {
19
+ "Arial" => nil,
20
+ "Times New Roman" => nil,
21
+ "Work Sans" => nil,
22
+ "STIX Two Math" => nil,
23
+ "Source Han Sans" => nil,
24
+ "TeX Gyre Chorus" => nil,
25
+ }
26
+ end
27
+
17
28
  def version
18
29
  "Metanorma::BIPM #{Metanorma::BIPM::VERSION}"
19
30
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module BIPM
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
28
28
 
29
- spec.add_dependency "metanorma-generic", "~> 1.8.0"
29
+ spec.add_dependency "metanorma-generic", "~> 1.8.1"
30
30
 
31
31
  spec.add_development_dependency "byebug", "~> 9.1"
32
32
  spec.add_development_dependency "sassc", "2.4.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-bipm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-generic
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
19
+ version: 1.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.0
26
+ version: 1.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -221,6 +221,7 @@ files:
221
221
  - lib/isodoc/bipm/i18n-en.yaml
222
222
  - lib/isodoc/bipm/i18n-fr.yaml
223
223
  - lib/isodoc/bipm/i18n.rb
224
+ - lib/isodoc/bipm/index.rb
224
225
  - lib/isodoc/bipm/init.rb
225
226
  - lib/isodoc/bipm/metadata.rb
226
227
  - lib/isodoc/bipm/pdf_convert.rb
@@ -228,7 +229,6 @@ files:
228
229
  - lib/isodoc/bipm/xref.rb
229
230
  - lib/metanorma-bipm.rb
230
231
  - lib/metanorma/bipm.rb
231
- - lib/metanorma/bipm/fonts_manifest.yaml
232
232
  - lib/metanorma/bipm/processor.rb
233
233
  - lib/metanorma/bipm/version.rb
234
234
  - metanorma-bipm.gemspec
@@ -1,7 +0,0 @@
1
- ---
2
- Times New Roman:
3
- STIX Two Math:
4
- Courier New:
5
- Arial:
6
- Work Sans:
7
- Source Han Sans: