metanorma-iec 1.0.9 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +0 -1
  3. data/.github/workflows/ubuntu.yml +10 -7
  4. data/.github/workflows/windows.yml +0 -1
  5. data/Rakefile +2 -0
  6. data/lib/asciidoctor/iec/converter.rb +11 -15
  7. data/lib/asciidoctor/iec/isodoc.rng +12 -6
  8. data/lib/isodoc/iec/base_convert.rb +9 -71
  9. data/lib/isodoc/iec/html/htmlstyle.css +962 -0
  10. data/lib/isodoc/iec/html/htmlstyle.scss +0 -3
  11. data/lib/isodoc/iec/html/isodoc.css +845 -0
  12. data/lib/isodoc/iec/html/isodoc.scss +0 -1
  13. data/lib/isodoc/iec/html/wordstyle.css +2013 -0
  14. data/lib/isodoc/iec/html/wordstyle.scss +0 -1
  15. data/lib/isodoc/iec/html_convert.rb +2 -0
  16. data/lib/isodoc/iec/i18n-en.yaml +13 -0
  17. data/lib/isodoc/iec/i18n-fr.yaml +13 -0
  18. data/lib/isodoc/iec/i18n-zh-Hans.yaml +11 -0
  19. data/lib/isodoc/iec/i18n.rb +19 -0
  20. data/lib/isodoc/iec/iec.international-standard.xsl +1130 -524
  21. data/lib/isodoc/iec/init.rb +29 -0
  22. data/lib/isodoc/iec/pdf_convert.rb +2 -12
  23. data/lib/isodoc/iec/presentation_xml_convert.rb +35 -0
  24. data/lib/isodoc/iec/word_convert.rb +5 -3
  25. data/lib/isodoc/iec/xref.rb +45 -0
  26. data/lib/metanorma-iec.rb +2 -0
  27. data/lib/metanorma/iec/processor.rb +6 -8
  28. data/lib/metanorma/iec/version.rb +1 -1
  29. data/metanorma-iec.gemspec +3 -2
  30. data/spec/asciidoctor-iec/blocks_spec.rb +1 -1
  31. data/spec/asciidoctor-iec/cleanup_spec.rb +3 -3
  32. data/spec/asciidoctor-iec/iev_spec.rb +74 -1
  33. data/spec/asciidoctor-iec/inline_spec.rb +1 -1
  34. data/spec/asciidoctor-iec/section_spec.rb +17 -15
  35. data/spec/isodoc/blocks_spec.rb +66 -1
  36. data/spec/isodoc/i18n_spec.rb +296 -244
  37. data/spec/isodoc/iev_spec.rb +221 -14
  38. data/spec/isodoc/inline_spec.rb +97 -73
  39. data/spec/isodoc/iso_spec.rb +6 -0
  40. data/spec/isodoc/postproc_spec.rb +15 -29
  41. data/spec/isodoc/ref_spec.rb +129 -2
  42. data/spec/isodoc/section_spec.rb +112 -102
  43. data/spec/isodoc/terms_spec.rb +67 -53
  44. data/spec/metanorma/processor_spec.rb +4 -3
  45. metadata +31 -14
  46. data/lib/asciidoctor/iec/i18n-en.yaml +0 -12
  47. data/lib/asciidoctor/iec/i18n-fr.yaml +0 -11
  48. data/lib/asciidoctor/iec/i18n-zh-Hans.yaml +0 -9
@@ -0,0 +1,29 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require_relative "xref"
4
+ require_relative "i18n"
5
+
6
+ module IsoDoc
7
+ module Iec
8
+ module Init
9
+ def metadata_init(lang, script, labels)
10
+ @meta = Metadata.new(lang, script, labels)
11
+ end
12
+
13
+ def xref_init(lang, script, klass, labels, options)
14
+ @xrefs = Xref.new(lang, script, HtmlConvert.new(language: lang, script: script), labels, options)
15
+ end
16
+
17
+ def i18n_init(lang, script, i18nyaml = nil)
18
+ @i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
19
+ end
20
+
21
+ def convert1(docxml, filename, dir)
22
+ id = docxml&.at(ns("//bibdata/docnumber"))&.text
23
+ @is_iev = id == "60050"
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -13,18 +13,8 @@ module IsoDoc
13
13
  super
