metanorma-itu 1.1.1 → 1.2.2

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: c64bb790ac1dfa65f1a9f04584d0dd0ffd293c372df9b4812bc29501217bd1a4
4
- data.tar.gz: efe01eee56939ed68f7dd70d846f6d54f1ec71903fa7509bc2f65764c5bb37d4
3
+ metadata.gz: ca92fde1a59224dabe1a60e9972946be9f5b4ee3a0ddc0b9d18b26d2ace7b070
4
+ data.tar.gz: c6ca6f1c6aab657534d9eba98a60ffccf57eff743b3f8d99601aee2706c47996
5
5
  SHA512:
6
- metadata.gz: 6a43368112b086f151bbd595a1a48d33563d7dba21435d1a16d78e3d21f2cd7c18a7ea1b22c4e3a3bef9cdb518e3e51207179df5e49a862bf9312bda2eaad72f
7
- data.tar.gz: 57c8ef4499538f54207e74757834138aa515c2f4100ed546824f2ed44d416d9908a301afcbce1d8636e926d6b5a04d128467128ce3cc68956da58350d0622c34
6
+ metadata.gz: e465d057bb288694d8ebb48c2e123df2cbea58b9a434fe033d9e41c5077eb00a027ae6a7ecfa653f416403510bed79cc3d4df1d438af0e4aa6eca8501175bf4d
7
+ data.tar.gz: f9c3be01cb4ade45f54f4aaba89dbdd3d4a03f53fb978c2bf1bb985587f5f4000c5dbea23042bf41a3037ec82ce6da0984b85f434c5e9f0d712017f56230819e
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'isodoc/gem_tasks'
3
4
 
5
+ IsoDoc::GemTasks.install
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
8
  task :default => :spec
@@ -4,6 +4,7 @@ module Asciidoctor
4
4
  def sections_cleanup(x)
5
5
  super
6
6
  insert_missing_sections(x) unless @no_insert_missing_sections
7
+ insert_empty_clauses(x)
7
8
  end
8
9
 
9
10
  def table_cleanup(xmldoc)
@@ -22,16 +23,20 @@ module Asciidoctor
22
23
  insert_conventions(x)
23
24
  end
24
25
 
26
+ def add_id
27
+ %(id="_#{UUIDTools::UUID.random_create}")
28
+ end
29
+
25
30
  def insert_scope(x)
26
31
  x.at("./*/sections") or
27
32
  x.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
28
33
  "<sections><sentinel/></sections>"
29
34
  x.at("./*/sections/*") or x.at("./*/sections") << "<sentinel/>"
30
35
  ins = x.at("//sections").elements.first
31
- unless x.at("//sections/clause/title[text() = 'Scope']")
32
- ins.previous = "<clause><title>Scope</title><p>"\
33
- "#{@labels['clause_empty']}</p></clause>"
34
- end
36
+ x.at("//sections/clause[@type = 'scope']") or
37
+ ins.previous =
38
+ "<clause type='scope' #{add_id}><title>#{@i18n.scope}</title><p>"\
39
+ "#{@i18n.clause_empty}</p></clause>"
35
40
  x&.at("//sentinel")&.remove
36
41
  end
37
42
 
@@ -40,42 +45,52 @@ module Asciidoctor
40
45
  x.at("./*/annex[last()] | ./*/sections").next =
41
46
  "<bibliography><sentinel/></bibliography>"
42
47
  ins = x.at("//bibliography").elements.first
43
- unless x.at("//bibliography/references[@normative = 'true']")
44
- #ins.previous = "<references normative='true'><title>References</title><p>"\
45
- # "#{@labels['clause_empty']}</p></references>"
46
- ins.previous = "<references normative='true'><title>References</title>"\
47
- "</references>"
48
- end
48
+ x.at("//bibliography/references[@normative = 'true']") or
49
+ ins.previous = "<references #{add_id} normative='true'>"\
50
+ "<title>#{@i18n.normref}</title></references>"
49
51
  x&.at("//sentinel")&.remove
50
52
  end
51
53
 
52
54
  def insert_terms(x)
53
- ins = x.at("//sections/clause/title[text() = 'Scope']/..")
54
- unless x.at("//sections//terms")
55
- ins.next = "<terms><title>Definitions</title><p>"\
56
- "#{@labels['clause_empty']}</p></terms>"
57
- end
55
+ ins = x.at("//sections/clause[@type = 'scope']")
56
+ x.at("//sections//terms") or
57
+ ins.next = "<terms #{add_id}><title>#{@i18n.termsdef}</title></terms>"
58
58
  end
