metanorma-iso 1.9.1 → 1.9.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require "isodoc"
2
2
 
3
3
  module IsoDoc
4
4
  module Iso
5
- class Metadata < IsoDoc::Metadata
5
+ class Metadata < IsoDoc::Metadata
6
6
  def initialize(lang, script, i18n)
7
7
  super
8
8
  set(:tc, "XXXX")
@@ -14,17 +14,17 @@ module IsoDoc
14
14
  set(:obsoletes_part, nil)
15
15
  end
16
16
 
17
- def status_abbrev(stage, substage, iter, draft, doctype)
17
+ def status_abbrev(stage, _substage, iter, draft, doctype)
18
18
  return "" unless stage
19
19
 
20
20
  if %w(technical-report technical-specification).include?(doctype)
21
21
  stage = "DTS" if stage == "DIS"
22
22
  stage = "FDTS" if stage == "FDIS"
23
23
  end
24
- if %w(PWI NWIP WD CD).include?(stage)
25
- stage += iter if iter
24
+ if %w(PWI NWIP WD CD).include?(stage) && iter
25
+ stage += iter
26
26
  end
27
- stage = "Pre" + stage if draft =~ /^0\./
27
+ stage = "Pre#{stage}" if /^0\./.match?(draft)
28
28
  stage
29
29
  end
30
30
 
@@ -48,14 +48,14 @@ module IsoDoc
48
48
  end
49
49
 
50
50
  def unpublished(status)
51
- status.to_i > 0 && status.to_i < 60
51
+ status.to_i.positive? && status.to_i < 60
52
52
  end
53
53
 
54
54
  def docid(isoxml, _out)
55
55
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'ISO']"))
56
56
  set(:docnumber, dn&.text)
57
57
  tcdn = isoxml.xpath(ns("//bibdata/docidentifier[@type = 'iso-tc']"))
58
- set(:tc_docnumber, tcdn.map { |n| n.text })
58
+ set(:tc_docnumber, tcdn.map(&:text))
59
59
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'iso-with-lang']"))
60
60
  set(:docnumber_lang, dn&.text)
61
61
  dn = isoxml.at(ns("//bibdata/docidentifier[@type = 'iso-reference']"))
@@ -87,6 +87,7 @@ module IsoDoc
87
87
 
88
88
  def part_title(part, partnum, subpartnum, lang)
89
89
  return "" unless part
90
+
90
91
  suffix = @c.encode(part.text, :hexadecimal)
91
92
  partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
92
93
  suffix = "#{part_label(lang)}&nbsp;#{partnum}: " + suffix if partnum
@@ -125,10 +126,14 @@ module IsoDoc
125
126
  end
126
127
 
127
128
  def title_parts(isoxml, lang)
128
- [isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='#{lang}']")),
129
- isoxml.at(ns("//bibdata//title[@type='title-main' and @language='#{lang}']")),
130
- isoxml.at(ns("//bibdata//title[@type='title-part' and @language='#{lang}']")),
131
- isoxml.at(ns("//bibdata//title[@type='title-amd' and @language='#{lang}']"))]
129
+ [isoxml.at(ns("//bibdata//title[@type='title-intro' and "\
130
+ "@language='#{lang}']")),
131
+ isoxml.at(ns("//bibdata//title[@type='title-main' and "\
132
+ "@language='#{lang}']")),
133
+ isoxml.at(ns("//bibdata//title[@type='title-part' and "\
134
+ "@language='#{lang}']")),
135
+ isoxml.at(ns("//bibdata//title[@type='title-amd' and "\
136
+ "@language='#{lang}']"))]
132
137
  end
133
138
 
134
139
  def title(isoxml, _out)
@@ -139,7 +144,10 @@ module IsoDoc
139
144
  set(:doctitlemain, @c.encode(main ? main.text : "", :hexadecimal))
140
145
  main = compose_title(main, intro, part, partnumber, subpartnumber, lang)
141
146
  set(:doctitle, main)