14
14
  end
15
15
 
16
- def convert(filename, file = nil, debug = false)
17
- file = File.read(filename, encoding: "utf-8") if file.nil?
18
- docxml, outname_html, dir = convert_init(file, filename, debug)
19
- /\.xml$/.match(filename) or
20
- filename = Tempfile.open([outname_html, ".xml"], encoding: "utf-8") do |f|
21
- f.write file
22
- f.path
23
- end
24
- FileUtils.rm_rf dir
25
- ::Metanorma::Output::XslfoPdf.new.convert(
26
- filename, outname_html + ".pdf",
27
- File.join(@libdir, "iec.international-standard.xsl"))
16
+ def pdf_stylesheet(docxml)
17
+ "iec.international-standard.xsl"
28
18
  end
29
19
  end
30
20
  end
@@ -0,0 +1,35 @@
1
+ require_relative "init"
2
+ require "isodoc"
3
+
4
+ module IsoDoc
5
+ module Iec
6
+ class PresentationXMLConvert < IsoDoc::Iso::PresentationXMLConvert
7
+ def clause(docxml)
8
+ docxml.xpath(ns("//clause[not(ancestor::annex)] | "\
9
+ "//definitions | //references | "\
10
+ "//preface/introduction[clause]")).
11
+ each do |f|
12
+ clause1(f)
13
+ end
14
+ docxml.xpath(ns("//terms")).each do |f|
15
+ termclause1(f)
16
+ end
17
+ end
18
+
19
+ def termclause1(f)
20
+ return clause1(f) unless @is_iev
21
+ return if @suppressheadingnumbers || f["unnumbered"]
22
+ lbl = @xrefs.anchor(f['id'], :label, true) or return
23
+ prefix_name(f, " ", "#{lbl}#{clausedelim}", "title")
24
+ end
25
+
26
+ def clause1(f)
27
+ IsoDoc::PresentationXMLConvert.instance_method(:clause1).bind(self).
28
+ call(f)
29
+ end
30
+
31
+ include Init
32
+ end
33
+ end
34
+ end
35
+
@@ -1,6 +1,7 @@
1
1
  require "isodoc"
2
2
  require "metanorma-iso"
3
3
  require_relative "base_convert"
4
+ require_relative "init"
4
5
 
5
6
  module IsoDoc
6
7
  module Iec
@@ -47,7 +48,7 @@ module IsoDoc
47
48
  <span lang="EN-GB"><span
48
49
  style='mso-element:field-begin'></span><span
49
50
  style='mso-spacerun:yes'>&#xA0;</span>TOC
50
- \\h \\z \\t &quot;TableTitle,1&quot; <span
51
+ \\h \\z \\t &quot;TableTitle,tabletitle&quot; <span
51
52
  style='mso-element:field-separator'></span></span>
52
53
  TOC
53
54
 
@@ -55,7 +56,7 @@ module IsoDoc
55
56
  <span lang="EN-GB"><span
56
57
  style='mso-element:field-begin'></span><span
57
58
  style='mso-spacerun:yes'>&#xA0;</span>TOC
58
- \\h \\z \\t &quot;FigureTitle,1&quot; <span
59
+ \\h \\z \\t &quot;FigureTitle,figuretitle&quot; <span
59
60
  style='mso-element:field-separator'></span></span>
60
61
  TOC
61
62
 
@@ -171,7 +172,7 @@ module IsoDoc
171
172
  div.p **attr_code(class: "formula") do |p|
172
173
  insert_tab(div, 1)
173
174
  parse(node.at(ns("./stem")), div)