59
59
 
60
60
  def insert_symbols(x)
61
61
  ins = x.at("//sections/terms") ||
62
62
  x.at("//sections/clause[descendant::terms]")
63
63
  unless x.at("//sections//definitions")
64
- ins.next = "<definitions><title>Abbreviations and acronyms</title><p>"\
65
- "#{@labels['clause_empty']}</p></definitions>"
64
+ ins.next = "<definitions #{add_id}>"\
65
+ "<title>#{@i18n.symbolsabbrev}</title></definitions>"
66
66
  end
67
67
  end
68
68
 
69
69
  def insert_conventions(x)
70
70
  ins = x.at("//sections//definitions") ||
71
71
  x.at("//sections/clause[descendant::definitions]")
72
- unless x.at("//sections/clause/title[text() = 'Conventions']")
73
- ins.next = "<clause id='_#{UUIDTools::UUID.random_create}'>"\
74
- "<title>Conventions</title><p>"\
75
- "#{@labels['clause_empty']}</p></clause>"
72
+ unless x.at("//sections/clause[@type = 'conventions']")
73
+ ins.next = "<clause #{add_id} type='conventions'>"\
74
+ "<title>#{@i18n.conventions}</title><p>"\
75
+ "#{@i18n.clause_empty}</p></clause>"
76
+ end
77
+ end
78
+
79
+ def insert_empty_clauses(x)
80
+ x.xpath("//terms[not(./term)][not(.//terms)]").each do |c|
81
+ insert_empty_clauses1(c, @i18n.clause_empty)
82
+ end
83
+ x.xpath("//definitions[not(./dl)]").each do |c|
84
+ insert_empty_clauses1(c, @i18n.clause_empty)
76
85
  end
77
86
  end
78
87
 
88
+ def insert_empty_clauses1(c, text)
89
+ c.at("./p") and return
90
+ ins = c.at("./title") or return
91
+ ins.next = "<p>#{text}</p>"
92
+ end
93
+
79
94
  def cleanup(xmldoc)
80
95
  symbols_cleanup(xmldoc)
81
96
  super
@@ -94,24 +109,46 @@ module Asciidoctor
94
109
  xmldoc
95
110
  end
96
111
 
97
- def termdef_cleanup(xmldoc)
98
- xmldoc.xpath("//term/preferred").each do |p|
99
- if ["terms defined elsewhere",
100
- "terms defined in this recommendation"].include? p.text.downcase
101
- p.name = "title"
102
- p.parent.name = "terms"
103
- end
104
- end
105
- super
112
+ def termdef_boilerplate_cleanup(xmldoc)
106
113
  end
107
114
 
108
- def termdef_boilerplate_cleanup(xmldoc)
115
+ def terms_extract(div)
116
+ internal = div.at("./terms[@type = 'internal']/title")
117
+ external = div.at("./terms[@type = 'external']/title")
118
+ [internal, external]
119
+ end
120
+
121
+ def term_defs_boilerplate(div, source, term, preface, isodoc)
122
+ internal, external = terms_extract(div.parent)
123
+ internal&.next_element&.name == "term" and
124
+ internal.next = "<p>#{@i18n.internal_terms_boilerplate}</p>"
125
+ internal and internal&.next_element == nil and
126
+ internal.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
127
+ external&.next_element&.name == "term" and
128
+ external.next = "<p>#{@i18n.external_terms_boilerplate}</p>"
129
+ external and external&.next_element == nil and
130
+ external.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
131
+ !internal and !external and
132
+ %w(term terms).include? div&.next_element&.name and
133
+ div.next = "<p>#{@i18n.term_def_boilerplate}</p>"
134
+ end
135
+
136
+ def section_names_terms_cleanup(x)
137
+ super
138
+ replace_title(
139
+ x, "//terms[@type = 'internal'] | "\
140
+ "//clause[./terms[@type = 'internal']][not(./terms[@type = 'external'])]",
141
+ @i18n&.internal_termsdef)
142
+ replace_title(
143
+ x, "//terms[@type = 'external'] | "\
144
+ "//clause[./terms[@type = 'external']][not(./terms[@type = 'internal'])]",
145
+ @i18n&.external_termsdef)
109
146
  end
110
147
 
111
148
  def symbols_cleanup(xmldoc)
112
149
  sym = xmldoc.at("//definitions/title")
113
150
  sym and sym&.next_element&.name == "dl" and