142
- set(:doctitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
147
+ if intro
148
+ set(:doctitleintro,
149
+ @c.encode(intro ? intro.text : "", :hexadecimal))
150
+ end
143
151
  set(:doctitlepartlabel, part_prefix(partnumber, subpartnumber, lang))
144
152
  set(:doctitlepart, @c.encode(part.text, :hexadecimal)) if part
145
153
  set(:doctitleamdlabel, amd_prefix(amdnumber, lang)) if amdnumber
@@ -155,7 +163,10 @@ module IsoDoc
155
163
  set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
156
164
  main = compose_title(main, intro, part, partnumber, subpartnumber, lang)
157
165
  set(:docsubtitle, main)
158
- set(:docsubtitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
166
+ if intro
167
+ set(:docsubtitleintro,
168
+ @c.encode(intro ? intro.text : "", :hexadecimal))
169
+ end
159
170
  set(:docsubtitlepartlabel, part_prefix(partnumber, subpartnumber, lang))
160
171
  set(:docsubtitlepart, @c.encode(part.text, :hexadecimal)) if part
161
172
  set(:docsubtitleamdlabel, amd_prefix(amdnumber, lang)) if amdnumber
@@ -173,8 +184,8 @@ module IsoDoc
173
184
 
174
185
  def tc(xml)
175
186
  tc_num = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@number"))
176
- tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@type"))&.
177
- text || "TC"
187
+ tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@type"))
188
+ &.text || "TC"
178
189
  if tc_num
179
190
  tcid = "#{tc_type} #{tc_num.text}"
180
191
  set(:tc, tcid)
@@ -212,7 +223,8 @@ module IsoDoc
212
223
  ics = []
213
224
  isoxml.xpath(ns("//bibdata/ext/ics/code")).each { |i| ics << i.text }
214
225
  set(:ics, ics.empty? ? nil : ics.join(", "))
215
- a = isoxml.at(ns("//bibdata/ext/horizontal")) and set(:horizontal, a.text)
226
+ a = isoxml.at(ns("//bibdata/ext/horizontal")) and set(:horizontal,
227
+ a.text)
216
228
  end
217
229
  end
218
230
  end
@@ -45,13 +45,15 @@ module IsoDoc
45
45
  prefix_name(node, "&nbsp;&mdash; ", lbl, "name")
46
46
  end
47
47
 
48
+ def eref_delim(delim, type)
49
+ if delim == ";" then ";"
50
+ else type == "list" ? "" : delim
51
+ end
52
+ end
53
+
48
54
  def eref_localities1_zh(target, type, from, upto, node, delim)
49
55
  subsection = from&.text&.match(/\./)
50
- ret = if delim == ";"
51
- ";"
52
- else
53
- type == "list" ? "" : delim
54
- end
56
+ ret = eref_delim(delim, type)
55
57
  ret += " 第#{from.text}" if from
56
58
  ret += "&ndash;#{upto.text}" if upto
57
59
  loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize)
@@ -68,11 +70,9 @@ module IsoDoc
68
70
  subsection = from&.text&.match(/\./)
69
71
  type = type.downcase
70
72
  lang == "zh" and
71
- return l10n(eref_localities1_zh(target, type, from, upto, node, delim))
72
- ret = if delim == ";" then ";"
73
- else
74
- type == "list" ? "" : delim
75
- end
73
+ return l10n(eref_localities1_zh(target, type, from, upto, node,
74
+ delim))
75
+ ret = eref_delim(delim, type)
76
76
  ret += eref_locality_populate(type, node) unless subsection &&
77
77
  type == "clause" || type == "list" ||
78
78
  target.match(/^IEV$|^IEC 60050-/)
@@ -113,31 +113,39 @@ module IsoDoc
113
113
  end
114
114
 
115
115
  def concept(docxml)
116
- docxml.xpath(ns("//terms//concept")).each_with_object({}) do |f, m|
116
+ docxml.xpath(ns("//term//concept")).each_with_object({}) do |f, m|
117
117
  concept_term(f, m)
118
118
  end
119
119
  docxml.xpath(ns("//concept")).each do |node|
120
- concept_render(node, node["ital"] || "false", node["ref"] || "false")
120
+ concept_render(node, ital: node["ital"] || "false",
121
+ ref: node["ref"] || "false",
122
+ linkref: node["linkref"] || "true",
123
+ linkmention: node["linkmention"] || "false")
121
124
  end
122
125
  end
123
126
 
124
127
  def concept_term(node, seen)
125
128
  term = node&.at(ns("./refterm"))&.to_xml
126
129
  if term && seen[term]
127
- concept_render(node, node["ital"] || "false", node["ref"] || "false")
128
- else concept_render(node, node["ital"] || "true", node["ref"] || "true")
130
+ concept_render(node, ital: node["ital"] || "false",
131
+ ref: node["ref"] || "false",
132
+ linkref: node["linkref"] || "true",
133
+ linkmention: node["linkmention"] || "false")
134
+ else concept_render(node, ital: node["ital"] || "true",
135
+ ref: node["ref"] || "true",
136
+ linkref: node["linkref"] || "true",
137
+ linkmention: node["linkmention"] || "false")
129
138
  end
130
139
  seen[term] = true if term
131
140
  seen
132
141
  end
133
142
 
134
- def concept1_ref(node, ref)
135
- if r = node.at(ns("./xref | ./eref | ./termref"))
136
- return r.remove if ref == "false"
137
-
138
- r.name == "termref" and
139
- r.replace(@i18n.term_defined_in.sub(/%/, r.to_xml)) or
140
- r.replace("(#{r.to_xml})")
143
+ def concept1_ref_content(ref)
144
+ if ref.name == "termref"
145
+ ref.replace(@i18n.term_defined_in.sub(/%/,
146
+ ref.to_xml))
147
+ else
148
+ ref.replace("(#{ref.to_xml})")
141
149
  end
142
150
  end
143
151
 
@@ -160,7 +168,7 @@ module IsoDoc
160
168
  # i = display_order_at(docxml, "//sections/definitions", i)
161
169
  # i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
162
170
  i = display_order_xpath(docxml, "//sections/clause[not(@type = 'scope')] | "\
163
- "//sections/terms | //sections/definitions", i)
171
+ "//sections/terms | //sections/definitions", i)
164
172
  i = display_order_xpath(docxml, "//annex", i)