174
- lbl = anchor(node['id'], :label, false)
175
+ lbl = node&.at(ns("./name"))&.text
175
176
  unless lbl.nil?
176
177
  insert_tab(div, 1)
177
178
  div << "(#{lbl})"
@@ -181,6 +182,7 @@ module IsoDoc
181
182
  end
182
183
 
183
184
  include BaseConvert
185
+ include Init
184
186
  end
185
187
  end
186
188
  end
@@ -0,0 +1,45 @@
1
+ module IsoDoc
2
+ module Iec
3
+ class Xref < IsoDoc::Iso::Xref
4
+ def parse(docxml)
5
+ id = docxml&.at(ns("//bibdata/docnumber"))&.text
6
+ @is_iev = id == "60050"
7
+ id = docxml&.at(ns("//bibdata/docidentifier[@type = 'ISO']"))&.text
8
+ m = /60050-(\d+)/.match(id) and @iev_part = m[1]
9
+ super
10
+ end
11
+
12
+ def introduction_names(clause)
13
+ return super unless @is_iev
14
+ end
15
+
16
+ def initial_anchor_names(d)
17
+ super
18
+ return unless @is_iev
19
+ terms_iev_names(d)
20
+ middle_section_asset_names(d)
21
+ termnote_anchor_names(d)
22
+ termexample_anchor_names(d)
23
+ end
24
+
25
+ def terms_iev_names(d)
26
+ d.xpath(ns("//sections/clause/terms")).each_with_index do |t, i|
27
+ num = "#{@iev_part}-%02d" % [i+1]
28
+ @anchors[t["id"]] =
29
+ { label: num, xref: l10n("#{@labels["section_iev"]}-#{num}"), level: 2,
30
+ type: "clause" }
31
+ t.xpath(ns("./term")).each_with_index do |c, i|
32
+ num2 = "%02d" % [i+1]
33
+ section_names1(c, "#{num}-#{num2}", 3)
34
+ end
35
+ end
36
+ end
37
+
38
+ def annex_name_lbl(clause, num)
39
+ obl = l10n("(#{@labels["inform_annex"]})")
40
+ obl = l10n("(#{@labels["norm_annex"]})") if clause["obligation"] == "normative"
41
+ l10n("<strong>#{@labels["annex"]} #{num}</strong><br/>#{obl}")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -4,7 +4,9 @@ require_relative "metanorma/iec/version"
4
4
  require "isodoc/iec/html_convert"
5
5
  require "isodoc/iec/word_convert"
6
6
  require "isodoc/iec/pdf_convert"
7
+ require "isodoc/iec/presentation_xml_convert"
7
8
  require "isodoc/iec/metadata"
9
+ require "isodoc/iec/xref"
8
10
 
9
11
  if defined? Metanorma
10
12
  require_relative "metanorma/iec"
@@ -30,18 +30,16 @@ module Metanorma
30
30
  "Metanorma::Iec #{Metanorma::Iec::VERSION}"
31
31
  end
32
32
 
33
- def input_to_isodoc(file, filename)
34
- Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
35
- end
36
-
37
- def output(isodoc_node, outname, format, options={})
33
+ def output(isodoc_node, inname, outname, format, options={})
38
34
  case format
39
35
  when :html
40
- IsoDoc::Iec::HtmlConvert.new(options).convert(outname, isodoc_node)
36
+ IsoDoc::Iec::HtmlConvert.new(options).convert(inname, isodoc_node, nil, outname)
41
37
  when :doc
42
- IsoDoc::Iec::WordConvert.new(options).convert(outname, isodoc_node)
38
+ IsoDoc::Iec::WordConvert.new(options).convert(inname, isodoc_node, nil, outname)
43
39
  when :pdf
