metanorma-nist 1.0.3 → 1.0.8

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"
@@ -93,7 +93,7 @@ module Iso690Render
93
93
  def self.standardidentifier(doc)
94
94
  ret = []
95
95
  doc.xpath("./docidentifier").each do |id|
96
- next if %w(nist-mr nist-long).include? id["type"]
96
+ next if %w(nist-mr nist-long metanorma rfc-anchor).include? id["type"]
97
97
  ret << standardidentifier1(id)
98
98
  end
99
99
  ret.join(". ")
@@ -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
@@ -207,7 +223,6 @@ module Iso690Render
207
223
  else
208
224
  ret += embedded ? wrap(creatornames(doc), "", "") : wrap(creatornames(doc), "", "")
209
225
  end
210
-
211
226
  if dr
212
227
  mdy = MMMddyyyy(date(doc)) and ret += wrap(mdy, " (", ")")
213
228
  else
@@ -229,8 +244,7 @@ module Iso690Render
229
244
  ret += wrap(accessLocation(doc), " At: ", ".")
230
245
  if container
231
246
  ret += wrap(parse(container.at("./bibitem"), true), " In: ", "")
232
- locality = container.xpath("./locality")
233
- locality.empty? and locality = doc.xpath("./extent")
247
+ locality = doc.xpath("./extent")
234
248
  ret += wrap(extent(locality))
235
249
  else
236
250
  ret += wrap(extent(doc.xpath("./extent")))
@@ -54,6 +54,7 @@ module Iso690Render
54
54
 
55
55
  def self.MMMddyyyy(isodate)
56
56
  return nil if isodate.nil?
57
+ return isodate if isodate == "--"
57
58
  arr = isodate.split("-")
58
59
  date = if arr.size == 1 and (/^\d+$/.match isodate)
59
60
  Date.new(*arr.map(&:to_i)).strftime("%Y")
@@ -70,26 +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
- annex_names1(c, "#{num}", 1)
81
- end
82
- hierarchical_asset_names(clause, num)
83
- end
84
-
85
- def annex_names1(clause, num, level)
86
- @anchors[clause["id"]] = { label: num, xref: "#{@annex_lbl} #{num}",
87
- level: level, type: "clause" }
88
- clause.xpath(ns("./clause | ./terms | ./term | ./references")).each_with_index do |c, i|
89
- annex_names1(c, "#{num}.#{i + 1}", level + 1)
90
- end
91
- end
92
-
93
73
  def terms_parse(node, out)
94
74
  out.div **attr_code(id: node["id"]) do |div|
95
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.3"
3
+ VERSION = "1.0.8"
4
4
  end
5
5
  end
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.3
4
+ version: 1.0.8
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-03-20 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -257,6 +257,7 @@ files:
257
257
  - lib/asciidoctor/nist/reqt.rng
258
258
  - lib/asciidoctor/nist/validate.rb
259
259
  - lib/isodoc/nist/base_convert.rb
260
+ - lib/isodoc/nist/common.xsl
260
261
  - lib/isodoc/nist/html/_coverpage.scss
261
262
  - lib/isodoc/nist/html/commerce-logo-color.png
262
263
  - lib/isodoc/nist/html/deptofcommerce.png
@@ -270,7 +271,6 @@ files:
270
271
  - lib/isodoc/nist/html/nist.scss
271
272
  - lib/isodoc/nist/html/nist_cswp.scss
272
273
  - lib/isodoc/nist/html/scripts.html
273
- - lib/isodoc/nist/html/scripts.pdf.html
274
274
  - lib/isodoc/nist/html/word_nist_intro.html
275
275
  - lib/isodoc/nist/html/word_nist_intro_cswp.html
276
276
  - lib/isodoc/nist/html/word_nist_titlepage.html
@@ -281,6 +281,8 @@ files:
281
281
  - lib/isodoc/nist/i18n-en.yaml
282
282
  - lib/isodoc/nist/metadata.rb
283
283
  - lib/isodoc/nist/metadata_id.rb
284
+ - lib/isodoc/nist/nist.cswp.xsl
285
+ - lib/isodoc/nist/nist.sp.xsl
284
286
  - lib/isodoc/nist/pdf_convert.rb
285
287
  - lib/isodoc/nist/refs.rb
286
288
  - lib/isodoc/nist/render.rb
@@ -1,72 +0,0 @@
1
- <script>
2
- //TOC generation
3
- $('#toc').toc({
4
- 'selectors': toclevel(), //elements to use as headings
5
- 'container': 'body', //element to find all selectors in
6
- 'smoothScrolling': true, //enable or disable smooth scrolling on click
7
- 'prefix': 'toc', //prefix for anchor tags and class names
8
- 'onHighlight': function(el) {}, //called when a new section is highlighted
9
- 'highlightOnScroll': false, //add class to heading that is currently in focus
10
- 'highlightOffset': 100, //offset to trigger the next headline
11
- 'anchorName': function(i, heading, prefix) { //custom function for anchor name
12
- return prefix+i;
13
- },
14
- 'headerText': function(i, heading, $heading) { //custom function building the header-item text
15
- return $heading.text();
16
- },
17
- 'itemClass': function(i, heading, $heading, prefix) { // custom function for item class
18
- return $heading[0].tagName.toLowerCase();
19
- }
20
- });
21
-
22
- </script>
23
-
24
- <script>
25
- //TOC toggle animation
26
- $('#toggle').on('click', function(){
27
- if( $('nav').is(':visible') ) {
28
- $('nav').animate({ 'left': '-353px' }, 'slow', function(){
29
- $('nav').hide();
30
- });
31
- $('.container').animate({ 'padding-left': '31px' }, 'slow');
32
- }
33
- else {
34
- $('nav').show();
35
- $('nav').animate({ 'left': '0px' }, 'slow');
36
- $('.container').animate({ 'padding-left': '360px' }, 'slow');
37
- }
38
- });
39
- </script>
40
-
41
- <script>
42
- // Scroll to top button
43
- window.onscroll = function() {scrollFunction()};
44
-
45
- function scrollFunction() {
46
- if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
47
- document.getElementById("myBtn").style.display = "block";
48
- } else {
49
- document.getElementById("myBtn").style.display = "none";
50
- }
51
- }
52
-
53
- // When the user clicks on the button, scroll to the top of the document
54
- function topFunction() {
55
- document.body.scrollTop = 0;
56
- document.documentElement.scrollTop = 0;
57
- }
58
- </script>
59
-
60
- <script>
61
- /*
62
- $(document).ready(function() {
63
- $('[id^=toc]').each(function ()
64
- {
65
- var currentToc = $(this);
66
- var url = window.location.href;
67
- currentToc.wrap("<a href='" + url + "#" + currentToc.attr("id") + "' </a>");
68
- });
69
- });
70
- */
71
- </script>
72
-