metanorma-nist 1.0.4 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,154 +13,21 @@ module IsoDoc
13
13
  super
14
14
  end
15
15
 
16
- def convert1(docxml, filename, dir)
17
- @bibliographycount = docxml.xpath(ns("//bibliography/references | //annex/references | //bibliography/clause/references")).size
18
- #FileUtils.cp html_doc_path('logo.png'), File.join(@localdir, "logo.png")
19
- #FileUtils.cp html_doc_path('commerce-logo-color.png'), File.join(@localdir, "commerce-logo-color.png")
20
- #@files_to_delete << File.join(@localdir, "logo.png")
21
- #@files_to_delete << File.join(@localdir, "commerce-logo-color.png")
22
- super
23
- end
24
-
25
- def default_fonts(options)
26
- {
27
- bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Libre Baskerville",serif'),
28
- headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Libre Baskerville",serif'),
29
- monospacefont: '"Space Mono",monospace'
30
- }
31
- end
32
-
33
- def default_file_locations(_options)
34
- {
35
- htmlstylesheet: html_doc_path("htmlstyle.scss"),
36
- htmlcoverpage: html_doc_path("html_nist_titlepage.html"),
37
- htmlintropage: html_doc_path("html_nist_intro.html"),
38
- scripts_pdf: html_doc_path("scripts.pdf.html"),
39
- }
40
- end
41
-
42
- def metadata_init(lang, script, labels)
43
- @meta = Metadata.new(lang, script, labels)
44
- end
45
-
46
- def googlefonts
47
- <<~HEAD.freeze
48
- <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,600,600i" rel="stylesheet">
49
- <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet" />
50
- <link href="https://fonts.googleapis.com/css?family=Libre+Baskerville:400,400i,700,700i" rel="stylesheet">
51
- HEAD
52
- end
53
-
54
- def toclevel
55
- <<~HEAD.freeze
56
- function toclevel() { var i; var text = "";
57
- for(i = 1; i <= #{@htmlToClevels}; i++) {
58
- if (i > 1) { text += ","; } text += "h" + i + ":not(:empty):not(.TermNum):not(.AbstractTitle):not(.IntroTitle):not(.ForewordTitle)"; }
59
- return text;}
60
- HEAD
61
- end
62
-
63
- def make_body(xml, docxml)
64
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
65
- xml.body **body_attr do |body|
66
- make_body1(body, docxml)
67
- make_body2(body, docxml)
68
- make_body3(body, docxml)
69
- end
70
- end
71
-
72
- def html_toc(docxml)
73
- docxml
74
- end
75
-
76
- def make_body3(body, docxml)
77
- body.div **{ class: "main-section" } do |div3|
78
- foreword docxml, div3
79
- abstract docxml, div3
80
- keywords docxml, div3
81
- boilerplate docxml, div3
82
- preface docxml, div3
83
- middle docxml, div3
84
- footnotes div3
85
- comments div3
16
+ def convert(filename, file = nil, debug = false)
17
+ file = File.read(filename, encoding: "utf-8") if file.nil?
18
+ docxml, outname_html, dir = convert_init(file, filename, debug)
19
+ @series = docxml&.at(ns("//bibdata/series/abbreviation"))&.text
20
+ /\.xml$/.match(filename) or
21
+ filename = Tempfile.open([outname_html, ".xml"], encoding: "utf-8") do |f|
22
+ f.write file
23
+ f.path
86
24
  end
25
+ FileUtils.rm_rf dir
26
+ ::Metanorma::Output::XslfoPdf.new.convert(
27
+ filename, outname_html + ".pdf",
28
+ File.join(@libdir, @series == "NIST CSWP" ?
29
+ "nist.cswp.xsl" : "nist.sp.xsl"))
87
30
  end
88
-
89
- def authority_cleanup(docxml)
90
- dest = docxml.at("//div[@id = 'authority']") || return
91
- auth = docxml.at("//div[@class = 'authority']") || return
92
- auth.xpath(".//h1 | .//h2").each { |h| h["class"] = "IntroTitle" }
93
- dest1 = docxml.xpath("//div[@class = 'authority6']")
94
- auth1 = docxml&.at("//div[@id = 'authority6']")&.remove
95
- dest1 and auth1 and dest1.each { |d| d.replace(auth1) }
96
- dest.replace(auth.remove)
97
- a = docxml.at("//div[@id = 'authority1']") and a["class"] = "authority1"
98
- a = docxml.at("//div[@id = 'authority2']") and a["class"] = "authority2"
99
- a = docxml.at("//div[@id = 'authority3']") and a["class"] = "authority3"
100
- a = docxml.at("//div[@id = 'authority3a']") and a["class"] = "authority3"
101
- a = docxml.at("//div[@id = 'authority4']") and a["class"] = "authority4"
102
- a = docxml.at("//div[@id = 'authority5']") and a["class"] = "authority5"
103
- a = docxml.at("//div[@id = 'authority6']") and a["class"] = "authority6"
104
- end
105
-
106
- def cleanup(docxml)
107
- super
108
- term_cleanup(docxml)
109
- requirement_cleanup(docxml)
110
- end
111
-
112
- def bibliography(isoxml, out)
113
- f = isoxml.at(ns("//bibliography/clause | //bibliography/references")) || return
114
- page_break(out)
115
- isoxml.xpath(ns("//bibliography/clause | //bibliography/references")).each do |f|
116
- out.div do |div|
117
- div.h1 **{ class: "Section3" } do |h1|
118
- if @bibliographycount == 1
119
- h1 << "References"
120
- else
121
- f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
122
- end
123
- end
124
- biblio_list(f, div, false)
125
- end
126
- end
127
- end
128
-
129
- def keywords(_docxml, out)
130
- kw = @meta.get[:keywords]
131
- kw.empty? and return
132
- out.div **{ class: "Section3" } do |div|
133
- out.div do |div|
134
- clause_name(nil, "Keywords", div, class: "IntroTitle")
135
- div.p kw.sort.join("; ")
136
- end
137
- end
138
- end
139
-
140
- def termdef_parse(node, out)
141
- pref = node.at(ns("./preferred"))
142
- out.dl **{ class: "terms_dl" } do |dl|
143
- dl.dt do |dt|
144
- pref.children.each { |n| parse(n, dt) }
145
- end
146
- set_termdomain("")
147
- dl.dd do |dd|
148
- node.children.each { |n| parse(n, dd) unless n.name == "preferred" }
149
- end
150
- end
151
- end
152
-
153
- def term_cleanup(docxml)
154
- docxml.xpath("//table[@class = 'terms_dl']").each do |d|
155
- prev = d.previous_element
156
- next unless prev.name == "table" and prev["class"] == "terms_dl"
157
- d.children.each { |n| prev.add_child(n.remove) }
158
- d.remove
159
- end
160
- docxml
161
- end
162
-
163
- include BaseConvert
164
31
  end
165
32
  end
166
33
  end
@@ -23,12 +23,12 @@ module IsoDoc
23
23
  def reference_format(b, r)
24
24
  id = bibitem_ref_code(b)
25
25
  code = render_identifier(id)
26
- if id["type"] == "metanorma"
27
- r << "[#{code}] "
26
+ if code[0]
27
+ r << "#{code[0]} "
28
28
  insert_tab(r, 1)
29
29
  end
30
30
  reference_format1(b, r)
31
- r << " [#{code}] " unless id["type"] == "metanorma"
31
+ r << " [#{code[1]}] " if code[1]
32
32
  end
33
33
 
34
34
  def reference_format1(b, r)
@@ -42,6 +42,12 @@ module IsoDoc
42
42
  end
43
43
  end
44
44
 
45
+ def bracket_if_num(x)
46
+ return nil if x.nil?
47
+ x = x.text.sub(/^\[/, "").sub(/\]$/, "")
48
+ "[#{x}]"
49
+ end
50
+
45
51
  def omit_docid_prefix(prefix)
46
52
  return true if prefix.nil? || prefix.empty?
47
53
  super || prefix == "NIST"
@@ -51,6 +57,44 @@ module IsoDoc
51
57
  bibitem = b.dup.to_xml
52
58
  r.parent.add_child ::Iso690Render.render(bibitem, true)
53
59
  end