44
- IsoDoc::Iec::PdfConvert.new(options).convert(outname, isodoc_node)
40
+ IsoDoc::Iec::PdfConvert.new(options).convert(inname, isodoc_node, nil, outname)
41
+ when :presentation
42
+ IsoDoc::Iec::PresentationXMLConvert.new(options).convert(inname, isodoc_node, nil, outname)
45
43
  else
46
44
  super
47
45
  end
@@ -1,6 +1,6 @@
1
1
  module Metanorma
2
2
  module Iec
3
- VERSION = "1.0.9"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
6
6
 
@@ -28,10 +28,11 @@ Gem::Specification.new do |spec|
28
28
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
29
29
 
30
30
  spec.add_dependency "ruby-jing"
31
- spec.add_dependency "isodoc", "~> 1.0.0"
32
- spec.add_dependency "metanorma-iso", "~> 1.3.0"
31
+ spec.add_dependency "isodoc", "~> 1.2.0"
32
+ spec.add_dependency "metanorma-iso", "~> 1.5.0"
33
33
 
34
34
  spec.add_development_dependency "byebug"
35
+ spec.add_development_dependency "sassc", "2.4.0"
35
36
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
36
37
  spec.add_development_dependency "guard", "~> 2.14"
37
38
  spec.add_development_dependency "guard-rspec", "~> 4.7"
@@ -265,7 +265,7 @@ RSpec.describe Asciidoctor::Iec do
265
265
  INPUT
266
266
  #{BLANK_HDR}
267
267
  <preface><foreword id="_" obligation="informative">
268
- <title>Foreword</title>
268
+ <title>FOREWORD</title>
269
269
  <p id="_">This is a preamble</p>
270
270
  </foreword></preface><sections>
271
271
  <clause id="_" inline-header="false" obligation="normative">
@@ -121,7 +121,7 @@ RSpec.describe Asciidoctor::Iec do
121
121
  #{BLANK_HDR}
122
122
  <preface>
123
123
  <foreword id="_" obligation="informative">
124
- <title>Foreword</title>
124
+ <title>FOREWORD</title>
125
125
  <p id="_">
126
126
  <eref type="inline" bibitemid="iso216" citeas="ISO 216"/>
127
127
  </p>
@@ -189,7 +189,7 @@ RSpec.describe Asciidoctor::Iec do
189
189
  INPUT
190
190
  #{BLANK_HDR}
191
191
  <sections></sections>
192
- <bibliography><references id="_" obligation="informative" normative="true"><title>Normative References</title>
192
+ <bibliography><references id="_" obligation="informative" normative="true"><title>Normative references</title>
193
193
  <p id="_">The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.</p>
194
194
  <bibitem id="iso216" type="standard">
195
195
  <title format="text/plain">Reference</title>
@@ -288,7 +288,7 @@ RSpec.describe Asciidoctor::Iec do
288
288
  INPUT
289
289
  #{BLANK_HDR}
290
290
  <sections><formula id="_">
291
- <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>F</mi><mtext>or</mtext><mi>μ</mi><mi>l</mi><mi>a</mi></math></stem>
291
+ <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>F</mi><mi>or</mi><mi>μ</mi><mi>l</mi><mi>a</mi></math></stem>
292
292
  <dl id="_">
293
293
  <dt>a</dt>
294
294
  <dd>
@@ -68,7 +68,7 @@ RSpec.describe Asciidoctor::Iec do
68
68
  <sections> </sections>
69
69
  <bibliography>
70
70
  <references id='_' obligation='informative' normative="true">
71
- <title>Normative References</title>
71
+ <title>Normative references</title>
72
72
  <p id='_'>There are no normative references in this document.</p>
73
73
  <bibitem id='A'>
74
74
  <formattedref format='application/x-isodoc+xml'>
@@ -158,4 +158,77 @@ INPUT
158
158
 
159
159
  OUTPUT
160
160
  end
