metanorma-un 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d89413090ed747b554d765b2c2670f943aab27e38f9b1db11c6adc6433932d31
4
- data.tar.gz: 5a2b19fda5a3ed32ab7231ca27fae981d5b315287b4d9cd17a9d272b8e604dd1
3
+ metadata.gz: 84ac6004180fc5b55f02c08ce72d19b4b2e0de5f5b406f4c6796fe5595edeee6
4
+ data.tar.gz: 0d742071c23c5455cca3ddcd9a13dcdcf45ad781478dfad4a4297510697e5f70
5
5
  SHA512:
6
- metadata.gz: 4dfc69a0efb1d8a48b6b479bcbdcb70ef22e5c733a0e6edfe210a66033af618de7daf596182957b53f0ab0be0187c5b7ad2abb8261258ea0609bf9d79cbba139
7
- data.tar.gz: 61f54df3a3d6b56718f887c81d0c3fca978e25fcffbbfc41d9a4b3f9e99cd86a7f86f483cdda80701bf7db16714cd49d7b90db8d732ce5f77e55ac09e9202fa6
6
+ metadata.gz: e0d3b23e08336a19b8000792d0facbb9e7311f77ef014e5931503027b5dd9e54fa84e6135c4e38535a8bc0a75d476f5b8ac95443cda73b1e9c4cb19a3d5b3571
7
+ data.tar.gz: 88d72ed256d4c45d0c1873c42423fcc6449a99b0a3efa8d842f9d33fcf63dc823a102fac228b4c3fb9a82f737e20cd3befeb6a43e59c7b13884a4c7f301216b6
@@ -5,10 +5,6 @@ require_relative "validate"
5
5
 
6
6
  module Asciidoctor
7
7
  module UN
8
-
9
- # A {Converter} implementation that generates RSD output, and a document
10
- # schema encapsulation of the document for validation
11
- #
12
8
  class Converter < Standoc::Converter
13
9
  XML_ROOT_TAG = "un-standard".freeze
14
10
  XML_NAMESPACE = "https://www.metanorma.org/ns/un".freeze
@@ -49,14 +45,20 @@ module Asciidoctor
49
45
  end
50
46
  end
51
47
 
48
+ def asciidoc_sub(text)
49
+ Asciidoctor::Standoc::Utils::asciidoc_sub(text)
50
+ end
51
+
52
52
  def title(node, xml)
53
53
  ["en"].each do |lang|
54
- xml.title **{ type: "main", language: lang, format: "text/plain" } do |t|
55
- t << (Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("title")) || node.title)
54
+ xml.title **{ type: "main", language: lang,
55
+ format: "text/plain" } do |t|
56
+ t << (asciidoc_sub(node.attr("title")) || node.title)
56
57
  end
57
58
  node.attr("subtitle") and
58
- xml.title **{ type: "subtitle", language: lang, format: "text/plain" } do |t|
59
- t << Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("subtitle"))
59
+ xml.title **{ type: "subtitle", language: lang,
60
+ format: "text/plain" } do |t|
61
+ t << asciidoc_sub(node.attr("subtitle"))
60
62
  end
61
63
  end
62
64
  end
@@ -64,7 +66,8 @@ module Asciidoctor
64
66
  def metadata_id(node, xml)
65
67
  dn = node.attr("docnumber")
66
68
  if docstatus = node.attr("status")
67
- abbr = IsoDoc::UN::Metadata.new("en", "Latn", {}).stage_abbr(docstatus)
69
+ abbr = IsoDoc::UN::Metadata.new("en", "Latn", @i18n)
70
+ .stage_abbr(docstatus)
68
71
  dn = "#{dn}(#{abbr})" unless abbr.empty?
69
72
  end
70
73
  xml.docidentifier { |i| i << dn }
@@ -92,17 +95,26 @@ module Asciidoctor
92
95
  xml.session do |session|
93
96
  session.number node.attr("session") if node.attr("session")
94
97
  session.date node.attr("session-date") if node.attr("session-date")