60
+
61
+ def bibliography_parse(node, out)
62
+ title = node&.at(ns("./title"))&.text || ""
63
+ out.div do |div|
64
+ unless suppress_biblio_title(node)
65
+ anchor(node['id'], :label, false) and
66
+ clause_parse_title(node, div, node.at(ns("./title")), out) or
67
+ div.h2 title, **{ class: "Section3" }
68
+ end
69
+ biblio_list(node, div, true)
70
+ end
71
+ end
72
+
73
+ def bibliography(isoxml, out)
74
+ f = isoxml.at(ns("//bibliography/clause | //bibliography/references")) || return
75
+ page_break(out)
76
+ isoxml.xpath(ns("//bibliography/clause | //bibliography/references")).each do |f|
77
+ out.div do |div|
78
+ div.h1 **{ class: "Section3" } do |h1|
79
+ if @bibliographycount == 1 then h1 << "References"
80
+ else
81
+ f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
82
+ end
83
+ end
84
+ biblio_list(f, div, false)
85
+ end
86
+ end
87
+ end
88
+
89
+ def suppress_biblio_title(node)
90
+ return false unless node.parent.name == "annex"
91
+ return false if node.parent.xpath("./references | ./clause | "\
92
+ "./terms | ./definitions").size > 1
93
+ title1 = node&.at(ns("./title"))&.text
94
+ return true unless title1
95
+ title2 = node&.parent&.at(ns("./title"))&.text
96
+ title1&.casecmp(title2) == 0
97
+ end
54
98
  end
55
99
  end
56
100
  end
@@ -134,7 +134,7 @@ module Iso690Render
134
134
  "book"
135
135
  end
136
136
 
137
- def self.extent1(type, from, to)
137
+ def self.extent2(type, from, to)
138
138
  ret = ""
139
139
  case type
140
140
  when "page" then type = to ? "pp." : "p."
@@ -146,15 +146,31 @@ module Iso690Render
146
146
  ret
147
147
  end
148
148
 
149
- def self.extent(localities)
149
+ def self.extent1(localities)
150
150
  ret = []
151
151
  localities.each do |l|