161
+
162
+ it "uses IEV introduction title" do
163
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
164
+ = Document title
165
+ Author
166
+ :docfile: test.adoc
167
+ :nodoc:
168
+ :novalid:
169
+ :no-isobib:
170
+ :docnumber: 60050
171
+
172
+ == Introduction
173
+
174
+ Text
175
+ INPUT
176
+ <?xml version='1.0' encoding='UTF-8'?>
177
+ <iec-standard xmlns='https://www.metanorma.org/ns/iec'>
178
+ <bibdata type='standard'>
179
+ <docidentifier type='ISO'>IEC 60050 ED 1</docidentifier>
180
+ <docnumber>60050</docnumber>
181
+ <contributor>
182
+ <role type='author'/>
183
+ <organization>
184
+ <name>International Electrotechnical Commission</name>
185
+ <abbreviation>IEC</abbreviation>
186
+ </organization>
187
+ </contributor>
188
+ <contributor>
189
+ <role type='publisher'/>
190
+ <organization>
191
+ <name>International Electrotechnical Commission</name>
192
+ <abbreviation>IEC</abbreviation>
193
+ </organization>
194
+ </contributor>
195
+ <language>en</language>
196
+ <script>Latn</script>
197
+ <status>
198
+ <stage abbreviation='PPUB'>60</stage>
199
+ <substage abbreviation='PPUB'>60</substage>
200
+ </status>
201
+ <copyright>
202
+ <from>2020</from>
203
+ <owner>
204
+ <organization>
205
+ <name>International Electrotechnical Commission</name>
206
+ <abbreviation>IEC</abbreviation>
207
+ </organization>
208
+ </owner>
209
+ </copyright>
210
+ <ext>
211
+ <doctype>article</doctype>
212
+ <editorialgroup>
213
+ <technical-committee/>
214
+ <subcommittee/>
215
+ <workgroup/>
216
+ </editorialgroup>
217
+ <structuredidentifier>
218
+ <project-number>IEC 60050</project-number>
219
+ </structuredidentifier>
220
+ <stagename>International standard</stagename>
221
+ </ext>
222
+ </bibdata>
223
+ #{BOILERPLATE}
224
+ <preface>
225
+ <introduction id='_' obligation='informative'>
226
+ <title>INTRODUCTION&lt;br/&gt;Principles and rules followed</title>
227
+ <p id='_'>Text</p>
228
+ </introduction>
229
+ </preface>
230
+ <sections> </sections>
231
+ </iec-standard>
232
+ OUTPUT
233
+ end
161
234
  end
@@ -128,7 +128,7 @@ RSpec.describe Asciidoctor::Iec do
128
128
  <sections>
129
129
 
130
130
  </sections><bibliography><references id="_" obligation="informative" normative="true">
131
- <title>Normative References</title>
131
+ <title>Normative references</title>
132
132
  <p id="_">The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.</p>
133
133
  <bibitem id="ISO712">
134
134
  <formattedref format="application/x-isodoc+xml">Reference</formattedref>
@@ -54,13 +54,14 @@ RSpec.describe Asciidoctor::Iec do
54
54
  INPUT
55
55
  #{BLANK_HDR}
56
56
  <preface><foreword id="_" obligation="informative">
57
- <title>Foreword</title>
57
+ <title>FOREWORD</title>
58
58
  <p id="_">Text</p>
59
- </foreword><introduction id="_" obligation="informative"><title>Introduction</title><clause id="_" inline-header="false" obligation="informative">
59
+ </foreword><introduction id="_" obligation="informative">
60
+ <title>INTRODUCTION</title><clause id="_" inline-header="false" obligation="informative">
60
61
  <title>Introduction Subsection</title>
61
62
  </clause>
62
63
  </introduction></preface><sections>
63
- <clause id="_" obligation="normative">
64
+ <clause id="_" obligation="normative" type="scope" inline-header='false'>
64
65
  <title>Scope</title>
65
66
  <p id="_">Text</p>
66
67
  </clause>
@@ -98,8 +99,8 @@ RSpec.describe Asciidoctor::Iec do
98
99
  <preferred>Term2</preferred>