114
- sym.next = "<p>#{@symbols_boilerplate}</p>"
151
+ sym.next = "<p>#{@i18n.symbols_boilerplate}</p>"
115
152
  end
116
153
 
117
154
  PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
@@ -160,13 +197,6 @@ module Asciidoctor
160
197
  biblio_reorder1(r)
161
198
  end
162
199
  end
163
-
164
- def normref_cleanup(xmldoc)
165
- super
166
- r = xmldoc.at(NORM_REF) || return
167
- title = r.at("./title") and
168
- title.content = "References"
169
- end
170
200
  end
171
201
  end
172
202
  end
@@ -39,7 +39,7 @@ module Asciidoctor
39
39
  end
40
40
 
41
41
  def doctype(node)
42
- ret = node.attr("doctype") || "recommendation"
42
+ ret = super || "recommendation"
43
43
  ret = "recommendation" if ret == "article"
44
44
  ret
45
45
  end
@@ -56,9 +56,12 @@ module Asciidoctor
56
56
  def outputs(node, ret)
57
57
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
58
58
  presentation_xml_converter(node).convert(@filename + ".xml")
59
- html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
60
- doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
61
- pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf")
59
+ html_converter(node).convert(@filename + ".presentation.xml",
60
+ nil, false, "#{@filename}.html")
61
+ doc_converter(node).convert(@filename + ".presentation.xml",
62
+ nil, false, "#{@filename}.doc")
63
+ pdf_converter(node)&.convert(@filename + ".presentation.xml",
64
+ nil, false, "#{@filename}.pdf")
62
65
  end
63
66
 
64
67
  def validate(doc)
@@ -76,56 +79,32 @@ module Asciidoctor
76
79
  when "definitions" then "terms and definitions"
77
80
  when "abbreviations and acronyms" then "symbols and abbreviated terms"
78
81
  when "references" then "normative references"
82
+ when "terms defined elsewhere" then "terms and definitions"
83
+ when "terms defined in this recommendation" then "terms and definitions"
79
84
  else
80
85
  super
81
86
  end
82
87
  end
83
88
 
84
- def term_def_title(toplevel, node)
85
- return node.title unless toplevel
86
- "Definitions"
89
+ def sectiontype(node, level = true)
90
+ ret = super
91
+ hdr = sectiontype_streamline(node&.attr("heading")&.downcase)
92
+ return nil if ret == "terms and definitions" &&
93
+ hdr != "terms and definitions" && node.level > 1
94
+ return nil if ret == "symbols and abbreviated terms" &&
95
+ hdr != "symbols and abbreviated terms" && node.level > 1
96
+ ret
87
97
  end
88
98
 
89
- def terms_extract(div)
90
- internal = nil
91
- external = nil
92
- div.parent.xpath("./terms/title").each do |t|
93
- case t&.text&.downcase
94
- when "terms defined elsewhere" then external = t
95
- when "terms defined in this recommendation" then internal = t
96
- end
99
+ def term_def_subclause_parse(attrs, xml, node)
100
+ case clausetype = sectiontype1(node)
101
+ when "terms defined in this recommendation"
102
+ term_def_parse(attrs.merge(type: "internal"), xml, node, false)
103
+ when "terms defined elsewhere"
104
+ term_def_parse(attrs.merge(type: "external"), xml, node, false)
105
+ else
106
+ super
97
107
  end
98
- [internal, external]
99
- end
100
-
101
- def term_defs_boilerplate(div, source, term, preface, isodoc)
102
- internal, external = terms_extract(div)
103
- internal&.next_element&.name == "term" and
104
- internal.next = "<p>#{@internal_terms_boilerplate}</p>"
105
- internal and internal&.next_element == nil and
106
- internal.next = "<p>#{@no_terms_boilerplate}</p>"
107
- external&.next_element&.name == "term" and
108
- external.next = "<p>#{@external_terms_boilerplate}</p>"
109
- external and external&.next_element == nil and
110
- external.next = "<p>#{@no_terms_boilerplate}</p>"
111
- !internal and !external and
112
- %w(term terms).include? div&.next_element&.name and
113
- div.next = "<p>#{@term_def_boilerplate}</p>"
114
- end
115
-
116
- def load_yaml(lang, script)
117
- y = if @i18nyaml then YAML.load_file(@i18nyaml)
118
- elsif lang == "en"
119
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
120
- else
121
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
122
- end
123
- @symbols_boilerplate = y["symbols_boilerplate"] || ""
124
- super.merge(y)
125
- end
126
-
127
- def i18n_init(lang, script)
128
- super
129
108
  end
