metanorma-nist 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,26 +7,15 @@ module IsoDoc
7
7
  module NIST
8
8
  # A {Converter} implementation that generates PDF HTML output, and a
9
9
  # document schema encapsulation of the document for validation
10
- class PdfConvert < IsoDoc::PdfConvert
10
+ class PdfConvert < IsoDoc::XslfoPdfConvert
11
11
  def initialize(options)
12
12
  @libdir = File.dirname(__FILE__)
13
13
  super
14
14
  end
15
15
 
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
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"))
16
+ def pdf_stylesheet(docxml)
17
+ series = docxml&.at(ns("//bibdata/series/abbreviation"))&.text
18
+ series == "NIST CSWP" ? "nist.cswp.xsl" : "nist.sp.xsl"
30
19
  end
31
20
  end
32
21
  end
@@ -0,0 +1,10 @@
1
+ require_relative "base_convert"
2
+ require "isodoc"
3
+
4
+ module IsoDoc
5
+ module NIST
6
+ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
7
+ end
8
+ end
9
+ end
10
+
@@ -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
+ @xrefs.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(@xrefs.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
@@ -49,10 +49,6 @@ module IsoDoc
49
49
  olstyle: "l2" }
50
50
  end
51
51
 
52
- def metadata_init(lang, script, labels)
53
- @meta = Metadata.new(lang, script, labels)
54
- end
55
-
56
52
  def make_body(xml, docxml)
57
53
  body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
58
54
  xml.body **body_attr do |body|
@@ -155,29 +151,6 @@ module IsoDoc
155
151
  docxml
156
152
  end
157
153
 
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
154
  def keywords(_docxml, out)
182
155
  kw = @meta.get[:keywords]
183
156
  kw.empty? and return
@@ -189,31 +162,18 @@ module IsoDoc
189
162
  end
190
163
 
191
164
  def termdef_parse(node, out)
192
- pref = node.at(ns("./preferred"))
193
165
  out.table **{ class: "terms_dl" } do |dl|
194
166
  dl.tr do |tr|
195
167
  tr.td **{ valign: "top", align: "left" } do |dt|
196
- pref.children.each { |n| parse(n, dt) }
168
+ term_and_termref_parse(node, dt)
197
169
  end
198
- set_termdomain("")
199
170
  tr.td **{ valign: "top" } do |dd|
200
- node.children.each { |n| parse(n, dd) unless n.name == "preferred" }
171
+ term_rest_parse(node, dd)
201
172
  end
202
173
  end
203
174
  end
204
175
  end
205
176
 
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
177
  include BaseConvert
218
178
  end
219
179
  end
@@ -4,7 +4,7 @@ require "fileutils"
4
4
 
5
5
  module IsoDoc
6
6
  module NIST
7
- module BaseConvert
7
+ class Xref < IsoDoc::Xref
8
8
  SECTIONS_XPATH =
9
9
  "//foreword | //introduction | //reviewnote | //executivesummary | //annex | "\
10
10
  "//sections/clause | //bibliography/references | //acknowledgements | "\
@@ -50,7 +50,7 @@ module IsoDoc
50
50
  end
51
51
 
52
52
  def annex_name_lbl(clause, num)
53
- l10n("<b>#{@annex_lbl} #{num}</b>")
53
+ l10n("<b>#{@labels['annex']} #{num}</b>")
54
54
  end
55
55
 
56
56
  def annex_name(annex, name, div)
@@ -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,7 +3,9 @@ require_relative "asciidoctor/nist/converter"
3
3
  require_relative "isodoc/nist/html_convert"
4
4
  require_relative "isodoc/nist/pdf_convert"
5
5
  require_relative "isodoc/nist/word_convert"
6
+ require_relative "isodoc/nist/presentation_xml_convert"
6
7
  require_relative "isodoc/nist/render"
8
+ require_relative "isodoc/nist/xref"
7
9
  require_relative "metanorma/nist/version"
8
10
 
9
11
  if defined? Metanorma
@@ -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
@@ -26,14 +33,16 @@ module Metanorma
26
33
  Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
27
34
  end
28
35
 
29
- def output(isodoc_node, outname, format, options={})
36
+ def output(isodoc_node, inname, outname, format, options={})
30
37
  case format
31
38
  when :html
32
- IsoDoc::NIST::HtmlConvert.new(options).convert(outname, isodoc_node)
39
+ IsoDoc::NIST::HtmlConvert.new(options).convert(inname, isodoc_node, nil, outname)
33
40
  when :doc
34
- IsoDoc::NIST::WordConvert.new(options).convert(outname, isodoc_node)
41
+ IsoDoc::NIST::WordConvert.new(options).convert(inname, isodoc_node, nil, outname)
35
42
  when :pdf
36
- IsoDoc::NIST::PdfConvert.new(options).convert(outname, isodoc_node)
43
+ IsoDoc::NIST::PdfConvert.new(options).convert(inname, isodoc_node, nil, outname)
44
+ when :presentation
45
+ IsoDoc::NIST::PresentationXMLConvert.new(options).convert(inname, isodoc_node, nil, outname)
37
46
  else
38
47
  super
39
48
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module NIST
3
- VERSION = "1.0.6"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -27,10 +27,11 @@ 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 "isodoc", "~> 1.0.0"
33
+ spec.add_dependency "metanorma-standoc", "~> 1.4.0"
34
+ spec.add_dependency "isodoc", "~> 1.1.0"
34
35
  #spec.add_dependency "relaton-nist", "~> 0.3.0"
35
36
 
36
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.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-01 00:00:00.000000000 Z
11
+ date: 2020-06-26 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,28 +86,28 @@ 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
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 1.0.0
103
+ version: 1.1.0
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 1.0.0
110
+ version: 1.1.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: byebug
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -271,7 +285,6 @@ files:
271
285
  - lib/isodoc/nist/html/nist.scss
272
286
  - lib/isodoc/nist/html/nist_cswp.scss
273
287
  - lib/isodoc/nist/html/scripts.html
274
- - lib/isodoc/nist/html/scripts.pdf.html
275
288
  - lib/isodoc/nist/html/word_nist_intro.html
276
289
  - lib/isodoc/nist/html/word_nist_intro_cswp.html
277
290
  - lib/isodoc/nist/html/word_nist_titlepage.html
@@ -285,13 +298,15 @@ files:
285
298
  - lib/isodoc/nist/nist.cswp.xsl
286
299
  - lib/isodoc/nist/nist.sp.xsl
287
300
  - lib/isodoc/nist/pdf_convert.rb
301
+ - lib/isodoc/nist/presentation_xml_convert.rb
288
302
  - lib/isodoc/nist/refs.rb
289
303
  - lib/isodoc/nist/render.rb
290
304
  - lib/isodoc/nist/render_contributors.rb
291
305
  - lib/isodoc/nist/render_dates.rb
306
+ - lib/isodoc/nist/section.rb
292
307
  - lib/isodoc/nist/word_convert.rb
293
308
  - lib/isodoc/nist/word_convert_toc.rb
294
- - lib/isodoc/nist/xrefs.rb
309
+ - lib/isodoc/nist/xref.rb
295
310
  - lib/metanorma-nist.rb
296
311
  - lib/metanorma/nist.rb
297
312
  - lib/metanorma/nist/processor.rb
@@ -301,7 +316,7 @@ homepage: https://github.com/metanorma/metanorma-nist
301
316
  licenses:
302
317
  - BSD-2-Clause
303
318
  metadata: {}
304
- post_install_message:
319
+ post_install_message:
305
320
  rdoc_options: []
306
321
  require_paths:
307
322
  - lib
@@ -316,9 +331,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
331
  - !ruby/object:Gem::Version
317
332
  version: '0'
318
333
  requirements: []
319
- rubyforge_project:
320
- rubygems_version: 2.7.6
321
- signing_key:
334
+ rubygems_version: 3.0.3
335
+ signing_key:
322
336
  specification_version: 4
323
337
  summary: Metanorma NIST gem.
324
338
  test_files: []