95
- node&.attr("item-number")&.split(/,[ ]*/)&.each { |i| session.item_number i }
96
- node&.attr("item-name")&.split(/,[ ]*/)&.each { |i| session.item_name i }
97
- node&.attr("subitem-name")&.split(/,[ ]*/)&.each { |i| session.subitem_name i }
98
- session.collaborator node.attr("collaborator") if node.attr("collaborator")
98
+ node&.attr("item-number")&.split(/,[ ]*/)&.each do |i|
99
+ session.item_number i
100
+ end
101
+ node&.attr("item-name")&.split(/,[ ]*/)&.each do |i|
102
+ session.item_name i
103
+ end
104
+ node&.attr("subitem-name")&.split(/,[ ]*/)&.each do |i|
105
+ session.subitem_name i
106
+ end
107
+ node.attr("collaborator") and
108
+ session.collaborator node.attr("collaborator")
99
109
  session.id node.attr("agenda-id") if node.attr("agenda-id")
100
- session.item_footnote node.attr("item-footnote") if node.attr("item-footnote")
110
+ node.attr("item-footnote") and
111
+ session.item_footnote node.attr("item-footnote")
101
112
  end
102
113
  end
103
114
 
104
115
  def metadata_language(node, xml)
105
- languages = node&.attr("language")&.split(/,[ ]*/) || %w(ar ru en fr zh es)
116
+ languages = node&.attr("language")&.split(/,[ ]*/) ||
117
+ %w(ar ru en fr zh es)
106
118
  languages.each { |l| xml.language l }
107
119
  end
108
120
 
@@ -124,15 +136,19 @@ module Asciidoctor
124
136
 
125
137
  def makexml(node)
126
138
  @draft = node.attributes.has_key?("draft")
127
- @no_number_subheadings = node.attributes.has_key?("do-not-number-subheadings")
139
+ @no_number_subheadings =
140
+ node.attributes.has_key?("do-not-number-subheadings")
128
141
  super
129
142
  end
130
143
 
131
144
  def doctype(node)
132
145
  d = node.attr("doctype")
133
- unless %w{plenary recommendation addendum communication corrigendum reissue
134
- agenda budgetary sec-gen-notes expert-report resolution plenary-attachment}.include? d
135
- @log.add("Document Attributes", nil, "#{d} is not a legal document type: reverting to 'recommendation'")
146
+ unless %w{plenary recommendation addendum communication corrigendum
147
+ reissue agenda budgetary sec-gen-notes expert-report resolution
148
+ plenary-attachment}.include? d
149
+ @log.add(
150
+ "Document Attributes", nil,
151
+ "#{d} is not a legal document type: reverting to 'recommendation'")
136
152
  d = "recommendation"
137
153
  end
138
154
  d
@@ -141,9 +157,12 @@ module Asciidoctor
141
157
  def outputs(node, ret)
142
158
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
143
159
  presentation_xml_converter(node).convert(@filename + ".xml")
144
- html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
145
- doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
146
- pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf")
160
+ html_converter(node).convert(@filename + ".presentation.xml",
161
+ nil, false, "#{@filename}.html")
162
+ doc_converter(node).convert(@filename + ".presentation.xml",
163
+ nil, false, "#{@filename}.doc")
164
+ pdf_converter(node)&.convert(@filename + ".presentation.xml",
165
+ nil, false, "#{@filename}.pdf")
147
166
  end
148
167
 
149
168
  def validate(doc)
@@ -217,10 +236,8 @@ module Asciidoctor
217
236
  end
218
237
 
219
238
  def admonition_attrs(node)
220
- attr_code(super.merge(
221
- "unnumbered": node.option?("unnumbered"),
222
- "subsequence": node.attr("subsequence"),
223
- ))
239
+ attr_code(super.merge("unnumbered": node.option?("unnumbered"),
240
+ "subsequence": node.attr("subsequence")))
224
241
  end
225
242
 
226
243
  def sectiontype_streamline(ret)
@@ -922,6 +922,9 @@
922
922
  <optional>
923
923
  <attribute name="script"/>
924
924
  </optional>
925
+ <optional>
926
+ <attribute name="type"/>
927
+ </optional>
925
928
  <optional>
926
929
  <attribute name="obligation">
927
930
  <choice>
@@ -961,9 +964,6 @@
961
964
  </define>
962
965
  <define name="content-subsection">
963
966
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
967
  <ref name="Content-Section"/>
968
968
  </element>
969
969
  </define>
@@ -992,6 +992,9 @@
992
992
  </choice>
993
993
  </attribute>
994
994
  </optional>
995
+ <optional>
996
+ <attribute name="type"/>
997
+ </optional>
995
998
  <optional>
