metanorma-nist 1.0.5 → 1.0.10

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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module NIST
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.10"
4
4
  end
5
5
  end
@@ -27,9 +27,10 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "htmlentities", "~> 4.3.4"
28
28
  spec.add_dependency "ruby-jing"
29
29
  spec.add_dependency "twitter_cldr"
30
+ spec.add_dependency "iso-639"
30
31
  spec.add_dependency "tzinfo-data" # we need this for windows only
31
32
 
32
- spec.add_dependency "metanorma-standoc", "~> 1.3.0"
33
+ spec.add_dependency "metanorma-standoc", "~> 1.4.0"
33
34
  spec.add_dependency "isodoc", "~> 1.0.0"
34
35
  #spec.add_dependency "relaton-nist", "~> 0.3.0"
35
36
 
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.0.5
4
+ version: 1.0.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-04-17 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: iso-639
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: tzinfo-data
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 1.3.0
89
+ version: 1.4.0
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.3.0
96
+ version: 1.4.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: isodoc
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -257,6 +271,7 @@ files:
257
271
  - lib/asciidoctor/nist/reqt.rng
258
272
  - lib/asciidoctor/nist/validate.rb
259
273
  - lib/isodoc/nist/base_convert.rb
274
+ - lib/isodoc/nist/common.xsl
260
275
  - lib/isodoc/nist/html/_coverpage.scss
261
276
  - lib/isodoc/nist/html/commerce-logo-color.png
262
277
  - lib/isodoc/nist/html/deptofcommerce.png
@@ -270,7 +285,6 @@ files:
270
285
  - lib/isodoc/nist/html/nist.scss
271
286
  - lib/isodoc/nist/html/nist_cswp.scss
272
287
  - lib/isodoc/nist/html/scripts.html
273
- - lib/isodoc/nist/html/scripts.pdf.html
274
288
  - lib/isodoc/nist/html/word_nist_intro.html
275
289
  - lib/isodoc/nist/html/word_nist_intro_cswp.html
276
290
  - lib/isodoc/nist/html/word_nist_titlepage.html
@@ -281,11 +295,14 @@ files:
281
295
  - lib/isodoc/nist/i18n-en.yaml
282
296
  - lib/isodoc/nist/metadata.rb
283
297
  - lib/isodoc/nist/metadata_id.rb
298
+ - lib/isodoc/nist/nist.cswp.xsl
299
+ - lib/isodoc/nist/nist.sp.xsl
284
300
  - lib/isodoc/nist/pdf_convert.rb
285
301
  - lib/isodoc/nist/refs.rb
286
302
  - lib/isodoc/nist/render.rb
287
303
  - lib/isodoc/nist/render_contributors.rb
288
304
  - lib/isodoc/nist/render_dates.rb
305
+ - lib/isodoc/nist/section.rb
289
306
  - lib/isodoc/nist/word_convert.rb
290
307
  - lib/isodoc/nist/word_convert_toc.rb
291
308
  - lib/isodoc/nist/xrefs.rb