99
100
  </term>
100
101
  </terms>
101
- <definitions id="_"><title>Symbols and Abbreviated Terms</title></definitions></clause>
102
- <definitions id="_"><title>Symbols and Abbreviated Terms</title></definitions>
102
+ <definitions id="_" obligation="normative"><title>Symbols and abbreviated terms</title></definitions></clause>
103
+ <definitions id="_" obligation="normative"><title>Symbols and abbreviated terms</title></definitions>
103
104
  <clause id="_" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="_" inline-header="false" obligation="normative">
104
105
  <title>Introduction</title>
105
106
  </clause>
@@ -119,7 +120,7 @@ RSpec.describe Asciidoctor::Iec do
119
120
  <appendix id="_" inline-header="false" obligation="normative">
120
121
  <title>Appendix 1</title>
121
122
  </appendix></annex><bibliography><references id="_" obligation="informative" normative="true">
122
- <title>Normative References</title><p id="_">There are no normative references in this document.</p>
123
+ <title>Normative references</title><p id="_">There are no normative references in this document.</p>
123
124
  </references><clause id="_" obligation="informative">
124
125
  <title>Bibliography</title>
125
126
  <references id="_" obligation="informative" normative="false">
@@ -191,16 +192,17 @@ RSpec.describe Asciidoctor::Iec do
191
192
  #{BLANK_HDR}
192
193
  <preface>
193
194
  <foreword id="_" obligation="informative">
194
- <title>Foreword</title>
195
+ <title>FOREWORD</title>
195
196
  <p id="_">Text</p>
196
197
  </foreword>
197
- <introduction id="_" obligation="informative"><title>Introduction</title><clause id="_" inline-header="false" obligation="informative">
198
+ <introduction id="_" obligation="informative">
199
+ <title>INTRODUCTION</title><clause id="_" inline-header="false" obligation="informative">
198
200
  <title>Introduction Subsection</title>
199
201
  </clause>
200
202
  </introduction>
201
203
  </preface>
202
204
  <sections>
203
- <clause id="_" obligation="normative">
205
+ <clause id="_" obligation="normative" type="scope" inline-header='false'>
204
206
  <title>Scope</title>
205
207
  <p id="_">Text</p>
206
208
  </clause>
@@ -214,7 +216,7 @@ RSpec.describe Asciidoctor::Iec do
214
216
  </term>
215
217
  </terms>
216
218
  <clause id='_' obligation='normative'>
217
- <title>Terms and definitions</title>
219
+ <title>Terms, definitions, symbols and abbreviated terms</title>
218
220
  <terms id='_' obligation='normative'>
219
221
  <title>Normal Terms</title>
220
222
  <p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
@@ -240,12 +242,12 @@ RSpec.describe Asciidoctor::Iec do
240
242
  <preferred>Term2</preferred>
241
243
  </term>
242
244
  </terms>
243
- <definitions id='_'>
244
- <title>Σύμβολα και Συντομογραφίες</title>
245
+ <definitions id='_' obligation="normative">
246
+ <title>Symbols and abbreviated terms</title>
245
247
  </definitions>
246
248
  </clause>
247
- <definitions id='_'>
248
- <title>Σύμβολα και Συντομογραφίες</title>
249
+ <definitions id='_' obligation="normative">
250
+ <title>Symbols and abbreviated terms</title>
249
251
  </definitions>
250
252
  <clause id='_' inline-header='false' obligation='normative'>
251
253
  <title>Clause 4</title>
@@ -268,7 +270,7 @@ RSpec.describe Asciidoctor::Iec do
268
270
  </annex>
269
271
  <bibliography>
270
272
  <references id='_' obligation='informative' normative="true">
271
- <title>Normative References</title>
273
+ <title>Normative references</title>
272
274
  <p id="_">There are no normative references in this document.</p>
273
275
  </references>
274
276
  <clause id='_' obligation='informative'>