996
999
  <ref name="section-title"/>
997
1000
  </optional>
@@ -1011,9 +1014,6 @@
1011
1014
  </define>
1012
1015
  <define name="clause">
1013
1016
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1017
  <ref name="Clause-Section"/>
1018
1018
  </element>
1019
1019
  </define>
@@ -1042,6 +1042,9 @@
1042
1042
  </choice>
1043
1043
  </attribute>
1044
1044
  </optional>
1045
+ <optional>
1046
+ <attribute name="type"/>
1047
+ </optional>
1045
1048
  <optional>
1046
1049
  <ref name="section-title"/>
1047
1050
  </optional>
@@ -1180,6 +1183,9 @@
1180
1183
  <optional>
1181
1184
  <attribute name="script"/>
1182
1185
  </optional>
1186
+ <optional>
1187
+ <attribute name="type"/>
1188
+ </optional>
1183
1189
  <optional>
1184
1190
  <attribute name="obligation">
1185
1191
  <choice>
@@ -14,7 +14,8 @@ module Asciidoctor
14
14
  stage = xmldoc&.at("//bibdata/status/stage")&.text
15
15
  %w(proposal working-draft committee-draft draft-standard final-draft
16
16
  published withdrawn).include? stage or
17
- @log.add("Document Attributes", nil, "#{stage} is not a recognised status")
17
+ @log.add("Document Attributes", nil,
18
+ "#{stage} is not a recognised status")
18
19
  end
19
20
  end
20
21
  end
@@ -1,52 +1,12 @@
1
- require_relative "metadata"
2
- require_relative "xref"
3
1
  require "fileutils"
4
2
 
5
3
  module IsoDoc
6
4
  module UN
7
5
  module BaseConvert
8
- def metadata_init(lang, script, labels)
9
- @meta = Metadata.new(lang, script, labels)
10
- @meta.set(:toc, @toc)
11
- end
12
-
13
- def xref_init(lang, script, klass, labels, options)
14
- @xrefs = Xref.new(lang, script, klass, labels, options)
15
- end
16
-
17
- def annex_name(annex, name, div)
18
- div.h1 **{ class: "Annex" } do |t|
19
- t << "#{@xrefs.anchor(annex['id'], :label)}"
20
- t.br
21
- t.b do |b|
22
- name&.children&.each { |c2| parse(c2, b) }
23
- end
24
- end
25
- end
26
-
27
- def i18n_init(lang, script)
28
- super
29
- @admonition_lbl = "Box"
30
- @abstract_lbl = "Summary"
31
- end
32
-
33
- def fileloc(loc)
34
- File.join(File.dirname(__FILE__), loc)
35
- end
36
-
37
6
  def middle_clause
38
7
  "//clause[parent::sections]"
39
8
  end
40
9
 
41
- def admonition_name_parse(node, div, name)
42
- div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p|
43
- lbl = @xrefs.anchor(node['id'], :label)
44
- lbl.nil? or p << l10n("#{@admonition_lbl} #{lbl}")
45
- name and !lbl.nil? and p << "&nbsp;&mdash; "
46
- name and name.children.each { |n| parse(n, div) }
47
- end
48
- end
49
-
50
10
  def admonition_parse(node, out)
51
11
  name = node.at(ns("./name"))
52
12
  out.div **admonition_attrs(node) do |t|
@@ -57,13 +17,10 @@ def xref_init(lang, script, klass, labels, options)
57
17
  end
58
18
  end
59
19
 
60
- def inline_header_title(out, node, c1)
20
+ def inline_header_title(out, node, title)
61
21
  out.span **{ class: "zzMoveToFollowing" } do |s|
62
- if lbl = @xrefs.anchor(node['id'], :label)
63
- s << "#{lbl}. " unless @suppressheadingnumbers
64
- insert_tab(s, 1)
65
- end
66
- c1&.children&.each { |c2| parse(c2, s) }
22
+ title&.children&.each { |c2| parse(c2, s) }
23
+ clausedelimspace(out) if /\S/.match(title&.text)
67
24
  end
68
25
  end
69
26
 
@@ -73,18 +30,6 @@ def xref_init(lang, script, klass, labels, options)
73
30
  return true if docxml&.at(ns("//bibdata/ext/session/*"))
74
31
  false
75
32
  end