130
109
 
131
110
  def metadata_keywords(node, xml)
@@ -135,6 +114,17 @@ module Asciidoctor
135
114
  end
136
115
  end
137
116
 
117
+ def clause_parse(attrs, xml, node)
118
+ case clausetype = sectiontype1(node)
119
+ when "conventions" then attrs = attrs.merge(type: "conventions")
120
+ when "history"
121
+ attrs[:preface] and attrs = attrs.merge(type: "history")
122
+ when "source"
123
+ attrs[:preface] and attrs = attrs.merge(type: "source")
124
+ end
125
+ super
126
+ end
127
+
138
128
  def html_extract_attributes(node)
139
129
  super.merge(hierarchical_assets: node.attr("hierarchical-object-numbering"))
140
130
  end
@@ -64,24 +64,8 @@ module Asciidoctor
64
64
  end
65
65
  end
66
66
 
67
- def metadata_author(node, xml)
68
- xml.contributor do |c|
69
- c.role **{ type: "author" }
70
- c.organization do |a|
71
- a.name "International Telecommunication Union"
72
- a.abbreviation "ITU"
73
- end
74
- end
75
- end
76
-
77
- def metadata_publisher(node, xml)
78
- xml.contributor do |c|
79
- c.role **{ type: "publisher" }
80
- c.organization do |a|
81
- a.name "International Telecommunication Union"
82
- a.abbreviation "ITU"
83
- end
84
- end
67
+ def default_publisher
68
+ "International Telecommunication Union"
85
69
  end
86
70
 
87
71
  def metadata_committee(node, xml)
@@ -149,19 +133,6 @@ module Asciidoctor
149
133
  xml.docnumber { |i| i << node.attr("docnumber") }
150
134
  end
151
135
 
152
- def metadata_copyright(node, xml)
153
- from = node.attr("copyright-year") || Date.today.year
154
- xml.copyright do |c|
155
- c.from from
156
- c.owner do |owner|
157
- owner.organization do |o|
158
- o.name "International Telecommunication Union"
159
- o.abbreviation "ITU"
160
- end
161
- end
162
- end
163
- end
164
-
165
136
  def metadata_series(node, xml)
166
137
  node.attr("series") and
167
138
  xml.series **{ type: "main" } do |s|
@@ -42,8 +42,11 @@
42
42
  </define>
43
43
  <define name="xref">
44
44
  <element name="xref">
45
+ <!-- attribute target { xsd:IDREF }, -->
45
46
  <attribute name="target">
46
- <data type="IDREF"/>
47
+ <data type="string">
48
+ <param name="pattern">\i\c*|\c+#\c+</param>
49
+ </data>
47
50
  </attribute>
48
51
  <optional>
49
52
  <attribute name="type">
@@ -922,6 +925,9 @@
922
925
  <optional>
923
926
  <attribute name="script"/>
924
927
  </optional>
928
+ <optional>
929
+ <attribute name="type"/>
930
+ </optional>
925
931
  <optional>
926
932
  <attribute name="obligation">
927
933
  <choice>
@@ -961,9 +967,6 @@
961
967
  </define>
962
968
  <define name="content-subsection">
963
969
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
970
  <ref name="Content-Section"/>
968
971
  </element>
969
972
  </define>
@@ -992,6 +995,9 @@
992
995
  </choice>
993
996
  </attribute>
994
997
  </optional>
998
+ <optional>
999
+ <attribute name="type"/>
1000
+ </optional>
995
1001
  <optional>
996
1002
  <ref name="section-title"/>
997
1003
  </optional>
@@ -1011,9 +1017,6 @@
1011
1017
  </define>
1012
1018
  <define name="clause">
1013
1019
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1020
  <ref name="Clause-Section"/>
1018
1021
  </element>
1019
1022
  </define>
@@ -1042,6 +1045,9 @@
1042
1045
  </choice>
1043
1046
  </attribute>
1044
1047
  </optional>
1048
+ <optional>
1049
+ <attribute name="type"/>
1050
+ </optional>
1045
1051
  <optional>
1046
1052
  <ref name="section-title"/>
1047
1053
  </optional>
@@ -1180,6 +1186,9 @@
1180
1186
  <optional>
1181
1187
  <attribute name="script"/>
1182
1188
  </optional>
1189
+ <optional>
1190
+ <attribute name="type"/>
1191
+ </optional>
1183
1192
  <optional>
