metanorma-nist 1.2.9 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,10 +22,8 @@ module IsoDoc
22
22
  def get_linkend(node)
23
23
  contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
24
24
  return unless contents.empty?
25
- link = anchor_linkend(node, docid_l10n(node["target"] ||
26
- wrap_brackets(node['citeas'])))
27
- link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
28
- link)
25
+ link = anchor_linkend(node, docid_l10n(node["target"] || wrap_brackets(node['citeas'])))
26
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link)
29
27
  non_locality_elems(node).each { |n| n.remove }
30
28
  node.add_child(link)
31
29
  end
@@ -57,15 +55,12 @@ module IsoDoc
57
55
  elsif foreword = docxml.at(ns("//preface/foreword"))
58
56
  foreword.next = keyword_clause(kw)
59
57
  else
60
- preface_init_insert_pt(docxml)&.children&.first&.
61
- add_previous_sibling(keyword_clause(kw))
58
+ preface_init_insert_pt(docxml)&.children&.first&.add_previous_sibling(keyword_clause(kw))
62
59
  end
63
60
  end
64
61
 
65
62
  def preface_init_insert_pt(docxml)
66
- docxml.at(ns("//preface")) ||
67
- docxml.at(ns("//sections")).
68
- add_previous_sibling("<preface> </preface>").first
63
+ docxml.at(ns("//preface")) || docxml.at(ns("//sections")).add_previous_sibling("<preface> </preface>").first
69
64
  end
70
65
 
71
66
  def clause1(f)
@@ -73,8 +68,33 @@ module IsoDoc
73
68
  super
74
69
  end
75
70
 
71
+ def references(docxml)
72
+ docxml.xpath(ns("//references/bibitem")).each do |x|
73
+ bibitem(x)
74
+ end
75
+ @xrefs.parse docxml
76
+ end
77
+
78
+ def bracket_if_num(x)
79
+ return nil if x.nil?
80
+ x = x.text.sub(/^\[/, "").sub(/\]$/, "")
81
+ "[#{x}]"
82
+ end
83
+
84
+ def bibitem(x)
85
+ if f = x.at(ns("./formattedref"))
86
+ code = render_identifier(bibitem_ref_code(x))
87
+ f << " [#{code[1]}] " if code[1]
88
+ else
89
+ x.children = ::Iso690Render.render(x.to_xml)
90
+ end
91
+ if id = x.at(ns("./docidentifier[@type = 'metanorma']"))
92
+ id["display"] = "true"
93
+ id.children = bracket_if_num(id)
94
+ end
95
+ end
96
+
76
97
  include Init
77
98
  end
78
99
  end
79
100
  end
80
-
@@ -8,11 +8,7 @@ module IsoDoc
8
8
  # we are taking the ref number/code out as prefix to reference
9
9
  def nonstd_bibitem(list, b, ordinal, bibliography)
10
10
  list.p **attr_code(iso_bibitem_entry_attrs(b, bibliography)) do |r|
11
- if !b.at(ns("./formattedref"))
12
- nist_reference_format(b, r)
13
- else
14
11
  reference_format(b, r)
15
- end
16
12
  end
17
13
  end
18
14
 
@@ -21,13 +17,11 @@ module IsoDoc
21
17
  end
22
18
 
23
19
  def reference_format(b, r)
24
- code = render_identifier(bibitem_ref_code(b))
25
- if code[0]
26
- r << "#{code[0]} "
20
+ if code = b.at(ns("./docidentifier[@display = 'true']"))
21
+ r << code.text
27
22
  insert_tab(r, 1)
28
23
  end
29
24
  reference_format1(b, r)
30
- r << " [#{code[1]}] " if code[1]
31
25
  end
32
26
 
33
27
  def reference_format1(b, r)
@@ -52,22 +46,12 @@ module IsoDoc
52
46
  super || prefix == "NIST"
53
47
  end
54
48
 
55
- def nist_reference_format(b, r)
56
- code = render_identifier(bibitem_ref_code(b))
57
- if code[0]
58
- r << "#{code[0]} "
59
- insert_tab(r, 1)
60
- end
61
- bibitem = b.dup.to_xml
62
- r.parent.add_child ::Iso690Render.render(bibitem, true)
63
- end
64
-
65
49
  def bibliography_parse(node, out)
66
50
  return if node["hidden"] == "true"
67
51
  title = node&.at(ns("./title"))&.text || ""
68
52
  out.div do |div|
69
53
  unless suppress_biblio_title(node)