76
-
77
- def note_label(node)
78
- n = @xrefs.get[node["id"]]
79
- lbl = case node["type"]
80
- when "source" then "Source"
81
- when "abbreviation" then "Abbreviations"
82
- else
83
- @note_lbl
84
- end
85
- return "#{lbl}:" # if n.nil? || n[:label].nil? || n[:label].empty?
86
- #l10n("#{lbl} #{n[:label]}:")
87
- end
88
33
  end
89
34
  end
90
35
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "base_convert"
2
+ require_relative "init"
2
3
  require "isodoc"
3
4
 
4
5
  module IsoDoc
@@ -48,8 +49,10 @@ module IsoDoc
48
49
 
49
50
  def make_body(xml, docxml)
50
51
  plenary = is_plenary?(docxml)
51
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
52
- if plenary && @htmlcoverpage == html_doc_path("html_unece_titlepage.html")
52
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72",
53
+ "xml:lang": "EN-US", class: "container" }
54
+ if plenary &&
55
+ @htmlcoverpage == html_doc_path("html_unece_titlepage.html")
53
56
  @htmlcoverpage = html_doc_path("html_unece_plenary_titlepage.html")
54
57
  end
55
58
  xml.body **body_attr do |body|
@@ -80,26 +83,11 @@ module IsoDoc
80
83
  bibliography isoxml, out
81
84
  end
82
85
 
83
- def clause_parse_title(node, div, c1, out)
84
- if node["inline-header"] == "true"
85
- inline_header_title(out, node, c1)
86
- else
87
- div.send "h#{@xrefs.anchor(node['id'], :level, false) || '1'}" do |h|
88
- lbl = @xrefs.anchor(node['id'], :label, false)
89
- h << "#{lbl}. " if lbl && !@suppressheadingnumbers
90
- insert_tab(h, 1) if lbl && !@suppressheadingnumbers
91
- c1&.children&.each { |c2| parse(c2, h) }
92
- end
93
- end
94
- end
95
-
96
86
  def introduction(isoxml, out)
97
87
  f = isoxml.at(ns("//introduction")) || return
98
88
  page_break(out)
99
89
  out.div **{ class: "Section3", id: f["id"] } do |div|
100
- div.h1(**{ class: "IntroTitle" }) do |h1|
101
- h1 << @introduction_lbl
102
- end
90
+ clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" })
103
91
  f.elements.each do |e|
104
92
  parse(e, div) unless e.name == "title"
105
93
  end
@@ -110,14 +98,14 @@ module IsoDoc
110
98
  f = isoxml.at(ns("//foreword")) || return
111
99
  page_break(out)
112
100
  out.div **attr_code(id: f["id"]) do |s|
113
- s.h1(**{ class: "ForewordTitle" }) do |h1|
114
- h1 << @foreword_lbl
115
- end
101
+ clause_name(nil, f.at(ns("./title")) || @i18n.foreword, s,
102
+ class: "ForewordTitle")
116
103
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
117
104
  end
118
105
  end
119
106
 
120
107
  include BaseConvert
108
+ include Init
121
109
  end
122
110
  end
123
111
  end
@@ -0,0 +1,2 @@
1
+ admonition: Box
2
+ abstract: Summary
@@ -0,0 +1,11 @@
1
+ module IsoDoc
2
+ module UN
3
+ class I18n < IsoDoc::I18n
4
+ def load_yaml1(lang, script)
5
+ y = YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
6
+ super.merge(y)
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -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 UN
8
+ module Init
9
+ def metadata_init(lang, script, labels)
10
+ @meta = Metadata.new(lang, script, labels)
11
+ @meta.set(:toc, @toc)
12
+ end
13
+
14
+ def xref_init(lang, script, klass, labels, options)
15
+ html = HtmlConvert.new(language: lang, script: script)
16
+ @xrefs = Xref.new(lang, script, html, labels, options)
17
+ end
18
+
19
+ def i18n_init(lang, script, i18nyaml = nil)
20
+ @i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
21
+ end
22
+
23
+ def fileloc(loc)
24
+ File.join(File.dirname(__FILE__), loc)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -13,12 +13,14 @@ module IsoDoc
13
13
  end
14
14
 
15
15
  def title(isoxml, _out)