165
173
  i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
166
174
  display_order_xpath(docxml, "//indexsect", i)
@@ -31,7 +31,7 @@ module Metanorma
31
31
  "Cambria Math" => nil,
32
32
  "Times New Roman" => nil,
33
33
  "Source Han Sans" => nil,
34
- "Courier" => nil,
34
+ "Source Han Sans Normal" => nil,
35
35
  "Courier New" => nil,
36
36
  }
37
37
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "1.9.1".freeze
3
+ VERSION = "1.9.5".freeze
4
4
  end
5
5
  end
@@ -5,60 +5,6 @@ RSpec.describe Asciidoctor::ISO do
5
5
  expect(Metanorma::ISO::VERSION).not_to be nil
6
6
  end
7
7
 
8
- it "processes a blank document" do
9
- input = <<~INPUT
10
- #{ASCIIDOC_BLANK_HDR}
11
- INPUT
12
- output = <<~OUTPUT
13
- #{BLANK_HDR}
14
- <sections/>
15
- </iso-standard>
16
- OUTPUT
17
- expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
18
- .to be_equivalent_to xmlpp(output)
19
- end
20
-
21
- it "converts a blank document" do
22
- input = <<~INPUT
23
- = Document title
24
- Author
25
- :docfile: test.adoc
26
- :novalid:
27
- :no-isobib:
28
- INPUT
29
- output = <<~OUTPUT
30
- #{BLANK_HDR}
31
- <sections/>
32
- </iso-standard>
33
- OUTPUT
34
- expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
35
- .to be_equivalent_to xmlpp(output)
36
- expect(File.exist?("test_alt.html")).to be true
37
- expect(File.exist?("test.html")).to be true
38
- expect(File.exist?("test.doc")).to be true
39
- expect(File.exist?("test.pdf")).to be true
40
- expect(File.exist?("htmlstyle.css")).to be false
41
- end
42
-
43
- it "converts a blank document in French" do
44
- input = <<~INPUT
45
- = Document title
46
- Author
47
- :docfile: test.adoc
48
- :novalid:
49
- :no-isobib:
50
- :no-pdf:
51
- :language: fr
52
- INPUT
53
- output = <<~OUTPUT
54
- #{BLANK_HDR_FR}
55
- <sections/>
56
- </iso-standard>
57
- OUTPUT
58
- expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
59
- .to be_equivalent_to xmlpp(output)
60
- end
61
-
62
8
  it "processes default metadata" do
