metanorma-nist 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +163 -18
- data/lib/asciidoctor/nist/biblio.rng +3 -0
- data/lib/asciidoctor/nist/boilerplate.rb +53 -3
- data/lib/asciidoctor/nist/cleanup.rb +41 -1
- data/lib/asciidoctor/nist/converter.rb +5 -6
- data/lib/asciidoctor/nist/front.rb +124 -63
- data/lib/asciidoctor/nist/isodoc.rng +38 -8
- data/lib/asciidoctor/nist/isostandard.rng +0 -8
- data/lib/asciidoctor/nist/nist.rng +145 -34
- data/lib/asciidoctor/nist/nist_intro.xml +6 -4
- data/lib/isodoc/nist/base_convert.rb +434 -0
- data/lib/isodoc/nist/html/header.html +30 -26
- data/lib/isodoc/nist/html/html_nist_titlepage.html +7 -3
- data/lib/isodoc/nist/html/word_nist_titlepage.html +1219 -155
- data/lib/isodoc/nist/html_convert.rb +7 -411
- data/lib/isodoc/nist/i18n-en.yaml +6 -1
- data/lib/isodoc/nist/metadata.rb +132 -20
- data/lib/isodoc/nist/pdf_convert.rb +19 -426
- data/lib/isodoc/nist/word_convert.rb +9 -442
- data/lib/metanorma/nist/version.rb +1 -1
- data/metanorma-nist.gemspec +1 -0
- metadata +17 -2
@@ -1,6 +1,7 @@
|
|
1
1
|
require "isodoc"
|
2
2
|
require_relative "metadata"
|
3
3
|
require "fileutils"
|
4
|
+
require_relative "base_convert"
|
4
5
|
|
5
6
|
module IsoDoc
|
6
7
|
module NIST
|
@@ -112,83 +113,17 @@ module IsoDoc
|
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
115
|
-
# common from here on
|
116
|
-
|
117
|
-
def abstract(isoxml, out)
|
118
|
-
f = isoxml.at(ns("//preface/abstract")) || return
|
119
|
-
page_break(out)
|
120
|
-
out.div **attr_code(id: f["id"]) do |s|
|
121
|
-
clause_name(nil, @abstract_lbl, s, class: "AbstractTitle")
|
122
|
-
f.elements.each { |e| parse(e, s) unless e.name == "title" }
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
116
|
def keywords(_docxml, out)
|
127
117
|
kw = @meta.get[:keywords]
|
128
118
|
kw.empty? and return
|
129
119
|
out.div **{ class: "Section3" } do |div|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
FRONT_CLAUSE = "//*[parent::preface][not(local-name() = 'abstract')]".freeze
|
136
|
-
|
137
|
-
def preface(isoxml, out)
|
138
|
-
isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
|
139
|
-
foreword(isoxml, out) and next if c.name == "foreword"
|
140
|
-
authority_parse(c, out) and next if c.name == "authority"
|
141
|
-
next if skip_render(c, isoxml)
|
142
|
-
out.div **attr_code(id: c["id"]) do |s|
|
143
|
-
clause_name(get_anchors[c['id']][:label],
|
144
|
-
c&.at(ns("./title"))&.content, s, nil)
|
145
|
-
c.elements.reject { |c1| c1.name == "title" }.each do |c1|
|
146
|
-
parse(c1, s)
|
147
|
-
end
|
120
|
+
out.div do |div|
|
121
|
+
clause_name(nil, "Keywords", div, class: "IntroTitle")
|
122
|
+
div.p kw.sort.join("; ")
|
148
123
|
end
|
149
124
|
end
|
150
125
|
end
|
151
126
|
|
152
|
-
def skip_render(c, isoxml)
|
153
|
-
return false unless c.name == "reviewernote"
|
154
|
-
status = isoxml&.at(ns("//bibdata/status/stage"))&.text
|
155
|
-
return true if status.nil?
|
156
|
-
/^final/.match status
|
157
|
-
end
|
158
|
-
|
159
|
-
def term_defs_boilerplate(div, source, term, preface)
|
160
|
-
if source.empty? && term.nil?
|
161
|
-
div << @no_terms_boilerplate
|
162
|
-
else
|
163
|
-
div << term_defs_boilerplate_cont(source, term)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def i18n_init(lang, script)
|
168
|
-
super
|
169
|
-
end
|
170
|
-
|
171
|
-
def fileloc(loc)
|
172
|
-
File.join(File.dirname(__FILE__), loc)
|
173
|
-
end
|
174
|
-
|
175
|
-
def requirement_cleanup(docxml)
|
176
|
-
docxml.xpath("//div[@class = 'recommend' or @class = 'require' "\
|
177
|
-
"or @class = 'permission'][title]").each do |d|
|
178
|
-
title = d.at("./title")
|
179
|
-
title.name = "b"
|
180
|
-
n = title.next_element
|
181
|
-
n&.children&.first&.add_previous_sibling(" ")
|
182
|
-
n&.children&.first&.add_previous_sibling(title.remove)
|
183
|
-
end
|
184
|
-
docxml
|
185
|
-
end
|
186
|
-
|
187
|
-
def figure_parse(node, out)
|
188
|
-
return pseudocode_parse(node, out) if node["type"] == "pseudocode"
|
189
|
-
super
|
190
|
-
end
|
191
|
-
|
192
127
|
def pseudocode_parse(node, out)
|
193
128
|
@in_figure = true
|
194
129
|
name = node.at(ns("./name"))
|
@@ -201,335 +136,6 @@ module IsoDoc
|
|
201
136
|
@in_figure = false
|
202
137
|
end
|
203
138
|
|
204
|
-
def dl_parse(node, out)
|
205
|
-
return glossary_parse(node, out) if node["type"] == "glossary"
|
206
|
-
super
|
207
|
-
end
|
208
|
-
|
209
|
-
def glossary_parse(node, out)
|
210
|
-
out.dl **attr_code(id: node["id"], class: "glossary") do |v|
|
211
|
-
node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
|
212
|
-
v.dt **attr_code(id: dt["id"]) do |term|
|
213
|
-
dt_parse(dt, term)
|
214
|
-
end
|
215
|
-
v.dd **attr_code(id: dd["id"]) do |listitem|
|
216
|
-
dd.children.each { |n| parse(n, listitem) }
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, out) }
|
221
|
-
end
|
222
|
-
|
223
|
-
def error_parse(node, out)
|
224
|
-
case node.name
|
225
|
-
when "nistvariable" then nistvariable_parse(node, out)
|
226
|
-
when "recommendation" then recommendation_parse(node, out)
|
227
|
-
when "requirement" then requirement_parse(node, out)
|
228
|
-
when "permission" then permission_parse(node, out)
|
229
|
-
when "errata" then errata_parse(node, out)
|
230
|
-
when "authority" then authority_parse(node, out)
|
231
|
-
when "authority1" then authority1_parse(node, out, "authority1")
|
232
|
-
when "authority2" then authority1_parse(node, out, "authority2")
|
233
|
-
when "authority3" then authority1_parse(node, out, "authority3")
|
234
|
-
when "authority4" then authority1_parse(node, out, "authority4")
|
235
|
-
when "authority5" then authority1_parse(node, out, "authority5")
|
236
|
-
else
|
237
|
-
super
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
def authority_parse(node, out)
|
242
|
-
out.div **{class: "authority"} do |s|
|
243
|
-
node.children.each do |n|
|
244
|
-
if n.name == "title"
|
245
|
-
s.h1 do |h|
|
246
|
-
n.children.each { |nn| parse(nn, h) }
|
247
|
-
end
|
248
|
-
else
|
249
|
-
parse(n, s)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
def authority1_parse(node, out, classname)
|
256
|
-
out.div **{class: classname} do |s|
|
257
|
-
node.children.each do |n|
|
258
|
-
if n.name == "title"
|
259
|
-
s.h2 do |h|
|
260
|
-
n.children.each { |nn| parse(nn, h) }
|
261
|
-
end
|
262
|
-
else
|
263
|
-
parse(n, s)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
def nistvariable_parse(node, out)
|
270
|
-
out.span **{class: "nistvariable"} do |s|
|
271
|
-
node.children.each { |n| parse(n, s) }
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
def recommendation_parse(node, out)
|
276
|
-
name = node["type"]
|
277
|
-
out.div **{ class: "recommend" } do |t|
|
278
|
-
t.title { |b| b << "Recommendation #{get_anchors[node['id']][:label]}:" }
|
279
|
-
node.children.each do |n|
|
280
|
-
parse(n, t)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def requirement_parse(node, out)
|
286
|
-
name = node["type"]
|
287
|
-
out.div **{ class: "require" } do |t|
|
288
|
-
t.title { |b| b << "Requirement #{get_anchors[node['id']][:label]}:" }
|
289
|
-
node.children.each do |n|
|
290
|
-
parse(n, t)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def permission_parse(node, out)
|
296
|
-
name = node["type"]
|
297
|
-
out.div **{ class: "permission" } do |t|
|
298
|
-
t.title { |b| b << "Permission #{get_anchors[node['id']][:label]}:" }
|
299
|
-
node.children.each do |n|
|
300
|
-
parse(n, t)
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def errata_parse(node, out)
|
306
|
-
out.table **make_table_attr(node) do |t|
|
307
|
-
t.thead do |h|
|
308
|
-
h.tr do |tr|
|
309
|
-
%w(Date Type Change Pages).each do |hdr|
|
310
|
-
tr.th hdr
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
t.tbody do |b|
|
315
|
-
node.xpath(ns("./row")).each do |row|
|
316
|
-
b.tr do |tr|
|
317
|
-
tr.td do |td|
|
318
|
-
row&.at(ns("./date"))&.children.each do |n|
|
319
|
-
parse(n, td)
|
320
|
-
end
|
321
|
-
end
|
322
|
-
tr.td do |td|
|
323
|
-
row&.at(ns("./type"))&.children.each do |n|
|
324
|
-
parse(n, td)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
tr.td do |td|
|
328
|
-
row&.at(ns("./change"))&.children.each do |n|
|
329
|
-
parse(n, td)
|
330
|
-
end
|
331
|
-
end
|
332
|
-
tr.td do |td|
|
333
|
-
row&.at(ns("./pages"))&.children.each do |n|
|
334
|
-
parse(n, td)
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
MIDDLE_CLAUSE = "//clause[parent::sections] | "\
|
344
|
-
"//terms[parent::sections]".freeze
|
345
|
-
|
346
|
-
def middle(isoxml, out)
|
347
|
-
middle_title(out)
|
348
|
-
clause isoxml, out
|
349
|
-
bibliography isoxml, out
|
350
|
-
annex isoxml, out
|
351
|
-
end
|
352
|
-
|
353
|
-
def info(isoxml, out)
|
354
|
-
@meta.keywords isoxml, out
|
355
|
-
@meta.series isoxml, out
|
356
|
-
@meta.commentperiod isoxml, out
|
357
|
-
@meta.commentperiod isoxml, out
|
358
|
-
super
|
359
|
-
end
|
360
|
-
|
361
|
-
SECTIONS_XPATH =
|
362
|
-
"//foreword | //introduction | //reviewnote | //execsummary | //annex | "\
|
363
|
-
"//sections/clause | //bibliography/references | "\
|
364
|
-
"//bibliography/clause".freeze
|
365
|
-
|
366
|
-
def initial_anchor_names(d)
|
367
|
-
d.xpath("//xmlns:preface/child::*").each do |c|
|
368
|
-
preface_names(c)
|
369
|
-
end
|
370
|
-
sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
|
371
|
-
clause_names(d, 0)
|
372
|
-
middle_section_asset_names(d)
|
373
|
-
termnote_anchor_names(d)
|
374
|
-
termexample_anchor_names(d)
|
375
|
-
end
|
376
|
-
|
377
|
-
def back_anchor_names(docxml)
|
378
|
-
docxml.xpath(ns("//annex")).each_with_index do |c, i|
|
379
|
-
annex_names(c, (65 + i).chr.to_s)
|
380
|
-
end
|
381
|
-
docxml.xpath(ns("//bibliography/clause | "\
|
382
|
-
"//bibliography/references")).each do |b|
|
383
|
-
preface_names(b)
|
384
|
-
end
|
385
|
-
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
386
|
-
reference_names(ref)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
def middle_section_asset_names(d)
|
391
|
-
middle_sections =
|
392
|
-
"//xmlns:preface/child::* | //xmlns:sections/child::*"
|
393
|
-
sequential_asset_names(d.xpath(middle_sections))
|
394
|
-
end
|
395
|
-
|
396
|
-
def sequential_asset_names(clause)
|
397
|
-
super
|
398
|
-
sequential_permission_names(clause)
|
399
|
-
sequential_requirement_names(clause)
|
400
|
-
sequential_recommendation_names(clause)
|
401
|
-
end
|
402
|
-
|
403
|
-
def sequential_permission_names(clause)
|
404
|
-
clause.xpath(ns(".//permission")).each_with_index do |t, i|
|
405
|
-
next if t["id"].nil? || t["id"].empty?
|
406
|
-
@anchors[t["id"]] = anchor_struct(i + 1, t, "Permission", "permission")
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
def sequential_requirement_names(clause)
|
411
|
-
clause.xpath(ns(".//requirement")).each_with_index do |t, i|
|
412
|
-
next if t["id"].nil? || t["id"].empty?
|
413
|
-
@anchors[t["id"]] = anchor_struct(i + 1, t, "Requirement", "requirement")
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
def sequential_recommendation_names(clause)
|
418
|
-
clause.xpath(ns(".//recommendation")).each_with_index do |t, i|
|
419
|
-
next if t["id"].nil? || t["id"].empty?
|
420
|
-
@anchors[t["id"]] = anchor_struct(i + 1, t, "Recommendation", "recommendation")
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
|
425
|
-
def hierarchical_asset_names(clause, num)
|
426
|
-
super
|
427
|
-
hierarchical_permission_names(clause, num)
|
428
|
-
hierarchical_requirement_names(clause, num)
|
429
|
-
hierarchical_recommendation_names(clause, num)
|
430
|
-
end
|
431
|
-
|
432
|
-
def hierarchical_permission_names(clause, num)
|
433
|
-
clause.xpath(ns(".//permission")).each_with_index do |t, i|
|
434
|
-
next if t["id"].nil? || t["id"].empty?
|
435
|
-
@anchors[t["id"]] = anchor_struct("#{num}.#{i + 1}",
|
436
|
-
t, "Permission", "permission")
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
def hierarchical_requirement_names(clause, num)
|
441
|
-
clause.xpath(ns(".//requirement")).each_with_index do |t, i|
|
442
|
-
next if t["id"].nil? || t["id"].empty?
|
443
|
-
@anchors[t["id"]] = anchor_struct("#{num}.#{i + 1}",
|
444
|
-
t, "Requirement", "requirement")
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
def hierarchical_recommendation_names(clause, num)
|
449
|
-
clause.xpath(ns(".//recommendation")).each_with_index do |t, i|
|
450
|
-
next if t["id"].nil? || t["id"].empty?
|
451
|
-
@anchors[t["id"]] = anchor_struct("#{num}.#{i + 1}",
|
452
|
-
t, "Recommendation", "recommendation")
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
def clause_names(docxml, sect_num)
|
457
|
-
q = "//xmlns:sections/child::*"
|
458
|
-
docxml.xpath(q).each_with_index do |c, i|
|
459
|
-
section_names(c, (i + sect_num), 1)
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
def get_linkend(node)
|
464
|
-
link = anchor_linkend(node, docid_l10n(node["target"] || "[#{node['citeas']}]"))
|
465
|
-
link += eref_localities(node.xpath(ns("./locality")), link)
|
466
|
-
contents = node.children.select { |c| c.name != "locality" }
|
467
|
-
return link if contents.nil? || contents.empty?
|
468
|
-
Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
|
469
|
-
# so not <origin bibitemid="ISO7301" citeas="ISO 7301">
|
470
|
-
# <locality type="section"><reference>3.1</reference></locality></origin>
|
471
|
-
end
|
472
|
-
|
473
|
-
def load_yaml(lang, script)
|
474
|
-
y = if @i18nyaml then YAML.load_file(@i18nyaml)
|
475
|
-
elsif lang == "en"
|
476
|
-
YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
|
477
|
-
else
|
478
|
-
YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
|
479
|
-
end
|
480
|
-
super.merge(y)
|
481
|
-
end
|
482
|
-
|
483
|
-
def annex_name_lbl(clause, num)
|
484
|
-
l10n("<b>#{@annex_lbl} #{num}</b>")
|
485
|
-
end
|
486
|
-
|
487
|
-
def annex_name(annex, name, div)
|
488
|
-
div.h1 **{ class: "Annex" } do |t|
|
489
|
-
t << "#{get_anchors[annex['id']][:label]} — "
|
490
|
-
t.b do |b|
|
491
|
-
if @bibliographycount == 1 && annex.at(ns("./references"))
|
492
|
-
b << "References"
|
493
|
-
else
|
494
|
-
name&.children&.each { |c2| parse(c2, b) }
|
495
|
-
end
|
496
|
-
end
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
def hiersep
|
501
|
-
"-"
|
502
|
-
end
|
503
|
-
|
504
|
-
def annex_names(clause, num)
|
505
|
-
@anchors[clause["id"]] = { label: annex_name_lbl(clause, num), type: "clause",
|
506
|
-
xref: "#{@annex_lbl} #{num}", level: 1 }
|
507
|
-
clause.xpath(ns("./clause | ./terms | ./term | ./references")).each_with_index do |c, i|
|
508
|
-
annex_names1(c, "#{num}.#{i + 1}", 2)
|
509
|
-
end
|
510
|
-
hierarchical_asset_names(clause, num)
|
511
|
-
end
|
512
|
-
|
513
|
-
def annex_names1(clause, num, level)
|
514
|
-
@anchors[clause["id"]] = { label: num, xref: "#{@annex_lbl} #{num}",
|
515
|
-
level: level, type: "clause" }
|
516
|
-
clause.xpath(ns("./clause | ./terms | ./term | ./references")).each_with_index do |c, i|
|
517
|
-
annex_names1(c, "#{num}.#{i + 1}", level + 1)
|
518
|
-
end
|
519
|
-
end
|
520
|
-
|
521
|
-
def terms_parse(node, out)
|
522
|
-
out.div **attr_code(id: node["id"]) do |div|
|
523
|
-
node.at(ns("./title")) and
|
524
|
-
clause_parse_title(node, div, node.at(ns("./title")), out)
|
525
|
-
term_defs_boilerplate(div, node.xpath(ns(".//termdocsource")),
|
526
|
-
node.at(ns(".//term")), node.at(ns("./p")))
|
527
|
-
node.elements.each do |e|
|
528
|
-
parse(e, div) unless %w{title source}.include? e.name
|
529
|
-
end
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
139
|
def termdef_parse(node, out)
|
534
140
|
pref = node.at(ns("./preferred"))
|
535
141
|
out.dl **{ class: "terms_dl" } do |dl|
|
@@ -544,26 +150,16 @@ module IsoDoc
|
|
544
150
|
end
|
545
151
|
|
546
152
|
def term_cleanup(docxml)
|
547
|
-
docxml.xpath("//
|
153
|
+
docxml.xpath("//table[@class = 'terms_dl']").each do |d|
|
548
154
|
prev = d.previous_element
|
549
|
-
next unless prev.name == "
|
155
|
+
next unless prev.name == "table" and prev["class"] == "terms_dl"
|
550
156
|
d.children.each { |n| prev.add_child(n.remove) }
|
551
157
|
d.remove
|
552
158
|
end
|
553
159
|
docxml
|
554
160
|
end
|
555
161
|
|
556
|
-
|
557
|
-
title = node&.at(ns("./title"))&.text || ""
|
558
|
-
out.div do |div|
|
559
|
-
node.parent.name == "annex" or
|
560
|
-
div.h2 title, **{ class: "Section3" }
|
561
|
-
node.elements.reject do |e|
|
562
|
-
["reference", "title", "bibitem"].include? e.name
|
563
|
-
end.each { |e| parse(e, div) }
|
564
|
-
biblio_list(node, div, true)
|
565
|
-
end
|
566
|
-
end
|
162
|
+
include BaseConvert
|
567
163
|
end
|
568
164
|
end
|
569
165
|
end
|