16
- main = isoxml&.at(ns("//bibdata/title[@language='en' and @type='main']"))&.text
16
+ main = isoxml&.at(ns("//bibdata/title"\
17
+ "[@language='en' and @type='main']"))&.text
17
18
  set(:doctitle, main)
18
19
  end
19
20
 
20
21
  def subtitle(isoxml, _out)
21
- main = isoxml&.at(ns("//bibdata/title[@language='en' and @type='subtitle']"))&.text
22
+ main = isoxml&.at(ns("//bibdata/title"\
23
+ "[@language='en' and @type='subtitle']"))&.text
22
24
  set(:docsubtitle, main)
23
25
  end
24
26
 
@@ -36,8 +38,10 @@ module IsoDoc
36
38
  set(:tc, tc.text) if tc
37
39
  set(:distribution, isoxml&.at(ns("//bibdata/ext/distribution"))&.text)
38
40
  lgs = extract_languages(isoxml.xpath(ns("//bibdata/language")))
39
- lgs = [] if lgs.sort == %w(English French Arabic Chinese Russian Spanish).sort
40
- slgs = extract_languages(isoxml.xpath(ns("//bibdata/ext/submissionlanguage")))
41
+ lgs.sort == %w(English French Arabic Chinese Russian Spanish).sort and
42
+ lgs = []
43
+ slgs = extract_languages(isoxml.xpath(ns("//bibdata/ext/"\
44
+ "submissionlanguage")))
41
45
  lgs = [] if slgs.size == 1
42
46
  set(:doclanguage, lgs) unless lgs.empty?
43
47
  set(:submissionlanguage, slgs) unless slgs.empty?
@@ -52,25 +56,32 @@ module IsoDoc
52
56
  end
53
57
 
54
58
  def session(isoxml, _out)
55
- set(:session_number, isoxml&.at(ns("//bibdata/ext/session/number"))&.text&.to_i&.
56
- localize&.to_rbnf_s("SpelloutRules", "spellout-ordinal")&.capitalize)
59
+ set(:session_number, isoxml&.at(ns("//bibdata/ext/session/number"))&.
60
+ text&.to_i&.localize&.
61
+ to_rbnf_s("SpelloutRules", "spellout-ordinal")&.capitalize)
57
62
  set(:session_date, isoxml&.at(ns("//bibdata/ext/session/date"))&.text)
58
- set(:session_collaborator, isoxml&.at(ns("//bibdata/ext/session/collaborator"))&.text)
63
+ set(:session_collaborator,
64
+ isoxml&.at(ns("//bibdata/ext/session/collaborator"))&.text)
59
65
  sid = isoxml&.at(ns("//bibdata/ext/session/id"))&.text
60
66
  set(:session_id, sid)
61
67
  set(:session_id_head, sid&.sub(%r{/.*$}, ""))
62
68
  set(:session_id_tail, sid&.sub(%r{^[^/]+}, ""))
63
- set(:item_footnote, isoxml&.at(ns("//bibdata/ext/session/item-footnote"))&.text)
64
- set(:session_itemnumber, multival(isoxml, "//bibdata/ext/session/item-number"))
65
- set(:session_itemname, multival(isoxml, "//bibdata/ext/session/item-name"))
66
- set(:session_subitemname, multival(isoxml, "//bibdata/ext/session/subitem-name"))
69
+ set(:item_footnote,
70
+ isoxml&.at(ns("//bibdata/ext/session/item-footnote"))&.text)
71
+ set(:session_itemnumber,
72
+ multival(isoxml, "//bibdata/ext/session/item-number"))
73
+ set(:session_itemname,
74
+ multival(isoxml, "//bibdata/ext/session/item-name"))
75
+ set(:session_subitemname,
76
+ multival(isoxml, "//bibdata/ext/session/subitem-name"))
67
77
  end
68
78
 
69
79
  def docid(isoxml, _out)
70
80
  dn = isoxml.at(ns("//bibdata/docidentifier"))&.text
71
81
  set(:docnumber, dn)
72
82
  type = isoxml&.at(ns("//bibdata/ext/doctype"))&.text
73
- set(:formatted_docnumber, type == "recommendation" ? "UN/CEFACT Recommendation #{dn}" : dn)
83
+ set(:formatted_docnumber, type == "recommendation" ?
84
+ "UN/CEFACT Recommendation #{dn}" : dn)
74
85
  end
75
86
 
76
87
  def stage_abbr(status)