63
9
  output = Asciidoctor.convert(<<~"INPUT", *OPTIONS)
64
10
  = Document title
@@ -212,6 +158,8 @@ RSpec.describe Asciidoctor::ISO do
212
158
  :pub-fax: 4444444
213
159
  :pub-email: x@example.com
214
160
  :pub-uri: http://www.example.com
161
+ :docstage:
162
+ :docsubstage:
215
163
  INPUT
216
164
  expect(xmlpp(output.sub(%r{<boilerplate>.*</boilerplate>}m, "")))
217
165
  .to be_equivalent_to xmlpp(<<~"OUTPUT")
@@ -304,7 +252,6 @@ RSpec.describe Asciidoctor::ISO do
304
252
  <phone type='fax'>4444444</phone>
305
253
  <email>x@example.com</email>
306
254
  <uri>http://www.example.com</uri>
307
- #{' '}
308
255
  </organization>
309
256
  </owner>
310
257
  </copyright>
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::ISO do
4
+ it "processes a blank document" do
5
+ input = <<~INPUT
6
+ #{ASCIIDOC_BLANK_HDR}
7
+ INPUT
8
+ output = <<~OUTPUT
9
+ #{BLANK_HDR}
10
+ <sections/>
11
+ </iso-standard>
12
+ OUTPUT
13
+ expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
14
+ .to be_equivalent_to xmlpp(output)
15
+ end
16
+
17
+ it "converts a blank document" do
18
+ input = <<~INPUT
19
+ = Document title
20
+ Author
21
+ :docfile: test.adoc
22
+ :novalid:
23
+ :no-isobib:
24
+ INPUT
25
+ output = <<~OUTPUT
26
+ #{BLANK_HDR}
27
+ <sections/>
28
+ </iso-standard>
29
+ OUTPUT
30
+ expect(xmlpp(Asciidoctor.convert(input, *OPTIONS)))
31
+ .to be_equivalent_to xmlpp(output)
32
+ expect(File.exist?("test_alt.html")).to be true
33
+ expect(File.exist?("test.html")).to be true
34
+ expect(File.exist?("test.doc")).to be true
35
+ expect(File.exist?("test.pdf")).to be true
36
+ expect(File.exist?("htmlstyle.css")).to be false
37
+ end
38
+ end
@@ -586,4 +586,43 @@ RSpec.describe Asciidoctor::ISO do
586
586
  expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
587
587
  .to be_equivalent_to xmlpp(output)
588
588
  end
589
+
590
+ it "processes nested terms" do
591
+ input = <<~INPUT
592
+ #{ASCIIDOC_BLANK_HDR}
593
+ == Terms and Definitions
594
+
595
+ [.term]
596
+ === Term1
597
+
598
+ definition
599
+
600
+ ==== Term11
601
+ definition2
602
+ INPUT
603
+ output = <<~OUTPUT
604
+ #{BLANK_HDR}
605
+ <sections>
606
+ <terms id='_' obligation='normative'>
607
+ <title>Terms and definitions</title>
608
+ #{TERM_BOILERPLATE}
609
+ <term id='term-term1'>
610
+ <preferred>Term1</preferred>
611
+ <definition>
612
+ <p id='_'>definition</p>
613
+ </definition>
614
+ <term id='term-term11'>
615
+ <preferred>Term11</preferred>
616
+ <definition>
617
+ <p id='_'>definition2</p>
618
+ </definition>
619
+ </term>
620
+ </term>
621
+ </terms>
622
+ </sections>
623
+ </iso-standard>
624
+ OUTPUT
625
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
626
+ .to be_equivalent_to xmlpp(output)
627
+ end
589
628
  end
@@ -26,7 +26,7 @@ RSpec.describe Asciidoctor::ISO do
26
26
  <title>Clause</title>
27
27
  <p id="_">
28
28
  <eref bibitemid="iso123" citeas="ISO 123:--" type="inline"/>
29
- <fn reference="1">The standard is in press</fn>
29
+ <fn reference="1"><p id="_">The standard is in press</p></fn>
30
30
  <eref bibitemid="iso123" citeas="ISO 123:--" type="inline"/>A.
31
31
  <fn reference="2">
32
32
  <p id="_">a footnote</p></fn>