70
- clause_parse_title(node, div, node.at(ns("./title")), out)
54
+ clause_parse_title(node, div, node.at(ns("./title")), out)
71
55
  end
72
56
  biblio_list(node, div, true)
73
57
  end
@@ -80,7 +64,7 @@ module IsoDoc
80
64
  next if f["hidden"] == "true"
81
65
  out.div do |div|
82
66
  div.h1 **{ class: "Section3" } do |h1|
83
- f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
67
+ f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
84
68
  end
85
69
  biblio_list(f, div, false)
86
70
  end
@@ -18,6 +18,10 @@ module Iso690Render
18
18
  doc&.at("./medium")&.text
19
19
  end
20
20
 
21
+ def self.blank?(x)
22
+ x.nil? || x.empty?
23
+ end
24
+
21
25
  =begin
22
26
  def self.edition(doc)
23
27
  x = doc.at("./edition")
@@ -51,19 +55,14 @@ module Iso690Render
51
55
  end
52
56
 
53
57
  def self.series_title(doc)
54
- s = doc.at("./series[@type = 'main']") ||
55
- doc.at("./series[not(@type)]") ||
56
- doc.at("./series")
58
+ s = doc.at("./series[@type = 'main']") || doc.at("./series[not(@type)]") || doc.at("./series")
57
59
  s&.at("./title")&.text
58
60
  end
59
61
 
60
62
  def self.series(doc, type)
61
- s = doc.at("./series[@type = 'main']") ||
62
- doc.at("./series[not(@type)]") ||
63
- doc.at("./series")
63
+ s = doc.at("./series[@type = 'main']") || doc.at("./series[not(@type)]") || doc.at("./series")
64
64
  return "" unless s
65
- f = s.at("./formattedref")
66
- return f.text if f
65
+ f = s.at("./formattedref") and return f.text
67
66
  t = s.at("./title")
68
67
  a = s.at("./abbreviation")
69
68
  n = s.at("./number")
@@ -72,7 +71,7 @@ module Iso690Render
72
71
  rev = doc&.at(".//edition")&.text&.sub(/^Revision /, "")
73
72
  ret = ""
74
73
  if t
75
- title = included(type) ? wrap(t.text, " <I>", "</I>") : wrap(t.text, " ", "")
74
+ title = included(type) ? wrap(t.text, " <em>", "</em>") : wrap(t.text, " ", "")
76
75
  ret += title
77
76
  ret += " (#{a.text.sub(/^NIST /, "")})" if a
78
77
  end
@@ -97,16 +96,13 @@ module Iso690Render
97
96
 
98
97
  def self.standardidentifier1(id)
99
98
  r = ""
100
- r += "#{id['type']} " if id["type"] and
101
- !%w(ISO IEC NIST).include? id["type"]
99
+ r += "#{id['type']} " if id["type"] and !%w(ISO IEC NIST).include? id["type"]
102
100
  r += id.text
103
101
  r
104
102
  end
105
103
 
106
104
  def self.uri(doc)
107
- uri = doc.at("./uri[@type = 'doi']") ||
108
- doc.at("./uri[@type = 'uri']") ||
109
- doc.at("./uri")
105
+ uri = doc.at("./uri[@type = 'doi']") || doc.at("./uri[@type = 'uri']") || doc.at("./uri")
110
106
  uri&.text
111
107
  end
112
108
 
@@ -120,7 +116,7 @@ module Iso690Render
120
116
  end
121
117
 
122
118
  def self.wrap(text, startdelim = " ", enddelim = ".")
123
- return "" if text.nil? || text.empty?
119
+ return "" if blank?(text)
124
120
  "#{startdelim}#{text}#{enddelim}"
125
121
  end
126
122
 
@@ -145,8 +141,7 @@ module Iso690Render
145
141
  def self.extent1(localities)
146
142
  ret = []
147
143
  localities.each do |l|
148
- ret << extent2(l["type"] || "page",
149
- l.at("./referenceFrom"), l.at("./referenceTo"))
144
+ ret << extent2(l["type"] || "page", l.at("./referenceFrom"), l.at("./referenceTo"))
150
145
  end
151
146
  ret.join(", ")
152
147
  end
@@ -199,53 +194,60 @@ module Iso690Render
199
194
  end
200
195
  end
201
196
 
197
+ # converting bibitem to <formattedref> + <docidentifier>
202
198
  def self.parse(doc, embedded = false)
203
- ret = ""
204
199
  f = doc.at("./formattedref") and
