metanorma-nist 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,13 +10,65 @@ module Asciidoctor
10
10
  #
11
11
  class Converter < Standoc::Converter
12
12
 
13
- def metadata_author(node, xml)
14
- xml.contributor do |c|
15
- c.role **{ type: "author" }
16
- c.organization do |a|
17
- a.name "NIST"
13
+ def title_subtitle(node, t, at)
14
+ return unless node.attr("title-sub")
15
+ t.title_sub(**attr_code(at)) do |t1|
16
+ t1 << asciidoc_sub(node.attr("title-sub"))
17
+ end
18
+ end
19
+
20
+ def title_main(node, t, at)
21
+ t.title_main **attr_code(at) do |t1|
22
+ t1 << asciidoc_sub(node.attr("title-main") || node.title)
23
+ end
24
+ end
25
+
26
+ def title(node, xml)
27
+ ["en"].each do |lang|
28
+ xml.title do |t|
29
+ at = { language: lang, format: "text/plain" }
30
+ title_main(node, t, at)
31
+ title_subtitle(node, t, at)
18
32
  end
19
33
  end
34
+ end
35
+
36
+ def metadata_id(node, xml)
37
+ did = node.attr("docidentifier")
38
+ dn = node.attr("docnumber")
39
+ if did
40
+ xml.docidentifier did, **attr_code(type: "nist")
41
+ xml.docidentifier unabbreviate(did), **attr_code(type: "nist-long")
42
+ else
43
+ metadata_id_compose(node, xml, dn)
44
+ end
45
+ xml.docnumber node.attr("docnumber")
46
+ end
47
+
48
+ def unabbreviate(did)
49
+ SERIES_ABBR.each { |k, v| did = did.sub(/^#{v} /, "#{k} ") }
50
+ SERIES.each { |k, v| did = did.sub(/^#{k} /, "#{v} ") }
51
+ did
52
+ end
53
+
54
+ def metadata_id_compose(node, xml, dn0)
55
+ return unless dn0
56
+ dn = add_id_parts(dn0, node.attr("series"), node.attr("edition"), false)
57
+ dn_long = add_id_parts(dn0, node.attr("series"), node.attr("edition"), true)
58
+ xml.docidentifier dn, **attr_code(type: "nist")
59
+ xml.docidentifier dn_long, **attr_code(type: "nist-long")
60
+ end
61
+
62
+ def add_id_parts(dn, series, edition, long)
63
+ ed_delim = "-"
64
+ series and series_name = long ? SERIES.dig(series.to_sym) :
65
+ SERIES_ABBR.dig(series.to_sym)
66
+ dn = (series_name || "NIST #{series}") + " " + dn
67
+ dn += "#{ed_delim}#{edition}" if edition
68
+ dn
69
+ end
70
+
71
+ def metadata_author(node, xml)
20
72
  personal_author(node, xml)
21
73
  end
22
74
 
@@ -29,19 +81,6 @@ module Asciidoctor
29
81
  end
30
82
  end
31
83
 
32
- def metadata_id(node, xml)
33
- docstatus = node.attr("status")
34
- dn = node.attr("docnumber")
35
- if docstatus
36
- abbr = IsoDoc::NIST::Metadata.new("en", "Latn", {}).
37
- status_abbr(docstatus)
38
- dn = "#{dn}(#{abbr})" unless abbr.empty?
39
- end
40
- dn and dn = "NIST " + dn
41
- xml.docidentifier dn, **{type: "nist"}
42
- xml.docnumber { |i| i << node.attr("docnumber") }
43
- end
44
-
45
84
  def metadata_committee(node, xml)
46
85
  xml.editorialgroup do |a|
47
86
  a.committee(node.attr("technical-committee"))
@@ -57,8 +96,11 @@ module Asciidoctor
57
96
  end
58
97
 
59
98
  def metadata_status(node, xml)
60
- status = node.attr("status") || "published"
61
- xml.status(**{ format: "plain" }) { |s| s << status }
99
+ status = node.attr("status") || "final"
100
+ xml.status do |s|
101
+ s.stage status
102
+ s.iteration node.attr("iteration") if node.attr("iteration")
103
+ end
62
104
  end
63
105
 
64
106
  def metadata_copyright(node, xml)
@@ -84,28 +126,87 @@ module Asciidoctor
84
126
  def metadata_source(node, xml)
85
127
  super
86
128
  node.attr("doc-email") && xml.uri(node.attr("doc-email"), type: "email")
129
+ node.attr("doi") && xml.uri(node.attr("doi"), type: "doi")
87
130
  end
88
131
 
89
- def title(node, xml)
90
- super
91
- subtitle(node, xml)
132
+ def metadata_series(node, xml)
133
+ series = node.attr("series")
134
+ subseries = node.attr("subseries")
135
+ series || subseries || return
136
+ series and xml.series **{ type: "main" } do |s|
137
+ s.title (SERIES.dig(series.to_sym) || series)
138
+ SERIES_ABBR.dig(series.to_sym) and s.abbreviation SERIES_ABBR.dig(series.to_sym)
139
+ end
140
+ subseries and xml.series **{ type: "secondary" } do |s|
141
+ s.title subseries.split(/-/).map{ |w| w.capitalize }.join(" ")
142
+ end
92
143
  end
93
144
 
94
- def subtitle(node, xml)
95
- return unless node.attr("subtitle")
96
- ["en"].each do |lang|
97
- at = { language: lang, format: "text/plain" }
98
- xml.subtitle **attr_code(at) do |t|
99
- t << asciidoc_sub(node.attr("subtitle"))
100
- end
145
+ def metadata_commentperiod(node, xml)
146
+ from = node.attr("comment-from") or return
147
+ to = node.attr("comment-to")
148
+ extended = node.attr("comment-extended")
149
+ xml.commentperiod do |c|
150
+ c.from from
151
+ c.to to if to
152
+ c.extended extended if extended
101
153
  end
102
154
  end
103
155
 
156
+ SERIES = {
157
+ "nist-ams": "NIST Advanced Manufacturing Series",
158
+ "building-science": "NIST Building Science Series",
159
+ "nist-fips": "NIST Federal Information Processing Standards",
160
+ "nist-gcr": "NIST Grant/Contract Reports",
161
+ "nist-hb": "NIST Handbook",
162
+ "itl-bulletin": "ITL Bulletin",
163
+ "jpcrd": "Journal of Physical and Chemical Reference Data",
164
+ "nist-jres": "NIST Journal of Research",
165
+ "letter-circular": "NIST Letter Circular",
166
+ "nist-monograph": "NIST Monograph",
167
+ "nist-ncstar": "NIST National Construction Safety Team Act Reports",
168
+ "nist-nsrds": "NIST National Standard Reference Data Series",
169
+ "nistir": "NIST Interagency/Internal Report",
170
+ "product-standards": "NIST Product Standards",
171
+ "nist-sp": "NIST Special Publication",
172
+ "nist-tn": "NIST Technical Note",
173
+ "other": "NIST Other",
174
+ "csrc-white-paper": "CSRC White Paper",
175
+ "csrc-book": "CSRC Book",
176
+ "csrc-use-case": "CSRC Use Case",
177
+ "csrc-building-block": "CSRC Building Block",
178
+ }.freeze
179
+
180
+ SERIES_ABBR = {
181
+ "nist-ams": "NIST AMS",
182
+ "building-science": "NIST Building Science Series",
183
+ "nist-fips": "NIST FIPS",
184
+ "nist-gcr": "NISTGCR",
185
+ "nist-hb": "NIST HB",
186
+ "itl-bulletin": "ITL Bulletin",
187
+ "jpcrd": "JPCRD",
188
+ "nist-jres": "NIST JRES",
189
+ "letter-circular": "NIST Letter Circular",
190
+ "nist-monograph": "NIST MN",
191
+ "nist-ncstar": "NIST NCSTAR",
192
+ "nist-nsrds": "NIST NSRDS",
193
+ "nistir": "NISTIR",
194
+ "product-standards": "NIST Product Standards",
195
+ "nist-sp": "NIST SP",
196
+ "nist-tn": "NIST TN",
197
+ "other": "NIST Other",
198
+ "csrc-white-paper": "CSRC White Paper",
199
+ "csrc-book": "CSRC Book",
200
+ "csrc-use-case": "CSRC Use Case",
201
+ "csrc-building-block": "CSRC Building Block",
202
+ }.freeze
203
+
104
204
  def metadata(node, xml)
105
205
  super
206
+ metadata_series(node, xml)
106
207
  metadata_keywords(node, xml)
208
+ metadata_commentperiod(node, xml)
107
209
  end
108
-
109
210
  end
110
211
  end
111
212
  end
@@ -18,6 +18,7 @@
18
18
  of this.
19
19
  -->
20
20
  <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
21
+ <include href="reqt.rng"/>
21
22
  <include href="biblio.rng">
22
23
  <define name="status">
23
24
  <element name="status">
@@ -22,11 +22,6 @@
22
22
  <text/>
23
23
  </element>
24
24
  </define>
25
- <define name="btitle">
26
- <element name="title">
27
- <ref name="FormattedString"/>
28
- </element>
29
- </define>
30
25
  <define name="figure">
31
26
  <element name="figure">
32
27
  <attribute name="id">
@@ -69,16 +64,10 @@
69
64
  </define>
70
65
  <define name="status">
71
66
  <element name="status">
72
- <choice>
73
- <value>proposal</value>
74
- <value>working-draft</value>
75
- <value>committee-draft</value>
76
- <value>draft-standard</value>
77
- <value>final-draft</value>
78
- <value>published</value>
79
- <value>withdrawn</value>
80
- <ref name="LocalizedString"/>
81
- </choice>
67
+ <ref name="stage"/>
68
+ <optional>
69
+ <ref name="iteration"/>
70
+ </optional>
82
71
  </element>
83
72
  </define>
84
73
  <define name="BibItemType" combine="choice">
@@ -100,6 +89,40 @@
100
89
  </oneOrMore>
101
90
  </element>
102
91
  </define>
92
+ <define name="btitle">
93
+ <element name="title">
94
+ <choice>
95
+ <ref name="FormattedString"/>
96
+ <group>
97
+ <ref name="title-main"/>
98
+ <optional>
99
+ <ref name="title-sub"/>
100
+ </optional>
101
+ </group>
102
+ </choice>
103
+ </element>
104
+ </define>
105
+ <define name="stage">
106
+ <element name="stage">
107
+ <choice>
108
+ <value>internal-draft</value>
109
+ <value>public-draft</value>
110
+ <value>final</value>
111
+ <value>retired-draft</value>
112
+ <value>withdrawn</value>
113
+ </choice>
114
+ </element>
115
+ </define>
116
+ <define name="iteration">
117
+ <element name="iteration">
118
+ <text/>
119
+ </element>
120
+ </define>
121
+ <define name="title-main">
122
+ <element name="title-main">
123
+ <ref name="FormattedString"/>
124
+ </element>
125
+ </define>
103
126
  <define name="BibData">
104
127
  <optional>
105
128
  <attribute name="type">
@@ -116,7 +139,7 @@
116
139
  <ref name="bsource"/>
117
140
  </zeroOrMore>
118
141
  <zeroOrMore>
119
- <ref name="docidentifier"/>
142
+ <ref name="nistdocidentifier"/>
120
143
  </zeroOrMore>
121
144
  <optional>
122
145
  <ref name="docnumber"/>
@@ -152,6 +175,12 @@
152
175
  <zeroOrMore>
153
176
  <ref name="docrelation"/>
154
177
  </zeroOrMore>
178
+ <optional>
179
+ <ref name="nistseries"/>
180
+ </optional>
181
+ <optional>
182
+ <ref name="nistsubseries"/>
183
+ </optional>
155
184
  <ref name="editorialgroup"/>
156
185
  <zeroOrMore>
157
186
  <ref name="ics"/>
@@ -159,6 +188,10 @@
159
188
  <optional>
160
189
  <ref name="security"/>
161
190
  </optional>
191
+ <oneOrMore>
192
+ <ref name="keyword"/>
193
+ </oneOrMore>
194
+ <ref name="commentperiod"/>
162
195
  </define>
163
196
  </include>
164
197
  <define name="committee">
@@ -172,11 +205,95 @@
172
205
  <text/>
173
206
  </element>
174
207
  </define>
208
+ <define name="title-sub">
209
+ <element name="title-sub">
210
+ <ref name="FormattedString"/>
211
+ </element>
212
+ </define>
213
+ <define name="nistdocidentifier">
214
+ <element name="docidentifier">
215
+ <attribute name="type">
216
+ <value>nist</value>
217
+ </attribute>
218
+ <text/>
219
+ </element>
220
+ </define>
175
221
  <define name="security">
176
222
  <element name="security">
177
223
  <text/>
178
224
  </element>
179
225
  </define>
226
+ <define name="nistseries">
227
+ <element name="series">
228
+ <attribute name="type">
229
+ <value>main</value>
230
+ </attribute>
231
+ <ref name="nistseriestitle"/>
232
+ <optional>
233
+ <ref name="abbreviation"/>
234
+ </optional>
235
+ </element>
236
+ </define>
237
+ <define name="nistsubseries">
238
+ <element name="series">
239
+ <attribute name="type">
240
+ <value>secondary</value>
241
+ </attribute>
242
+ <ref name="nistsubseriestitle"/>
243
+ </element>
244
+ </define>
245
+ <define name="nistseriestitle">
246
+ <element name="title">
247
+ <choice>
248
+ <value>nist-ams</value>
249
+ <value>building-science</value>
250
+ <value>nist-fips</value>
251
+ <value>nist-gcr</value>
252
+ <value>nist-hb</value>
253
+ <value>itl-bulletin</value>
254
+ <value>jpcrd</value>
255
+ <value>nist-jres</value>
256
+ <value>letter-circular</value>
257
+ <value>nist-monograph</value>
258
+ <value>nist-ncstar</value>
259
+ <value>nist-nsrds</value>
260
+ <value>nistir</value>
261
+ <value>product-stadnards</value>
262
+ <value>nist-sp</value>
263
+ <value>nist-tn</value>
264
+ <value>other</value>
265
+ <value>csrc-white-paper</value>
266
+ <value>csrc-book</value>
267
+ <value>csrc-use-case</value>
268
+ <value>csrc-building-block</value>
269
+ </choice>
270
+ </element>
271
+ </define>
272
+ <define name="nistsubseriestitle">
273
+ <element name="title">
274
+ <choice>
275
+ <value>computer-security</value>
276
+ <value>information-security</value>
277
+ </choice>
278
+ </element>
279
+ </define>
280
+ <define name="commentperiod">
281
+ <element name="commentperiod">
282
+ <element name="from">
283
+ <ref name="ISO8601Date"/>
284
+ </element>
285
+ <optional>
286
+ <element name="to">
287
+ <ref name="ISO8601Date"/>
288
+ </element>
289
+ </optional>
290
+ <optional>
291
+ <element name="extended">
292
+ <ref name="ISO8601Date"/>
293
+ </element>
294
+ </optional>
295
+ </element>
296
+ </define>
180
297
  <define name="nist-standard">
181
298
  <element name="nist-standard">
182
299
  <ref name="bibdata"/>
@@ -0,0 +1,157 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <!--
4
+ Presupposes isodoc.rnc, is included in it
5
+ include "isodoc.rnc" { }
6
+ -->
7
+ <define name="requirement">
8
+ <element name="requirement">
9
+ <ref name="RequirementType"/>
10
+ </element>
11
+ </define>
12
+ <define name="recommendation">
13
+ <element name="recommendation">
14
+ <ref name="RequirementType"/>
15
+ </element>
16
+ </define>
17
+ <define name="permission">
18
+ <element name="permission">
19
+ <ref name="RequirementType"/>
20
+ </element>
21
+ </define>
22
+ <define name="RequirementType">
23
+ <optional>
24
+ <attribute name="obligation">
25
+ <ref name="ObligationType"/>
26
+ </attribute>
27
+ </optional>
28
+ <attribute name="id">
29
+ <data type="ID"/>
30
+ </attribute>
31
+ <optional>
32
+ <attribute name="filename"/>
33
+ </optional>
34
+ <optional>
35
+ <ref name="reqtitle"/>
36
+ </optional>
37
+ <optional>
38
+ <ref name="label"/>
39
+ </optional>
40
+ <optional>
41
+ <ref name="subject"/>
42
+ </optional>
43
+ <optional>
44
+ <ref name="reqinherit"/>
45
+ </optional>
46
+ <zeroOrMore>
47
+ <ref name="classification"/>
48
+ </zeroOrMore>
49
+ <zeroOrMore>
50
+ <choice>
51
+ <ref name="measurementtarget"/>
52
+ <ref name="specification"/>
53
+ <ref name="verification"/>
54
+ <ref name="import"/>
55
+ <ref name="description"/>
56
+ </choice>
57
+ </zeroOrMore>
58
+ <optional>
59
+ <ref name="reqt_references"/>
60
+ </optional>
61
+ <zeroOrMore>
62
+ <choice>
63
+ <ref name="requirement"/>
64
+ <ref name="recommendation"/>
65
+ <ref name="permission"/>
66
+ </choice>
67
+ </zeroOrMore>
68
+ </define>
69
+ <define name="reqtitle">
70
+ <element name="title">
71
+ <ref name="FormattedString"/>
72
+ </element>
73
+ </define>
74
+ <define name="label">
75
+ <element name="label">
76
+ <text/>
77
+ </element>
78
+ </define>
79
+ <define name="subject">
80
+ <element name="subject">
81
+ <text/>
82
+ </element>
83
+ </define>
84
+ <define name="reqinherit">
85
+ <element name="subject">
86
+ <text/>
87
+ </element>
88
+ </define>
89
+ <define name="measurementtarget">
90
+ <element name="measurement-target">
91
+ <ref name="RequirementSubpart"/>
92
+ </element>
93
+ </define>
94
+ <define name="specification">
95
+ <element name="specification">
96
+ <ref name="RequirementSubpart"/>
97
+ </element>
98
+ </define>
99
+ <define name="verification">
100
+ <element name="verification">
101
+ <ref name="RequirementSubpart"/>
102
+ </element>
103
+ </define>
104
+ <define name="import">
105
+ <element name="import">
106
+ <ref name="RequirementSubpart"/>
107
+ </element>
108
+ </define>
109
+ <define name="description">
110
+ <element name="description">
111
+ <ref name="RequirementSubpart"/>
112
+ </element>
113
+ </define>
114
+ <define name="reqt_references">
115
+ <element name="references">
116
+ <oneOrMore>
117
+ <ref name="bibitem"/>
118
+ </oneOrMore>
119
+ </element>
120
+ </define>
121
+ <define name="RequirementSubpart">
122
+ <optional>
123
+ <attribute name="type"/>
124
+ </optional>
125
+ <optional>
126
+ <attribute name="exclude">
127
+ <data type="boolean"/>
128
+ </attribute>
129
+ </optional>
130
+ <oneOrMore>
131
+ <ref name="BasicBlock"/>
132
+ </oneOrMore>
133
+ </define>
134
+ <define name="ObligationType">
135
+ <choice>
136
+ <value>requirement</value>
137
+ <value>recommendation</value>
138
+ <value>permission</value>
139
+ </choice>
140
+ </define>
141
+ <define name="classification">
142
+ <element name="classification">
143
+ <ref name="classification_tag"/>
144
+ <ref name="classification_value"/>
145
+ </element>
146
+ </define>
147
+ <define name="classification_tag">
148
+ <element name="tag">
149
+ <text/>
150
+ </element>
151
+ </define>
152
+ <define name="classification_value">
153
+ <element name="value">
154
+ <text/>
155
+ </element>
156
+ </define>
157
+ </grammar>