metanorma-nist 0.2.14 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor/nist/converter.rb +1 -1
- data/lib/asciidoctor/nist/front_id.rb +1 -1
- data/lib/asciidoctor/nist/nist.rng +1 -1
- data/lib/isodoc/nist/metadata.rb +12 -119
- data/lib/isodoc/nist/metadata_id.rb +125 -0
- data/lib/isodoc/nist/render.rb +2 -144
- data/lib/isodoc/nist/render_contributors.rb +80 -0
- data/lib/isodoc/nist/render_dates.rb +66 -0
- data/lib/isodoc/nist/word_convert.rb +5 -88
- data/lib/isodoc/nist/word_convert_toc.rb +86 -0
- data/lib/metanorma/nist/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 390fa7e0d2b9f5159246cb5334ac5aa765da260f7e01305806f011e90bb0e357
|
4
|
+
data.tar.gz: 3e571e05d0a8885bf9c857fbd3a9a0f588eb114a47a1f7e2f70e1fa76dd15653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 929748797649b3913451079a7f6ea48f975eb35aa395cf7ac26077a9a662c8785e2923cf51aa3b17651323235eb14b72331f7b2c3637796b5bf203e46f51079d
|
7
|
+
data.tar.gz: 2e29269159b3938c08f7c3ea1c3db30de91a648afb2e11713ebe171823b25a91c9aeee0469f5c8e8d0eafd9b17fe066f52b2eafcaff89c9033cf682ba20148a3
|
@@ -13,7 +13,7 @@ module Asciidoctor
|
|
13
13
|
module NIST
|
14
14
|
class Converter < Standoc::Converter
|
15
15
|
XML_ROOT_TAG = "nist-standard".freeze
|
16
|
-
XML_NAMESPACE = "https://www.metanorma.
|
16
|
+
XML_NAMESPACE = "https://www.metanorma.org/ns/nist".freeze
|
17
17
|
|
18
18
|
register_for "nist"
|
19
19
|
|
@@ -58,7 +58,7 @@ module Asciidoctor
|
|
58
58
|
dn += "#{vol_delim}#{args[:vol]}" if args[:vol]
|
59
59
|
dn += "," if args[:vol] && args[:revision]
|
60
60
|
dn += "#{ed_delim}#{args[:revision]}" if args[:revision]
|
61
|
-
stage = IsoDoc::NIST::Metadata.new(nil, nil, {}).
|
61
|
+
stage = IsoDoc::NIST::Metadata.new(nil, nil, {}).status_abbr(args[:stage], args[:iter])
|
62
62
|
dn += " (#{stage})" if stage
|
63
63
|
dn += " (#{MMMddyyyy(args[:date])})" if args[:date]
|
64
64
|
dn
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<grammar ns="https://www.metanorma.
|
2
|
+
<grammar ns="https://www.metanorma.org/ns/nist" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
3
|
<!--
|
4
4
|
Currently we inherit from a namespaced grammar, isostandard. Until we inherit from isodoc,
|
5
5
|
we cannot have a new default namespace: we will end up with a grammar with two different
|
data/lib/isodoc/nist/metadata.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "isodoc"
|
2
2
|
require "twitter_cldr"
|
3
|
+
require_relative "./metadata_id.rb"
|
3
4
|
|
4
5
|
module IsoDoc
|
5
6
|
module NIST
|
@@ -7,42 +8,16 @@ module IsoDoc
|
|
7
8
|
def initialize(lang, script, labels)
|
8
9
|
super
|
9
10
|
here = File.dirname(__FILE__)
|
10
|
-
set(:logo_nist,
|
11
|
-
File.expand_path(File.join(here, "html", "logo.png")))
|
11
|
+
set(:logo_nist, File.expand_path(File.join(here, "html", "logo.png")))
|
12
12
|
set(:logo_cswp,
|
13
13
|
File.expand_path(File.join(here, "html", "logo_cswp.png")))
|
14
14
|
set(:logo_commerce,
|
15
|
-
File.expand_path(File.join(here, "html",
|
15
|
+
File.expand_path(File.join(here, "html",
|
16
|
+
"commerce-logo-color.png")))
|
16
17
|
set(:logo_commerce_word,
|
17
18
|
File.expand_path(File.join(here, "html", "deptofcommerce.png")))
|
18
19
|
end
|
19
20
|
|
20
|
-
def iter_abbr(stage, iter)
|
21
|
-
return "F" if iter&.downcase == "final" &&
|
22
|
-
%w(draft-wip draft-prelim draft-public draft-approval).include?(stage)
|
23
|
-
case stage
|
24
|
-
when "draft-wip", "draft-prelim", "dradt-internal", "draft-approval"
|
25
|
-
iter || ""
|
26
|
-
when "draft-public"
|
27
|
-
iter ||= "1"
|
28
|
-
iter == "1" ? "I" : iter
|
29
|
-
else
|
30
|
-
""
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def stage_abbr(stage, iter)
|
35
|
-
case stage
|
36
|
-
when "draft-internal" then "#{iter_abbr(stage, iter)}ID"
|
37
|
-
when "draft-wip" then "#{iter_abbr(stage, iter)}WD"
|
38
|
-
when "draft-prelim" then "#{iter_abbr(stage, iter)}PreD"
|
39
|
-
when "draft-public" then "#{iter_abbr(stage, iter)}PD"
|
40
|
-
when "draft-approval" then "#{iter_abbr(stage, iter)}AD"
|
41
|
-
else
|
42
|
-
nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
21
|
def title(ixml, out)
|
47
22
|
main = ixml&.at(ns("//bibdata/title[@type = 'main']"))&.text
|
48
23
|
set(:doctitle, main)
|
@@ -64,86 +39,8 @@ module IsoDoc
|
|
64
39
|
set(:tc, tc.text.upcase) if tc
|
65
40
|
personal_authors(ixml)
|
66
41
|
subdiv = ixml.at(ns("//bibdata/contributor[role/@type = 'publisher']/"\
|
67
|
-
"organization/subdivision"))
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def docid(ixml, _out)
|
72
|
-
docid = ixml.at(ns("//bibdata/docidentifier[@type = 'NIST']"))&.text
|
73
|
-
docid_long = ixml.at(ns("//bibdata/docidentifier"\
|
74
|
-
"[@type = 'nist-long']"))&.text
|
75
|
-
docnumber = ixml.at(ns("//bibdata/docnumber"))&.text
|
76
|
-
set(:docidentifier, docid)
|
77
|
-
set(:docidentifier_long, docid_long)
|
78
|
-
set(:docidentifier_undated, stripdate(docid))
|
79
|
-
set(:docidentifier_long_undated, stripdate(docid_long))
|
80
|
-
d = draft_prefix(ixml) and set(:draft_prefix, d)
|
81
|
-
d = iter_code(ixml) and set(:iteration_code, d)
|
82
|
-
d = iter_ordinal(ixml) and set(:iteration_ordinal, d)
|
83
|
-
set(:docnumber, docnumber)
|
84
|
-
end
|
85
|
-
|
86
|
-
def stripdate(id)
|
87
|
-
return if id.nil?
|
88
|
-
id.sub(/ \((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[^)]+\)$/,
|
89
|
-
"")
|
90
|
-
end
|
91
|
-
|
92
|
-
def draft_prefix(ixml)
|
93
|
-
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
94
|
-
return nil unless docstatus && /^draft/.match(docstatus)
|
95
|
-
iter = iter_code(ixml)
|
96
|
-
prefix = "DRAFT "
|
97
|
-
iter and prefix += "(#{iter}) "
|
98
|
-
prefix
|
99
|
-
end
|
100
|
-
|
101
|
-
def iter_code(ixml)
|
102
|
-
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
103
|
-
iter = ixml.at(ns("//bibdata/status/iteration"))&.text
|
104
|
-
stage_abbr(docstatus, iter)
|
105
|
-
end
|
106
|
-
|
107
|
-
def iter_ordinal(ixml)
|
108
|
-
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
109
|
-
iter = ixml.at(ns("//bibdata/status/iteration"))&.text
|
110
|
-
iter ||= "1" if docstatus == "draft-public"
|
111
|
-
return if iter.nil?
|
112
|
-
return "Initial" if iter == "1" && docstatus == "draft-public"
|
113
|
-
return "Final" if iter.downcase == "final"
|
114
|
-
iter.to_i.localize.to_rbnf_s("SpelloutRules", "spellout-ordinal")
|
115
|
-
end
|
116
|
-
|
117
|
-
def draftinfo(draft, revdate)
|
118
|
-
draftinfo = ""
|
119
|
-
if draft
|
120
|
-
draftinfo = " #{@labels["draft_label"]} #{draft}"
|
121
|
-
end
|
122
|
-
IsoDoc::Function::I18n::l10n(draftinfo, @lang, @script)
|
123
|
-
end
|
124
|
-
|
125
|
-
def docstatus(ixml, _out)
|
126
|
-
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
127
|
-
set(:unpublished, !/^draft/.match(docstatus).nil?)
|
128
|
-
substage = ixml.at(ns("//bibdata/status/substage"))&.text
|
129
|
-
substage and set(:substage, substage)
|
130
|
-
iter = ixml.at(ns("//bibdata/status/iteration"))&.text
|
131
|
-
set(:iteration, iter) if iter
|
132
|
-
set(:status, status_print(docstatus || "final"))
|
133
|
-
set(:errata, true) if ixml.at(ns("//errata"))
|
134
|
-
end
|
135
|
-
|
136
|
-
def status_print(status)
|
137
|
-
case status
|
138
|
-
when "draft-internal" then "Internal Draft"
|
139
|
-
when "draft-wip" then "Work-in-Progress Draft"
|
140
|
-
when "draft-prelim" then "Preliminary Draft"
|
141
|
-
when "draft-public" then "Public Draft"
|
142
|
-
when "draft-approval" then "Approval Draft"
|
143
|
-
when "final" then "Final"
|
144
|
-
when "final-review" then "Under Review"
|
145
|
-
when "final-withdrawn" then "Withdrawn"
|
146
|
-
end
|
42
|
+
"organization/subdivision")) and
|
43
|
+
set(:nist_subdiv, subdiv.text)
|
147
44
|
end
|
148
45
|
|
149
46
|
def version(ixml, _out)
|
@@ -203,14 +100,13 @@ module IsoDoc
|
|
203
100
|
end
|
204
101
|
|
205
102
|
def series(ixml, _out)
|
206
|
-
series = ixml.at(ns("//bibdata/series[@type = 'main']/title"))&.text
|
207
|
-
|
103
|
+
series = ixml.at(ns("//bibdata/series[@type = 'main']/title"))&.text and
|
104
|
+
set(:series, series)
|
208
105
|
seriesabbr =
|
209
106
|
ixml.at(ns("//bibdata/series[@type = 'main']/abbreviation"))&.text
|
210
107
|
set(:seriesabbr, seriesabbr) if seriesabbr
|
211
|
-
|
212
|
-
|
213
|
-
set(:subseries, subseries) if subseries
|
108
|
+
subs = ixml.at(ns("//bibdata/series[@type = 'secondary']/"\
|
109
|
+
"title"))&.text and set(:subseries, subs)
|
214
110
|
end
|
215
111
|
|
216
112
|
def monthyr(isodate)
|
@@ -230,9 +126,7 @@ module IsoDoc
|
|
230
126
|
|
231
127
|
def keywords(ixml, _out)
|
232
128
|
keywords = []
|
233
|
-
ixml.xpath(ns("//bibdata/keyword")).each
|
234
|
-
keywords << kw.text
|
235
|
-
end
|
129
|
+
ixml.xpath(ns("//bibdata/keyword")).each { |kw| keywords << kw.text }
|
236
130
|
set(:keywords, keywords)
|
237
131
|
end
|
238
132
|
|
@@ -296,8 +190,7 @@ module IsoDoc
|
|
296
190
|
end
|
297
191
|
|
298
192
|
def superseding_titles(ixml, d)
|
299
|
-
title = d.at(ns("./title[@type = 'main']"))&.text
|
300
|
-
if title
|
193
|
+
if title = d.at(ns("./title[@type = 'main']"))&.text
|
301
194
|
set(:superseding_title, d.at(ns("./title[@type = 'main']"))&.text)
|
302
195
|
set(:superseding_subtitle,
|
303
196
|
d.at(ns("./title[@type = 'subtitle']"))&.text)
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module NIST
|
3
|
+
class Metadata < IsoDoc::Metadata
|
4
|
+
def iter_abbr(stage, iter)
|
5
|
+
return "F" if iter&.downcase == "final" &&
|
6
|
+
%w(draft-wip draft-prelim draft-public draft-approval).include?(stage)
|
7
|
+
case stage
|
8
|
+
when "draft-wip", "draft-prelim", "dradt-internal", "draft-approval"
|
9
|
+
iter || ""
|
10
|
+
when "draft-public"
|
11
|
+
iter ||= "1"
|
12
|
+
iter == "1" ? "I" : iter
|
13
|
+
else
|
14
|
+
""
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def stage_abbr(stage)
|
19
|
+
case stage
|
20
|
+
when "draft-internal" then "ID"
|
21
|
+
when "draft-wip" then "WD"
|
22
|
+
when "draft-prelim" then "PreD"
|
23
|
+
when "draft-public" then "PD"
|
24
|
+
when "draft-approval" then "AD"
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def status_abbr(stage, iter)
|
31
|
+
case stage
|
32
|
+
when "draft-internal" then "#{iter_abbr(stage, iter)}ID"
|
33
|
+
when "draft-wip" then "#{iter_abbr(stage, iter)}WD"
|
34
|
+
when "draft-prelim" then "#{iter_abbr(stage, iter)}PreD"
|
35
|
+
when "draft-public" then "#{iter_abbr(stage, iter)}PD"
|
36
|
+
when "draft-approval" then "#{iter_abbr(stage, iter)}AD"
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def docstatus(ixml, _out)
|
43
|
+
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
44
|
+
set(:unpublished, unpublished(docstatus))
|
45
|
+
substage = ixml.at(ns("//bibdata/status/substage"))&.text
|
46
|
+
substage and set(:substage, substage)
|
47
|
+
iter = ixml.at(ns("//bibdata/status/iteration"))&.text
|
48
|
+
set(:iteration, iter) if iter
|
49
|
+
set(:status, status_print(docstatus || "final"))
|
50
|
+
set(:errata, true) if ixml.at(ns("//errata"))
|
51
|
+
unpublished(docstatus) and
|
52
|
+
set(:stageabbr, stage_abbr(docstatus))
|
53
|
+
end
|
54
|
+
|
55
|
+
def unpublished(status)
|
56
|
+
!/^draft/.match(status).nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def status_print(status)
|
60
|
+
case status
|
61
|
+
when "draft-internal" then "Internal Draft"
|
62
|
+
when "draft-wip" then "Work-in-Progress Draft"
|
63
|
+
when "draft-prelim" then "Preliminary Draft"
|
64
|
+
when "draft-public" then "Public Draft"
|
65
|
+
when "draft-approval" then "Approval Draft"
|
66
|
+
when "final" then "Final"
|
67
|
+
when "final-review" then "Under Review"
|
68
|
+
when "final-withdrawn" then "Withdrawn"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def docid(ixml, _out)
|
73
|
+
docid = ixml.at(ns("//bibdata/docidentifier[@type = 'NIST']"))&.text
|
74
|
+
docid_long = ixml.at(ns("//bibdata/docidentifier"\
|
75
|
+
"[@type = 'nist-long']"))&.text
|
76
|
+
set(:docidentifier, docid)
|
77
|
+
set(:docidentifier_long, docid_long)
|
78
|
+
set(:docidentifier_undated, stripdate(docid))
|
79
|
+
set(:docidentifier_long_undated, stripdate(docid_long))
|
80
|
+
d = draft_prefix(ixml) and set(:draft_prefix, d)
|
81
|
+
d = iter_code(ixml) and set(:iteration_code, d)
|
82
|
+
d = iter_ordinal(ixml) and set(:iteration_ordinal, d)
|
83
|
+
end
|
84
|
+
|
85
|
+
def stripdate(id)
|
86
|
+
return if id.nil?
|
87
|
+
id.sub(/ \((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[^)]+\)$/,
|
88
|
+
"")
|
89
|
+
end
|
90
|
+
|
91
|
+
def draft_prefix(ixml)
|
92
|
+
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
93
|
+
return nil unless docstatus && /^draft/.match(docstatus)
|
94
|
+
iter = iter_code(ixml)
|
95
|
+
prefix = "DRAFT "
|
96
|
+
iter and prefix += "(#{iter}) "
|
97
|
+
prefix
|
98
|
+
end
|
99
|
+
|
100
|
+
def iter_code(ixml)
|
101
|
+
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
102
|
+
iter = ixml.at(ns("//bibdata/status/iteration"))&.text
|
103
|
+
status_abbr(docstatus, iter)
|
104
|
+
end
|
105
|
+
|
106
|
+
def iter_ordinal(ixml)
|
107
|
+
docstatus = ixml.at(ns("//bibdata/status/stage"))&.text
|
108
|
+
iter = ixml.at(ns("//bibdata/status/iteration"))&.text
|
109
|
+
iter ||= "1" if docstatus == "draft-public"
|
110
|
+
return if iter.nil?
|
111
|
+
return "Initial" if iter == "1" && docstatus == "draft-public"
|
112
|
+
return "Final" if iter.downcase == "final"
|
113
|
+
iter.to_i.localize.to_rbnf_s("SpelloutRules", "spellout-ordinal")
|
114
|
+
end
|
115
|
+
|
116
|
+
def draftinfo(draft, revdate)
|
117
|
+
draftinfo = ""
|
118
|
+
if draft
|
119
|
+
draftinfo = " #{@labels["draft_label"]} #{draft}"
|
120
|
+
end
|
121
|
+
IsoDoc::Function::I18n::l10n(draftinfo, @lang, @script)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/isodoc/nist/render.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "nokogiri"
|
2
2
|
require "twitter_cldr"
|
3
|
+
require_relative "render_contributors"
|
4
|
+
require_relative "render_dates"
|
3
5
|
|
4
6
|
module Iso690Render
|
5
7
|
=begin
|
@@ -12,85 +14,6 @@ module Iso690Render
|
|
12
14
|
parse(docxml.root, embedded)
|
13
15
|
end
|
14
16
|
|
15
|
-
=begin
|
16
|
-
def self.multiplenames_and(names)
|
17
|
-
return "" if names.length == 0
|
18
|
-
return names[0] if names.length == 1
|
19
|
-
return "#{names[0]} and #{names[1]}" if names.length == 2
|
20
|
-
names[0..-2].join(", ") + " and #{names[-1]}"
|
21
|
-
end
|
22
|
-
=end
|
23
|
-
|
24
|
-
def self.multiplenames(names)
|
25
|
-
names.join(", ")
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.extract_orgname(org)
|
29
|
-
name = org.at("./name")
|
30
|
-
name&.text || "--"
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.frontname(given, initials)
|
34
|
-
if given.empty? && initials.empty? then ""
|
35
|
-
elsif initials.empty?
|
36
|
-
given.map{ |m| m.text[0] }.join("")
|
37
|
-
else
|
38
|
-
initials.map{ |m| m.text[0] }.join("")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.commajoin(a, b)
|
43
|
-
return a unless b
|
44
|
-
return b unless a
|
45
|
-
#"#{a}, #{b}"
|
46
|
-
"#{a} #{b}"
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.extract_personname(person)
|
50
|
-
completename = person.at("./name/completename")
|
51
|
-
return completename.text if completename
|
52
|
-
surname = person.at("./name/surname")
|
53
|
-
initials = person.xpath("./name/initials")
|
54
|
-
forenames = person.xpath("./name/forename")
|
55
|
-
#given = []
|
56
|
-
#forenames.each { |x| given << x.text }
|
57
|
-
#given.empty? && initials.each { |x| given << x.text }
|
58
|
-
commajoin(surname&.text, frontname(forenames, initials))
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.extractname(contributor)
|
62
|
-
org = contributor.at("./organization")
|
63
|
-
person = contributor.at("./person")
|
64
|
-
return extract_orgname(org) if org
|
65
|
-
return extract_personname(person) if person
|
66
|
-
"--"
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.contributorRole(contributors)
|
70
|
-
return "" unless contributors.length > 0
|
71
|
-
if contributors[0]&.at("role/@type")&.text == "editor"
|
72
|
-
return contributors.length > 1 ? " (Eds.)" : "(Ed.)"
|
73
|
-
end
|
74
|
-
""
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.creatornames(doc)
|
78
|
-
cr = doc.xpath("./contributor[role/@type = 'author']")
|
79
|
-
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'performer']")
|
80
|
-
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'adapter']")
|
81
|
-
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'translator']")
|
82
|
-
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'editor']")
|
83
|
-
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'publisher']")
|
84
|
-
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'distributor']")
|
85
|
-
cr.empty? and cr = doc.xpath("./contributor")
|
86
|
-
cr.empty? and return ""
|
87
|
-
ret = []
|
88
|
-
cr.each do |x|
|
89
|
-
ret << extractname(x)
|
90
|
-
end
|
91
|
-
multiplenames(ret) + contributorRole(cr)
|
92
|
-
end
|
93
|
-
|
94
17
|
def self.title(doc)
|
95
18
|
doc&.at("./title")&.text
|
96
19
|
end
|
@@ -131,34 +54,6 @@ module Iso690Render
|
|
131
54
|
ret
|
132
55
|
end
|
133
56
|
|
134
|
-
def self.date1(date)
|
135
|
-
return nil if date.nil?
|
136
|
-
on = date&.at("./on")&.text
|
137
|
-
from = date&.at("./from")&.text
|
138
|
-
to = date&.at("./to")&.text
|
139
|
-
return MMMddyyyy(on) if on
|
140
|
-
return "#{MMMddyyyy(from)}–#{MMMddyyyy(to)}" if from
|
141
|
-
nil
|
142
|
-
end
|
143
|
-
|
144
|
-
def self.date(doc)
|
145
|
-
updated = date1(doc&.at("./date[@type = 'updated']"))
|
146
|
-
pub = date1(doc&.at("./date[@type = 'issued']"))
|
147
|
-
if pub
|
148
|
-
ret = pub
|
149
|
-
ret += " (updated #{updated})" if updated
|
150
|
-
return ret
|
151
|
-
end
|
152
|
-
pub = date1(doc&.at("./date[@type = 'circulated']")) and
|
153
|
-
return pub
|
154
|
-
date1(doc&.at("./date"))
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.year(date)
|
158
|
-
return nil if date.nil?
|
159
|
-
date.sub(/^(\d\d\d\d).*$/, "\\1")
|
160
|
-
end
|
161
|
-
|
162
57
|
def self.series_title(doc)
|
163
58
|
s = doc.at("./series[@type = 'main']") ||
|
164
59
|
doc.at("./series[not(@type)]") ||
|
@@ -260,43 +155,6 @@ module Iso690Render
|
|
260
155
|
ret.join(", ")
|
261
156
|
end
|
262
157
|
|
263
|
-
=begin
|
264
|
-
def self.monthyr(isodate)
|
265
|
-
return nil if isodate.nil?
|
266
|
-
arr = isodate.split("-")
|
267
|
-
date = if arr.size == 2
|
268
|
-
DateTime.new(*arr.map(&:to_i))
|
269
|
-
else
|
270
|
-
DateTime.parse(isodate)
|
271
|
-
end
|
272
|
-
date.localize(:en).to_additional_s("yMMMM")
|
273
|
-
end
|
274
|
-
|
275
|
-
def self.mmddyyyy(isodate)
|
276
|
-
return nil if isodate.nil?
|
277
|
-
arr = isodate.split("-")
|
278
|
-
date = if arr.size == 1 and (/^\d+$/.match isodate)
|
279
|
-
Date.new(*arr.map(&:to_i)).strftime("%Y")
|
280
|
-
elsif arr.size == 2
|
281
|
-
Date.new(*arr.map(&:to_i)).strftime("%m-%Y")
|
282
|
-
else
|
283
|
-
Date.parse(isodate).strftime("%m-%d-%Y")
|
284
|
-
end
|
285
|
-
end
|
286
|
-
=end
|
287
|
-
|
288
|
-
def self.MMMddyyyy(isodate)
|
289
|
-
return nil if isodate.nil?
|
290
|
-
arr = isodate.split("-")
|
291
|
-
date = if arr.size == 1 and (/^\d+$/.match isodate)
|
292
|
-
Date.new(*arr.map(&:to_i)).strftime("%Y")
|
293
|
-
elsif arr.size == 2
|
294
|
-
Date.new(*arr.map(&:to_i)).strftime("%B %Y")
|
295
|
-
else
|
296
|
-
Date.parse(isodate).strftime("%B %d, %Y")
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
158
|
def self.draft(doc)
|
301
159
|
return nil unless is_nist(doc)
|
302
160
|
dr = doc&.at("./status/stage")&.text
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Iso690Render
|
2
|
+
=begin
|
3
|
+
def self.multiplenames_and(names)
|
4
|
+
return "" if names.length == 0
|
5
|
+
return names[0] if names.length == 1
|
6
|
+
return "#{names[0]} and #{names[1]}" if names.length == 2
|
7
|
+
names[0..-2].join(", ") + " and #{names[-1]}"
|
8
|
+
end
|
9
|
+
=end
|
10
|
+
|
11
|
+
def self.multiplenames(names)
|
12
|
+
names.join(", ")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.extract_orgname(org)
|
16
|
+
name = org.at("./name")
|
17
|
+
name&.text || "--"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.frontname(given, initials)
|
21
|
+
if given.empty? && initials.empty? then ""
|
22
|
+
elsif initials.empty?
|
23
|
+
given.map{ |m| m.text[0] }.join("")
|
24
|
+
else
|
25
|
+
initials.map{ |m| m.text[0] }.join("")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.commajoin(a, b)
|
30
|
+
return a unless b
|
31
|
+
return b unless a
|
32
|
+
#"#{a}, #{b}"
|
33
|
+
"#{a} #{b}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.extract_personname(person)
|
37
|
+
completename = person.at("./name/completename")
|
38
|
+
return completename.text if completename
|
39
|
+
surname = person.at("./name/surname")
|
40
|
+
initials = person.xpath("./name/initials")
|
41
|
+
forenames = person.xpath("./name/forename")
|
42
|
+
#given = []
|
43
|
+
#forenames.each { |x| given << x.text }
|
44
|
+
#given.empty? && initials.each { |x| given << x.text }
|
45
|
+
commajoin(surname&.text, frontname(forenames, initials))
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.extractname(contributor)
|
49
|
+
org = contributor.at("./organization")
|
50
|
+
person = contributor.at("./person")
|
51
|
+
return extract_orgname(org) if org
|
52
|
+
return extract_personname(person) if person
|
53
|
+
"--"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.contributorRole(contributors)
|
57
|
+
return "" unless contributors.length > 0
|
58
|
+
if contributors[0]&.at("role/@type")&.text == "editor"
|
59
|
+
return contributors.length > 1 ? " (Eds.)" : "(Ed.)"
|
60
|
+
end
|
61
|
+
""
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.creatornames(doc)
|
65
|
+
cr = doc.xpath("./contributor[role/@type = 'author']")
|
66
|
+
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'performer']")
|
67
|
+
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'adapter']")
|
68
|
+
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'translator']")
|
69
|
+
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'editor']")
|
70
|
+
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'publisher']")
|
71
|
+
cr.empty? and cr = doc.xpath("./contributor[role/@type = 'distributor']")
|
72
|
+
cr.empty? and cr = doc.xpath("./contributor")
|
73
|
+
cr.empty? and return ""
|
74
|
+
ret = []
|
75
|
+
cr.each do |x|
|
76
|
+
ret << extractname(x)
|
77
|
+
end
|
78
|
+
multiplenames(ret) + contributorRole(cr)
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Iso690Render
|
2
|
+
def self.date1(date)
|
3
|
+
return nil if date.nil?
|
4
|
+
on = date&.at("./on")&.text
|
5
|
+
from = date&.at("./from")&.text
|
6
|
+
to = date&.at("./to")&.text
|
7
|
+
return MMMddyyyy(on) if on
|
8
|
+
return "#{MMMddyyyy(from)}–#{MMMddyyyy(to)}" if from
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.date(doc)
|
13
|
+
updated = date1(doc&.at("./date[@type = 'updated']"))
|
14
|
+
pub = date1(doc&.at("./date[@type = 'issued']"))
|
15
|
+
if pub
|
16
|
+
ret = pub
|
17
|
+
ret += " (updated #{updated})" if updated
|
18
|
+
return ret
|
19
|
+
end
|
20
|
+
pub = date1(doc&.at("./date[@type = 'circulated']")) and
|
21
|
+
return pub
|
22
|
+
date1(doc&.at("./date"))
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.year(date)
|
26
|
+
return nil if date.nil?
|
27
|
+
date.sub(/^(\d\d\d\d).*$/, "\\1")
|
28
|
+
end
|
29
|
+
|
30
|
+
=begin
|
31
|
+
def self.monthyr(isodate)
|
32
|
+
return nil if isodate.nil?
|
33
|
+
arr = isodate.split("-")
|
34
|
+
date = if arr.size == 2
|
35
|
+
DateTime.new(*arr.map(&:to_i))
|
36
|
+
else
|
37
|
+
DateTime.parse(isodate)
|
38
|
+
end
|
39
|
+
date.localize(:en).to_additional_s("yMMMM")
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.mmddyyyy(isodate)
|
43
|
+
return nil if isodate.nil?
|
44
|
+
arr = isodate.split("-")
|
45
|
+
date = if arr.size == 1 and (/^\d+$/.match isodate)
|
46
|
+
Date.new(*arr.map(&:to_i)).strftime("%Y")
|
47
|
+
elsif arr.size == 2
|
48
|
+
Date.new(*arr.map(&:to_i)).strftime("%m-%Y")
|
49
|
+
else
|
50
|
+
Date.parse(isodate).strftime("%m-%d-%Y")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
=end
|
54
|
+
|
55
|
+
def self.MMMddyyyy(isodate)
|
56
|
+
return nil if isodate.nil?
|
57
|
+
arr = isodate.split("-")
|
58
|
+
date = if arr.size == 1 and (/^\d+$/.match isodate)
|
59
|
+
Date.new(*arr.map(&:to_i)).strftime("%Y")
|
60
|
+
elsif arr.size == 2
|
61
|
+
Date.new(*arr.map(&:to_i)).strftime("%B %Y")
|
62
|
+
else
|
63
|
+
Date.parse(isodate).strftime("%B %d, %Y")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -3,6 +3,7 @@ require_relative "metadata"
|
|
3
3
|
require "fileutils"
|
4
4
|
require "sassc"
|
5
5
|
require_relative "base_convert"
|
6
|
+
require_relative "word_convert_toc"
|
6
7
|
|
7
8
|
module IsoDoc
|
8
9
|
module NIST
|
@@ -31,25 +32,21 @@ module IsoDoc
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def default_fonts(options)
|
34
|
-
{
|
35
|
-
bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' :
|
35
|
+
{ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' :
|
36
36
|
'"Times New Roman",serif'),
|
37
37
|
headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' :
|
38
38
|
'"Arial",sans-serif'),
|
39
|
-
monospacefont: '"Courier New",monospace'
|
40
|
-
}
|
39
|
+
monospacefont: '"Courier New",monospace' }
|
41
40
|
end
|
42
41
|
|
43
42
|
def default_file_locations(_options)
|
44
|
-
{
|
45
|
-
wordstylesheet: html_doc_path("wordstyle.scss"),
|
43
|
+
{ wordstylesheet: html_doc_path("wordstyle.scss"),
|
46
44
|
standardstylesheet: html_doc_path("nist.scss"),
|
47
45
|
header: html_doc_path("header.html"),
|
48
46
|
wordcoverpage: html_doc_path("word_nist_titlepage.html"),
|
49
47
|
wordintropage: html_doc_path("word_nist_intro.html"),
|
50
48
|
ulstyle: "l3",
|
51
|
-
olstyle: "l2"
|
52
|
-
}
|
49
|
+
olstyle: "l2" }
|
53
50
|
end
|
54
51
|
|
55
52
|
def metadata_init(lang, script, labels)
|
@@ -138,86 +135,6 @@ module IsoDoc
|
|
138
135
|
word_annex_cleanup1(docxml, 6)
|
139
136
|
end
|
140
137
|
|
141
|
-
def toc_insert(docxml, level)
|
142
|
-
insertion = docxml.at("//div[h1 = 'Executive Summary']/"\
|
143
|
-
"preceding-sibling::div[h1][1]") ||
|
144
|
-
docxml.at("//div[@class = 'WordSection2']/child::*[last()]")
|
145
|
-
if docxml.at("//p[@class = 'TableTitle']")
|
146
|
-
insertion.next = make_TableWordToC(docxml)
|
147
|
-
insertion.next = %{<p class="TOCTitle">List of Tables</p>}
|
148
|
-
end
|
149
|
-
if docxml.at("//p[@class = 'FigureTitle']")
|
150
|
-
insertion.next = make_FigureWordToC(docxml)
|
151
|
-
insertion.next = %{<p class="TOCTitle">List of Figures</p>}
|
152
|
-
end
|
153
|
-
if docxml.at("//p[@class = 'h1Annex']")
|
154
|
-
insertion.next = make_AppendixWordToC(docxml)
|
155
|
-
insertion.next = %{<p class="TOCTitle">List of Appendices</p>}
|
156
|
-
end
|
157
|
-
insertion.next = make_WordToC(docxml, level)
|
158
|
-
insertion.next = %{<p class="TOCTitle" style="page-break-before:
|
159
|
-
always;">Table of Contents</p>}
|
160
|
-
docxml
|
161
|
-
end
|
162
|
-
|
163
|
-
WORD_TOC_APPENDIX_PREFACE1 = <<~TOC.freeze
|
164
|
-
<span lang="EN-GB"><span
|
165
|
-
style='mso-element:field-begin'></span><span
|
166
|
-
style='mso-spacerun:yes'> </span>TOC
|
167
|
-
\\h \\z \\t "h1Annex,1,h2Annex,2,h3Annex,3" <span
|
168
|
-
style='mso-element:field-separator'></span></span>
|
169
|
-
TOC
|
170
|
-
|
171
|
-
WORD_TOC_TABLE_PREFACE1 = <<~TOC.freeze
|
172
|
-
<span lang="EN-GB"><span
|
173
|
-
style='mso-element:field-begin'></span><span
|
174
|
-
style='mso-spacerun:yes'> </span>TOC
|
175
|
-
\\h \\z \\t "TableTitle,1" <span
|
176
|
-
style='mso-element:field-separator'></span></span>
|
177
|
-
TOC
|
178
|
-
|
179
|
-
WORD_TOC_FIGURE_PREFACE1 = <<~TOC.freeze
|
180
|
-
<span lang="EN-GB"><span
|
181
|
-
style='mso-element:field-begin'></span><span
|
182
|
-
style='mso-spacerun:yes'> </span>TOC
|
183
|
-
\\h \\z \\t "FigureTitle,1" <span
|
184
|
-
style='mso-element:field-separator'></span></span>
|
185
|
-
TOC
|
186
|
-
|
187
|
-
def header_strip(h)
|
188
|
-
h = h.to_s.gsub(/<\/?p[^>]*>/, "").
|
189
|
-
gsub(%r{<a [^>]+>[^<]+</a><aside>.*</aside>}m, "")
|
190
|
-
super
|
191
|
-
end
|
192
|
-
|
193
|
-
def make_TableWordToC(docxml)
|
194
|
-
toc = ""
|
195
|
-
docxml.xpath("//p[@class = 'TableTitle']").each do |h|
|
196
|
-
toc += word_toc_entry(1, header_strip(h))
|
197
|
-
end
|
198
|
-
toc.sub(/(<p class="MsoToc1">)/,
|
199
|
-
%{\\1#{WORD_TOC_TABLE_PREFACE1}}) + WORD_TOC_SUFFIX1
|
200
|
-
end
|
201
|
-
|
202
|
-
def make_FigureWordToC(docxml)
|
203
|
-
toc = ""
|
204
|
-
docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
|
205
|
-
toc += word_toc_entry(1, header_strip(h))
|
206
|
-
end
|
207
|
-
toc.sub(/(<p class="MsoToc1">)/,
|
208
|
-
%{\\1#{WORD_TOC_FIGURE_PREFACE1}}) + WORD_TOC_SUFFIX1
|
209
|
-
end
|
210
|
-
|
211
|
-
def make_AppendixWordToC(docxml)
|
212
|
-
toc = ""
|
213
|
-
docxml.xpath("//p[@class = 'h1Annex'] | //p[@class = 'h2Annex'] | "\
|
214
|
-
"p[@class = 'h3Annex']").each do |h|
|
215
|
-
toc += word_toc_entry(h["class"][1].to_i, header_strip(h))
|
216
|
-
end
|
217
|
-
toc.sub(/(<p class="MsoToc1">)/,
|
218
|
-
%{\\1#{WORD_TOC_APPENDIX_PREFACE1}}) + WORD_TOC_SUFFIX1
|
219
|
-
end
|
220
|
-
|
221
138
|
def word_preface_cleanup(docxml)
|
222
139
|
docxml.xpath("//h1[@class = 'AbstractTitle'] | "\
|
223
140
|
"//h1[@class = 'IntroTitle'] | "\
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module NIST
|
3
|
+
class WordConvert < IsoDoc::WordConvert
|
4
|
+
def toc_insert(docxml, level)
|
5
|
+
insertion = docxml.at("//div[h1 = 'Executive Summary']/"\
|
6
|
+
"preceding-sibling::div[h1][1]") ||
|
7
|
+
docxml.at("//div[@class = 'WordSection2']/child::*[last()]")
|
8
|
+
if docxml.at("//p[@class = 'TableTitle']")
|
9
|
+
insertion.next = make_TableWordToC(docxml)
|
10
|
+
insertion.next = %{<p class="TOCTitle">List of Tables</p>}
|
11
|
+
end
|
12
|
+
if docxml.at("//p[@class = 'FigureTitle']")
|
13
|
+
insertion.next = make_FigureWordToC(docxml)
|
14
|
+
insertion.next = %{<p class="TOCTitle">List of Figures</p>}
|
15
|
+
end
|
16
|
+
if docxml.at("//p[@class = 'h1Annex']")
|
17
|
+
insertion.next = make_AppendixWordToC(docxml)
|
18
|
+
insertion.next = %{<p class="TOCTitle">List of Appendices</p>}
|
19
|
+
end
|
20
|
+
insertion.next = make_WordToC(docxml, level)
|
21
|
+
insertion.next = %{<p class="TOCTitle" style="page-break-before:
|
22
|
+
always;">Table of Contents</p>}
|
23
|
+
docxml
|
24
|
+
end
|
25
|
+
|
26
|
+
WORD_TOC_APPENDIX_PREFACE1 = <<~TOC.freeze
|
27
|
+
<span lang="EN-GB"><span
|
28
|
+
style='mso-element:field-begin'></span><span
|
29
|
+
style='mso-spacerun:yes'> </span>TOC
|
30
|
+
\\h \\z \\t "h1Annex,1,h2Annex,2,h3Annex,3" <span
|
31
|
+
style='mso-element:field-separator'></span></span>
|
32
|
+
TOC
|
33
|
+
|
34
|
+
WORD_TOC_TABLE_PREFACE1 = <<~TOC.freeze
|
35
|
+
<span lang="EN-GB"><span
|
36
|
+
style='mso-element:field-begin'></span><span
|
37
|
+
style='mso-spacerun:yes'> </span>TOC
|
38
|
+
\\h \\z \\t "TableTitle,1" <span
|
39
|
+
style='mso-element:field-separator'></span></span>
|
40
|
+
TOC
|
41
|
+
|
42
|
+
WORD_TOC_FIGURE_PREFACE1 = <<~TOC.freeze
|
43
|
+
<span lang="EN-GB"><span
|
44
|
+
style='mso-element:field-begin'></span><span
|
45
|
+
style='mso-spacerun:yes'> </span>TOC
|
46
|
+
\\h \\z \\t "FigureTitle,1" <span
|
47
|
+
style='mso-element:field-separator'></span></span>
|
48
|
+
TOC
|
49
|
+
|
50
|
+
def header_strip(h)
|
51
|
+
h = h.to_s.gsub(/<\/?p[^>]*>/, "").
|
52
|
+
gsub(%r{<a [^>]+>[^<]+</a><aside>.*</aside>}m, "")
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
def make_TableWordToC(docxml)
|
57
|
+
toc = ""
|
58
|
+
docxml.xpath("//p[@class = 'TableTitle']").each do |h|
|
59
|
+
toc += word_toc_entry(1, header_strip(h))
|
60
|
+
end
|
61
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
62
|
+
%{\\1#{WORD_TOC_TABLE_PREFACE1}}) + WORD_TOC_SUFFIX1
|
63
|
+
end
|
64
|
+
|
65
|
+
def make_FigureWordToC(docxml)
|
66
|
+
toc = ""
|
67
|
+
docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
|
68
|
+
toc += word_toc_entry(1, header_strip(h))
|
69
|
+
end
|
70
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
71
|
+
%{\\1#{WORD_TOC_FIGURE_PREFACE1}}) + WORD_TOC_SUFFIX1
|
72
|
+
end
|
73
|
+
|
74
|
+
def make_AppendixWordToC(docxml)
|
75
|
+
toc = ""
|
76
|
+
docxml.xpath("//p[@class = 'h1Annex'] | //p[@class = 'h2Annex'] | "\
|
77
|
+
"p[@class = 'h3Annex']").each do |h|
|
78
|
+
toc += word_toc_entry(h["class"][1].to_i, header_strip(h))
|
79
|
+
end
|
80
|
+
toc.sub(/(<p class="MsoToc1">)/,
|
81
|
+
%{\\1#{WORD_TOC_APPENDIX_PREFACE1}}) + WORD_TOC_SUFFIX1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma-nist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -294,10 +294,14 @@ files:
|
|
294
294
|
- lib/isodoc/nist/html_convert.rb
|
295
295
|
- lib/isodoc/nist/i18n-en.yaml
|
296
296
|
- lib/isodoc/nist/metadata.rb
|
297
|
+
- lib/isodoc/nist/metadata_id.rb
|
297
298
|
- lib/isodoc/nist/pdf_convert.rb
|
298
299
|
- lib/isodoc/nist/refs.rb
|
299
300
|
- lib/isodoc/nist/render.rb
|
301
|
+
- lib/isodoc/nist/render_contributors.rb
|
302
|
+
- lib/isodoc/nist/render_dates.rb
|
300
303
|
- lib/isodoc/nist/word_convert.rb
|
304
|
+
- lib/isodoc/nist/word_convert_toc.rb
|
301
305
|
- lib/isodoc/nist/xrefs.rb
|
302
306
|
- lib/metanorma-nist.rb
|
303
307
|
- lib/metanorma/nist.rb
|