205
- return embedded ? f.children.to_xml : "<p>#{f.children.to_xml}</p>"
200
+ return embedded ? f.children.to_xml : doc.to_xml
206
201
 
202
+ ret = ""
207
203
  type = type(doc)
208
204
  container = doc.at("./relation[@type='includedIn']")
209
205
  if container && !date(doc) && date(container&.at("./bibitem"))
210
- doc <<
211
- ( container&.at("./bibitem/date[@type = 'issued' or @type = 'published' or "\
206
+ doc << ( container&.at("./bibitem/date[@type = 'issued' or @type = 'published' or "\
212
207
  "@type = 'circulated']")&.remove )
213
208
  end
214
- ser = series_title(doc)
215
209
  dr = draft(doc)
216
-
210
+ cr = creatornames(doc)
217
211
  # NIST has seen fit to completely change rendering based on the type of publication.
218
- if ser == "NIST Federal Information Processing Standards"
219
- ret += "National Institute of Standards and Technology"
220
- else
221
- ret += embedded ? wrap(creatornames(doc), "", "") : wrap(creatornames(doc), "", "")
212
+ if series_title(doc) == "NIST Federal Information Processing Standards"
213
+ cr = "National Institute of Standards and Technology"
222
214
  end
215
+ pub = placepub(doc)
216
+
217
+ ret += wrap(cr, "", "")
223
218
  if dr
224
219
  mdy = MMMddyyyy(date(doc)) and ret += wrap(mdy, " (", ")")
225
220
  else
226
221
  yr = year(date(doc)) and ret += wrap(yr, " (", ")")
227
222
  end
228
- ret += included(type) ? wrap(title(doc)) : wrap(title(doc), " <I>", "</I>.")
229
- ret += wrap(medium(doc), " [", "].")
223
+ ret += included(type) ? wrap(title(doc), " ", "") : wrap(title(doc), " <em>", "</em>")
224
+ ret += wrap(medium(doc), " [", "]")
230
225
  #ret += wrap(edition(doc), "", " edition.")
231
- s = series(doc, type)
232
- ret += wrap(placepub(doc), " (", "),")
226
+ if cr != pub
227
+ ret += wrap(pub, " (", ")")
228
+ end
229
+ if cr != pub && pub && !pub.empty? && (dr || !blank?(series(doc, type)))
230
+ ret += ","
231
+ end
233
232
  if dr
234
233
  ret += " Draft (#{dr})"
235
234
  end
236
235
  ret += wrap(series(doc, type), " ", "")
237
- ret += "," if !series(doc, type).empty? && date(doc)
238
- ret += wrap(date(doc))
239
- ret += wrap(standardidentifier(doc)) unless is_nist(doc)
240
- ret += wrap(uri(doc))
241
- ret += wrap(accessLocation(doc), " At: ", ".")
236
+ ret += wrap(date(doc), ", ", "")
237
+ ret += wrap(standardidentifier(doc), ". ", "") unless is_nist(doc)
238
+ ret += wrap(uri(doc), ". ", "")
239
+ ret += wrap(accessLocation(doc), ". At: ", "")
242
240
  if container
243
- ret += wrap(parse(container.at("./bibitem"), true), " In: ", "")
241
+ ret += wrap(parse(container.at("./bibitem"), true), ". In: ", "")
244
242
  locality = doc.xpath("./extent")
245
- ret += wrap(extent(locality))
243
+ ret += wrap(extent(locality), ", " , "")
246
244
  else
247
- ret += wrap(extent(doc.xpath("./extent")))
245
+ ret += wrap(extent(doc.xpath("./extent")), ", ", "")
248
246
  end
249
- embedded ? ret : "<p>#{ret}</p>"
247
+ if !embedded
248
+ ret += "."
249
+ end
250
+
251
+ embedded ? ret : "<formattedref>#{ret}</formattedref>#{doc.xpath('./docidentifier').to_xml}"
250
252
  end
251
253
  end
@@ -17,8 +17,7 @@ module Iso690Render
17
17
  ret += " (updated #{updated})" if updated
18
18
  return ret
19
19
  end
20
- pub = date1(doc&.at("./date[@type = 'circulated']")) and
21
- return pub
20
+ pub = date1(doc&.at("./date[@type = 'circulated']")) and return pub
22
21
  date1(doc&.at("./date"))
23
22
  end
24
23
 
@@ -31,12 +30,12 @@ module Iso690Render
31
30
  return nil if isodate.nil?
32
31
  return isodate if isodate == "--"
33
32
  arr = isodate.split("-")
34
- date = if arr.size == 1 and (/^\d+$/.match isodate)
35
- Date.new(*arr.map(&:to_i)).strftime("%Y")
36
- elsif arr.size == 2
37
- Date.new(*arr.map(&:to_i)).strftime("%B %Y")
38
- else
39
- Date.parse(isodate).strftime("%B %d, %Y")
40
- end
33
+ if arr.size == 1 and (/^\d+$/.match isodate)
34
+ Date.new(*arr.map(&:to_i)).strftime("%Y")
35
+ elsif arr.size == 2
36
+ Date.new(*arr.map(&:to_i)).strftime("%B %Y")
37
+ else
38
+ Date.parse(isodate).strftime("%B %d, %Y")
39
+ end
41
40
  end
42
41
  end
@@ -22,10 +22,11 @@ module IsoDoc
22
22
 
23
23
  def convert1(docxml, filename, dir)
24
24
  @series = docxml&.at(ns("//bibdata/series/abbreviation"))&.text
25
+ @cswp = ["NIST CSWP", "NIST CSTS"].include?(@series)
25
26
  @bibliographycount =
26
27
  docxml.xpath(ns("//bibliography/references | //annex/references | "\
27
28
  "//bibliography/clause/references")).size
28
- if @series == "NIST CSWP"
29
+ if @cswp
29
30
  @wordstylesheet_name = html_doc_path("wordstyle_cswp.scss")
30
31
  @standardstylesheet_name = html_doc_path("nist_cswp.scss")
31
32
  @wordcoverpage = html_doc_path("word_nist_titlepage_cswp.html")
@@ -111,7 +112,7 @@ module IsoDoc
111
112
  auth1 = docxml&.at("//div[@id = 'authority6']")&.remove
112
113
  dest1 and auth1 and dest1.each { |d| d.replace(auth1) }
113
114
  insert = docxml.at("//div[@class = 'WordSection2']")
114
- if @series != "NIST CSWP"
115
+ if @cswp
115
116
  auth = docxml&.at("//div[@class = 'authority']")&.remove || return
116
117
  insert.children.first.add_previous_sibling(auth)
117
118
  end
@@ -17,6 +17,20 @@ module Metanorma
17
17
  )
18
18
  end
19
19
 
20
+ def fonts_manifest
21
+ {
22
+ "Arial" => nil,
23
+ "Calibri" => nil,
24
+ "Cambria" => nil,
25
+ "Courier" => nil,
26
+ "Courier New" => nil,
27
+ "SimSun" => nil,
28
+ "SimHei" => nil,
29
+ "STIX Two Math" => nil,
30
+ "Times New Roman" => nil,
31
+ }
32
+ end
33
+
20
34
  def version
21
35
  "Metanorma::NIST #{Metanorma::NIST::VERSION}"
22
36
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module NIST
3
- VERSION = "1.2.9"
3
+ VERSION = "1.2.10"
4
4
  end
5
5
  end
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "iso-639"
31
31
  spec.add_dependency "tzinfo-data" # we need this for windows only
32
32
 
33
- spec.add_dependency "metanorma-standoc", "~> 1.6.0"
34
- spec.add_dependency "isodoc", "~> 1.3.0"
33
+ spec.add_dependency "metanorma-standoc", "~> 1.7.0"
34
+ spec.add_dependency "isodoc", "~> 1.4.0"
35
35
  #spec.add_dependency "relaton-nist", "~> 0.3.0"
36
36
 
37
37
  spec.add_development_dependency "byebug", "~> 9.1"
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: 1.2.9
4
+ version: 1.2.10
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-12-14 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.6.0
89
+ version: 1.7.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.6.0
96
+ version: 1.7.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isodoc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.3.0
103
+ version: 1.4.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.3.0
110
+ version: 1.4.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: byebug
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -331,7 +331,6 @@ files:
331
331
  - lib/isodoc/nist/xref.rb
332
332
  - lib/metanorma-nist.rb
333
333
  - lib/metanorma/nist.rb
334
- - lib/metanorma/nist/fonts_manifest.yaml
335
334
  - lib/metanorma/nist/processor.rb
336
335
  - lib/metanorma/nist/version.rb
337
336
  - metanorma-nist.gemspec
@@ -1,6 +0,0 @@
1
- ---
2
- SimSun:
3
- Cambria:
4
- SimHei:
5
- Calibri:
6
- Courier New: