metanorma-bipm 1.1.1 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,29 +25,46 @@ module IsoDoc
25
25
  end
26
26
  end
27
27
 
28
- def table1(f)
29
- return if labelled_ancestor(f)
30
- return if f["unnumbered"]
28
+ def table1(elem)
29
+ return if labelled_ancestor(elem)
30
+ return if elem["unnumbered"]
31
31
 
32
- n = @xrefs.anchor(f["id"], :label, false)
33
- prefix_name(f, ".<tab/>", l10n("#{@i18n.table.capitalize} #{n}"), "name")
32
+ n = @xrefs.anchor(elem["id"], :label, false)
33
+ prefix_name(elem, ".<tab/>",
34
+ l10n("#{@i18n.table.capitalize} #{n}"), "name")
34
35
  end
35
36
 
36
- def annex1(f)
37
+ def figure1(elem)
38
+ if @jcgm
39
+ @iso.xrefs = @xrefs
40
+ @iso.figure1(elem)
41
+ else super
42
+ end
43
+ end
44
+
45
+ def annex1(elem)
37
46
  return super if @jcgm
38
- return if f["unnumbered"] == "true"
47
+ return if elem["unnumbered"] == "true"
39
48
 
40
- lbl = @xrefs.anchor(f["id"], :label)
41
- if t = f.at(ns("./title"))
49
+ lbl = @xrefs.anchor(elem["id"], :label)
50
+ if t = elem.at(ns("./title"))
42
51
  t.children = "<strong>#{t.children.to_xml}</strong>"
43
52
  end
44
- prefix_name(f, ".<tab/>", lbl, "title")
53
+ prefix_name(elem, ".<tab/>", lbl, "title")
45
54
  end
46
55
 
47
- def clause1(f)
48
- return if f["unnumbered"] == "true"
49
- return if f.at(("./ancestor::*[@unnumbered = 'true']"))
56
+ def clause(docxml)
57
+ super
58
+ if @jcgm
59
+ docxml.xpath(ns("//preface/introduction[clause]")).each do |f|
60
+ clause1(f)
61
+ end
62
+ end
63
+ end
50
64
 
65
+ def clause1(elem)
66
+ return if elem["unnumbered"] == "true"
67
+ return if elem.at(("./ancestor::*[@unnumbered = 'true']"))
51
68
  super
52
69
  end
53
70
 
@@ -56,31 +73,32 @@ module IsoDoc
56
73
  doccontrol docxml
57
74
  end
58
75
 
59
- def doccontrol(docxml)
60
- return unless docxml.at(ns("//bibdata/relation[@type = 'supersedes']"))
76
+ def doccontrol(doc)
77
+ return unless doc.at(ns("//bibdata/relation[@type = 'supersedes']"))
61
78
 
62
- clause = <<~END
79
+ clause = <<~DOCCONTROL
63
80
  <doccontrol>
64
81
  <title>Document Control</title>
65
82
  <table unnumbered="true"><tbody>
66
- <tr><th>Authors:</th><td/><td>#{list_authors(docxml)}</td></tr>
67
- #{doccontrol_row1(docxml)} #{doccontrol_row2(docxml)} #{list_drafts(docxml)}
83
+ <tr><th>Authors:</th><td/><td>#{list_authors(doc)}</td></tr>
84
+ #{doccontrol_row1(doc)} #{doccontrol_row2(doc)} #{list_drafts(doc)}
68
85
  </tbody></table></doccontrol>
69
- END
70
- docxml.root << clause
86
+ DOCCONTROL
87
+ doc.root << clause
71
88
  end
72
89
 
73
- def doccontrol_row1(docxml)
74
- return "" if list_draft(docxml, 1) == ["", ""] && list_cochairs(docxml).empty?
90
+ def doccontrol_row1(doc)
91
+ return "" if list_draft(doc, 1) == ["", ""] && list_cochairs(doc).empty?
75
92
 
76
93
  <<~ROW
77
- <tr>#{list_draft(docxml, 1)&.map { |x| "<td>#{x}</td>" }&.join}
78
- <td>#{list_cochairs(docxml)}</td></tr>
94
+ <tr>#{list_draft(doc, 1)&.map { |x| "<td>#{x}</td>" }&.join}
95
+ <td>#{list_cochairs(doc)}</td></tr>
79
96
  ROW
80
97
  end
81
98
 
82
99
  def doccontrol_row2(docxml)
83
- return "" if list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty?
100
+ list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty? and
101
+ return ""
84
102
 
85
103
  <<~ROW
86
104
  <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join}
@@ -99,15 +117,13 @@ module IsoDoc
99
117
  ret
100
118
  end
101
119
 
102
- def list_draft(xml, i)
103
- return ["", ""] unless d =
104
- xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{i}]/bibitem"))
120
+ def list_draft(xml, idx)
121
+ d = xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{idx}]"\
122
+ "/bibitem")) or return ["", ""]
105
123
 
106
124
  date = d&.at(ns("./date"))&.text
107
- draft = d&.at(ns("./version/draft"))&.text and
108
- draft = "Draft #{draft}"
109
- edn = d&.at(ns("./edition"))&.text and
110
- edn = "Version #{edn}"
125
+ draft = d&.at(ns("./version/draft"))&.text and draft = "Draft #{draft}"
126
+ edn = d&.at(ns("./edition"))&.text and edn = "Version #{edn}"
111
127
  [[draft, edn].join(" "), date]
112
128
  end
113
129
 
@@ -156,8 +172,8 @@ module IsoDoc
156
172
  fraction_group_digits: 3 }
157
173
  end
158
174
 
159
- def mathml1(f, locale)
160
- localize_maths(f, locale)
175
+ def mathml1(elem, locale)
176
+ localize_maths(elem, locale)
161
177
  end
162
178
 
163
179
  def bibdata_i18n(bibdata)
@@ -175,6 +191,49 @@ module IsoDoc
175
191
  pubdate.next.children = meta.monthyr(pubdate.text)
176
192
  end
177
193
 
194
+ def eref(docxml)
195
+ super
196
+ jcgm_eref(docxml, "//eref")
197
+ end
198
+
199
+ def origin(docxml)
200
+ super
201
+ jcgm_eref(docxml, "//origin[not(termref)]")
202
+ end
203
+
204
+ def quotesource(docxml)
205
+ super
206
+ jcgm_eref(docxml, "//quote/source")
207
+ end
208
+
209
+ def jcgm_eref(docxml, xpath)
210
+ return unless @jcgm
211
+
212
+ docxml.xpath(ns(xpath)).each do |x|
213
+ extract_brackets(x)
214
+ end
215
+ # merge adjacent text nodes
216
+ docxml.root.replace(Nokogiri::XML(docxml.root.to_xml).root)
217
+ docxml.xpath(ns(xpath)).each do |x| # rubocop: disable Style/CombinableLoops
218
+ if x&.next&.text? && /^\],\s+\[$/.match?(x&.next&.text) &&
219
+ %w(eref origin source).include?(x&.next&.next&.name)
220
+ x.next.replace(", ")
221
+ end
222
+ end
223
+ end
224
+
225
+ def extract_brackets(node)
226
+ start = node.at("./text()[1]")
227
+ finish = node.at("./text()[last()]")
228
+ if /^\[/.match?(start.text) && /\]$/.match?(finish.text)
229
+ start.replace(start.text[1..-1])
230
+ node.previous = "["
231
+ finish = node.at("./text()[last()]")
232
+ finish.replace(finish.text[0..-2])
233
+ node.next = "]"
234
+ end
235
+ end
236
+
178
237
  include Init
179
238
  end
180
239
  end
@@ -5,6 +5,7 @@ module IsoDoc
5
5
 
6
6
  class Xref < IsoDoc::Xref
7
7
  def initialize(lang, script, klass, i18n, options = {})
8
+ @iso = IsoDoc::Iso::Xref.new(lang, script, klass, i18n, options)
8
9
  super
9
10
  end
10
11
 
@@ -12,10 +13,10 @@ module IsoDoc
12
13
  @jcgm = docxml&.at(ns("//bibdata/ext/editorialgroup/committee/"\
13
14
  "@acronym"))&.value == "JCGM"
14
15
  @annexlbl =
15
- if docxml.at(ns("//bibdata/ext/structuredidentifier/appendix"))
16
+ if @jcgm then @labels["iso_annex"]
17
+ elsif docxml.at(ns("//bibdata/ext/structuredidentifier/appendix"))
16
18
  @labels["appendix"]
17
- else
18
- @labels["annex"]
19
+ else @labels["annex"]
19
20
  end
20
21
  super
21
22
  end
@@ -28,9 +29,8 @@ module IsoDoc
28
29
 
29
30
  def reference_names(ref)
30
31
  super
31
- if @jcgm
32
+ @jcgm and
32
33
  @anchors[ref["id"]][:xref] = wrap_brackets(@anchors[ref["id"]][:xref])
33
- end
34
34
  end
35
35
 
36
36
  def clause_names(docxml, sect_num)
@@ -109,8 +109,7 @@ module IsoDoc
109
109
  def section_name1_anchors(clause, num, level)
110
110
  lbl = @jcgm ? "" : "#{@labels['subclause']} "
111
111
  @anchors[clause["id"]] =
112
- { label: num, level: level,
113
- xref: l10n("#{lbl}#{num}"),
112
+ { label: num, level: level, xref: l10n("#{lbl}#{num}"),
114
113
  type: "clause" }
115
114
  end
116
115
 
@@ -226,6 +225,30 @@ module IsoDoc
226
225
  )
227
226
  end
228
227
  end
228
+
229
+ def initial_anchor_names(doc)
230
+ super
231
+ if @jcgm
232
+ @iso.introduction_names(doc.at(ns("//introduction")))
233
+ @anchors.merge!(@iso.get)
234
+ end
235
+ end
236
+
237
+ def sequential_figure_names(clause)
238
+ if @jcgm
239
+ @iso.sequential_figure_names(clause)
240
+ @anchors.merge!(@iso.get)
241
+ else super
242
+ end
243
+ end
244
+
245
+ def hierarchical_figure_names(clause, num)
246
+ if @jcgm
247
+ @iso.hierarchical_figure_names(clause, num)
248
+ @anchors.merge!(@iso.get)
249
+ else super
250
+ end
251
+ end
229
252
  end
230
253
  end
231
254
  end
@@ -1,9 +1,9 @@
1
- require 'metanorma'
2
- require 'metanorma/bipm'
1
+ require "metanorma"
2
+ require "metanorma/bipm"
3
3
  require "isodoc/bipm"
4
4
 
5
- require 'asciidoctor' unless defined? Asciidoctor::Converter
6
- require 'asciidoctor/bipm'
5
+ require "asciidoctor" unless defined? Asciidoctor::Converter
6
+ require "asciidoctor/bipm"
7
7
 
8
8
  if defined? Metanorma
9
9
  require_relative "metanorma/bipm"
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module BIPM
3
- VERSION = "1.1.1".freeze
3
+ VERSION = "1.1.5".freeze
4
4
  end
5
5
  end
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.bindir = "exe"
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
27
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
28
28
 
29
- spec.add_dependency "metanorma-generic", "~> 1.10.0"
29
+ spec.add_dependency "metanorma-generic", "~> 1.10.2"
30
30
  spec.add_dependency "metanorma-iso", "~> 1.8.0"
31
31
 
32
32
  spec.add_development_dependency "byebug", "~> 9.1"
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.1.1
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2021-07-19 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.10.0
19
+ version: 1.10.2
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.10.0
26
+ version: 1.10.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: metanorma-iso
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +190,7 @@ extra_rdoc_files: []
190
190
  files:
191
191
  - ".github/workflows/rake.yml"
192
192
  - ".gitignore"
193
+ - ".hound.yml"
193
194
  - ".rubocop.yml"
194
195
  - CODE_OF_CONDUCT.md
195
196
  - Gemfile
@@ -263,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
264
  requirements:
264
265
  - - ">="
265
266
  - !ruby/object:Gem::Version
266
- version: 2.4.0
267
+ version: 2.5.0
267
268
  required_rubygems_version: !ruby/object:Gem::Requirement
268
269
  requirements:
269
270
  - - ">="