152
- ret << extent1(l["type"] || "page",
152
+ ret << extent2(l["type"] || "page",
153
153
  l.at("./referenceFrom"), l.at("./referenceTo"))
154
154
  end
155
155
  ret.join(", ")
156
156
  end
157
157
 
158
+ def self.extent(localities)
159
+ ret = []
160
+ ret1 = ""
161
+ localities.each do |l|
162
+ if %w(localityStack).include? l.name
163
+ ret << ret1
164
+ ret1 = ""
165
+ ret << extent1(l.children)
166
+ else
167
+ ret1 += extent1([l])
168
+ end
169
+ end
170
+ ret << ret1
171
+ ret.reject { |c| c.empty? }.join("; ")
172
+ end
173
+
158
174
  def self.draft(doc)
159
175
  return nil unless is_nist(doc)
160
176
  dr = doc&.at("./status/stage")&.text
@@ -228,8 +244,7 @@ module Iso690Render
228
244
  ret += wrap(accessLocation(doc), " At: ", ".")
229
245
  if container
230
246
  ret += wrap(parse(container.at("./bibitem"), true), " In: ", "")
231
- locality = container.xpath("./locality")
232
- locality.empty? and locality = doc.xpath("./extent")
247
+ locality = doc.xpath("./extent")
233
248
  ret += wrap(extent(locality))
234
249
  else
235
250
  ret += wrap(extent(doc.xpath("./extent")))
@@ -0,0 +1,55 @@
1
+ module IsoDoc
2
+ module NIST
3
+ module BaseConvert
4
+ def abstract(isoxml, out)
5
+ f = isoxml.at(ns("//preface/abstract")) || return
6
+ #page_break(out)
7
+ out.div **attr_code(id: f["id"]) do |s|
8
+ clause_name(nil, @abstract_lbl, s, class: "AbstractTitle")
9
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
10
+ end
11
+ end
12
+
13
+ # All "[preface]" sections should have class "IntroTitle" to prevent
14
+ # page breaks, but for the Exec Summary
15
+ def preface(isoxml, out)
16
+ isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
17
+ next if skip_render(c, isoxml)
18
+ title = c&.at(ns("./title"))
19
+ patent = ["Call for Patent Claims",
20
+ "Patent Disclosure Notice"].include? title&.text
21
+ preface1(c, title, patent, out)
22
+ end
23
+ end
24
+
25
+ def preface1(c, title, patent, out)
26
+ out.div **attr_code(id: c["id"]) do |s|
27
+ page_break(s) if patent
28
+ clause_name(anchor(c['id'], :label), title, s,
29
+ class: (c.name == "executivesummary") ? "NormalTitle" :
30
+ "IntroTitle")
31
+ c.elements.reject { |c1| c1.name == "title" }.each do |c1|
32
+ parse(c1, s)
33
+ end
34
+ end
35
+ end
36
+
37
+ def middle(isoxml, out)
38
+ clause isoxml, out
39
+ bibliography isoxml, out
40
+ annex isoxml, out
41
+ end
42
+
43
+ def foreword(isoxml, out)
44
+ f = isoxml.at(ns("//foreword")) || return
45
+ out.div **attr_code(id: f["id"]) do |s|
46
+ title = f.at(ns("./title"))
47
+ s.h1(**{ class: "ForewordTitle" }) do |h1|
48
+ title and title.children.each { |e| parse(e, h1) }
49
+ end
50
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -155,29 +155,6 @@ module IsoDoc
155
155
  docxml
156
156
  end
157
157
 
158
- def bibliography(isoxml, out)
159
- f = isoxml.at(ns("//bibliography/clause | "\
160
- "//bibliography/references")) || return
161
- page_break(out)
162
- isoxml.xpath(ns("//bibliography/clause | "\
163
- "//bibliography/references")).each do |f|
164
- out.div do |div|
165
- #div.p **{ class: "h1Annex" } do |h1|
166
- div.h1 do |h1|
167
- if @bibliographycount == 1
168
- h1 << "References"
169
- else
170
- f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
171
- end
172
- end
173
- f.elements.reject do |e|
174
- ["reference", "title", "bibitem"].include? e.name
175
- end.each { |e| parse(e, div) }
176
- biblio_list(f, div, false)
177
- end
178
- end
179
- end
180
-
181
158
  def keywords(_docxml, out)
182
159
  kw = @meta.get[:keywords]
183
160
  kw.empty? and return
@@ -189,31 +166,18 @@ module IsoDoc
189
166
  end
190
167
 
191
168
  def termdef_parse(node, out)
192
- pref = node.at(ns("./preferred"))
193
169
  out.table **{ class: "terms_dl" } do |dl|
194
170
  dl.tr do |tr|
195
171
  tr.td **{ valign: "top", align: "left" } do |dt|
196
- pref.children.each { |n| parse(n, dt) }
172
+ term_and_termref_parse(node, dt)
197
173
  end
198
- set_termdomain("")
199
174
  tr.td **{ valign: "top" } do |dd|
200
- node.children.each { |n| parse(n, dd) unless n.name == "preferred" }
175
+ term_rest_parse(node, dd)
201
176
  end
202
177
  end
203
178
  end
204
179
  end
205
180
 
206
- def term_cleanup(docxml)
207
- docxml.xpath("//table[@class = 'terms_dl']").each do |d|
208
- prev = d.previous_element
209
- next unless prev and prev.name == "table" and
210
- prev["class"] == "terms_dl"
211
- d.children.each { |n| prev.add_child(n.remove) }
212
- d.remove
213
- end
214
- docxml
215
- end
216
-
217
181
  include BaseConvert
218
182
  end
219
183
  end
@@ -70,27 +70,6 @@ module IsoDoc
70
70
  "-"
71
71
  end
72
72
 
73
- def annex_names(clause, num)
74
- @anchors[clause["id"]] = { label: annex_name_lbl(clause, num), type: "clause",
75
- xref: "#{@annex_lbl} #{num}", level: 1 }
76
- clause.xpath(ns("./clause")).each_with_index do |c, i|
77
- annex_names1(c, "#{num}.#{i + 1}", 2)
78
- end
79
- clause.xpath(ns("./terms | ./term | ./references")).each_with_index do |c, i|
80
- suppress_biblio_title(c) ?
81
- annex_names1(c, "#{num}", 1) : annex_names1(c, "#{num}.#{i + 1}", 2)
82
- end
83
- hierarchical_asset_names(clause, num)
84
- end
85
-
86
- def annex_names1(clause, num, level)
87
- @anchors[clause["id"]] = { label: num, xref: "#{@annex_lbl} #{num}",
88
- level: level, type: "clause" }
89
- clause.xpath(ns("./clause | ./terms | ./term | ./references")).each_with_index do |c, i|
90
- annex_names1(c, "#{num}.#{i + 1}", level + 1)
91
- end
92
- end
93
-
94
73
  def terms_parse(node, out)
95
74
  out.div **attr_code(id: node["id"]) do |div|
96
75
  node.at(ns("./title")) and
@@ -3,6 +3,13 @@ require "metanorma/processor"
3
3
  module Metanorma
4
4
  module NIST
5
5
  class Processor < Metanorma::Processor
6
+ def self.fonts_used
7
+ {
8
+ html: ["Times New Roman", "Arial", "Courier New"],
9
+ doc: ["Times New Roman", "Arial", "Courier New"],
10
+ pdf: ["Times New Roman", "Arial", "Courier New"],
11
+ }
12
+ end
6
13
 
7
14
  def initialize
8
15
  @short = :nist