1184
1193
  <attribute name="obligation">
1185
1194
  <choice>
@@ -12,13 +12,16 @@ module Asciidoctor
12
12
  recommendation-corrigendum recommendation-errata recommendation-annex
13
13
  focus-group implementers-guide technical-paper technical-report
14
14
  joint-itu-iso-iec).include? doctype or
15
- @log.add("Document Attributes", nil, "#{doctype} is not a recognised document type")
15
+ @log.add("Document Attributes", nil,
16
+ "#{doctype} is not a recognised document type")
16
17
  end
17
18
 
18
19
  def stage_validate(xmldoc)
19
20
  stage = xmldoc&.at("//bibdata/status/stage")&.text
20
- %w(in-force superseded in-force-prepublished withdrawn draft).include? stage or
21
- @log.add("Document Attributes", nil, "#{stage} is not a recognised status")
21
+ %w(in-force superseded in-force-prepublished withdrawn
22
+ draft).include? stage or
23
+ @log.add("Document Attributes", nil,
24
+ "#{stage} is not a recognised status")
22
25
  end
23
26
 
24
27
  def content_validate(doc)
@@ -38,7 +41,8 @@ module Asciidoctor
38
41
  xmldoc.xpath("//bibdata/series/title").each do |s|
39
42
  series = s.text.sub(/^[A-Z]: /, "")
40
43
  t.downcase.include?(series.downcase) and
41
- @log.add("Document Attributes", nil, "Title includes series name #{series}")
44
+ @log.add("Document Attributes", nil,
45
+ "Title includes series name #{series}")
42
46
  end
43
47
  end
44
48
 
@@ -56,7 +60,8 @@ module Asciidoctor
56
60
  xmldoc.xpath("//preface/*").each do |c|
57
61
  extract_text(c).split(/\.\s+/).each do |t|
58
62
  /\b(shall|must)\b/i.match(t) and
59
- @log.add("Style", c, "Requirement possibly in preface: #{t.strip}")
63
+ @log.add("Style", c,
64
+ "Requirement possibly in preface: #{t.strip}")
60
65
  end
61
66
  end
62
67
  end
@@ -86,20 +91,24 @@ module Asciidoctor
86
91
  end
87
92
 
88
93
  def approval_validate(xmldoc)
89
- s = xmldoc.at("//bibdata/ext/recommendationstatus/approvalstage") || return
94
+ s = xmldoc.at("//bibdata/ext/recommendationstatus/approvalstage") or
95
+ return
90
96
  process = s["process"]
91
97
  if process == "aap" and %w(determined in-force).include? s.text
92
- @log.add("Document Attributes", nil, "Recommendation Status #{s.text} inconsistent with AAP")
98
+ @log.add("Document Attributes", nil,
99
+ "Recommendation Status #{s.text} inconsistent with AAP")
93
100
  end
94
101
  if process == "tap" and !%w(determined in-force).include? s.text
95
- @log.add("Document Attributes", nil, "Recommendation Status #{s.text} inconsistent with TAP")
102
+ @log.add("Document Attributes", nil,
103
+ "Recommendation Status #{s.text} inconsistent with TAP")
96
104
  end
97
105
  end
98
106
 
99
107
  def itu_identifier_validate(xmldoc)
100
108
  s = xmldoc.xpath("//bibdata/docidentifier[@type = 'ITU']").each do |x|
101
109
  /^ITU-[RTF] [AD-VX-Z]\.[0-9]+$/.match(x.text) or
102
- @log.add("Style", nil, "#{x.text} does not match ITU document identifier conventions")
110
+ @log.add("Style", nil, "#{x.text} does not match ITU document "\
111
+ "identifier conventions")
103
112
  end
104
113
  end
105
114
 
@@ -121,8 +130,10 @@ module Asciidoctor
121
130
  para = t.at("./definition") || return
122
131
  term = t.at("./preferred").text
123
132
  termdef_warn(term, /^[A-Z][a-z]+/, t, term, "term is not lowercase")
124
- termdef_warn(para.text, /^[a-z]/, t, term, "term definition does not start with capital")
125
- termdef_warn(para.text, /[^.]$/, t, term, "term definition does not end with period")
133
+ termdef_warn(para.text, /^[a-z]/, t, term,
134
+ "term definition does not start with capital")
135
+ termdef_warn(para.text, /[^.]$/, t, term,
136
+ "term definition does not end with period")
126
137
  end
127
138
  end
128
139