metanorma-nist 1.0.10 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +0 -1
  3. data/.github/workflows/ubuntu.yml +10 -7
  4. data/.github/workflows/windows.yml +0 -1
  5. data/Rakefile +2 -0
  6. data/lib/asciidoctor/nist/boilerplate.rb +2 -2
  7. data/lib/asciidoctor/nist/cleanup.rb +34 -4
  8. data/lib/asciidoctor/nist/converter.rb +17 -19
  9. data/lib/asciidoctor/nist/front.rb +27 -23
  10. data/lib/asciidoctor/nist/front_id.rb +1 -1
  11. data/lib/asciidoctor/nist/isodoc.rng +12 -6
  12. data/lib/asciidoctor/nist/validate.rb +16 -9
  13. data/lib/isodoc/nist/base_convert.rb +8 -47
  14. data/lib/isodoc/nist/html/_coverpage.css +243 -0
  15. data/lib/isodoc/nist/html/_coverpage.scss +1 -1
  16. data/lib/isodoc/nist/html/html_nist_titlepage.html +1 -1
  17. data/lib/isodoc/nist/html/htmlstyle.css +955 -0
  18. data/lib/isodoc/nist/html/nist.css +1055 -0
  19. data/lib/isodoc/nist/html/nist.scss +0 -1
  20. data/lib/isodoc/nist/html/nist_cswp.css +996 -0
  21. data/lib/isodoc/nist/html/nist_cswp.scss +0 -1
  22. data/lib/isodoc/nist/html/wordstyle.css +1440 -0
  23. data/lib/isodoc/nist/html/wordstyle.scss +0 -1
  24. data/lib/isodoc/nist/html/wordstyle_cswp.css +1119 -0
  25. data/lib/isodoc/nist/html/wordstyle_cswp.scss +0 -1
  26. data/lib/isodoc/nist/html_convert.rb +4 -9
  27. data/lib/isodoc/nist/i18n-en.yaml +3 -0
  28. data/lib/isodoc/nist/i18n.rb +10 -0
  29. data/lib/isodoc/nist/init.rb +37 -0
  30. data/lib/isodoc/nist/metadata_id.rb +1 -1
  31. data/lib/isodoc/nist/nist.cswp.xsl +2010 -2301
  32. data/lib/isodoc/nist/nist.sp.xsl +2824 -2902
  33. data/lib/isodoc/nist/pdf_convert.rb +4 -16
  34. data/lib/isodoc/nist/presentation_xml_convert.rb +80 -0
  35. data/lib/isodoc/nist/refs.rb +8 -19
  36. data/lib/isodoc/nist/render.rb +2 -1
  37. data/lib/isodoc/nist/render_dates.rb +0 -25
  38. data/lib/isodoc/nist/section.rb +9 -6
  39. data/lib/isodoc/nist/word_convert.rb +7 -19
  40. data/lib/isodoc/nist/word_convert_toc.rb +2 -2
  41. data/lib/isodoc/nist/{xrefs.rb → xref.rb} +2 -25
  42. data/lib/metanorma-nist.rb +2 -0
  43. data/lib/metanorma/nist/processor.rb +6 -8
  44. data/lib/metanorma/nist/version.rb +1 -1
  45. data/metanorma-nist.gemspec +3 -2
  46. metadata +34 -12
@@ -1,5 +1,4 @@
1
1
  require "isodoc"
2
- require_relative "metadata"
3
2
  require "fileutils"
4
3
  require_relative "base_convert"
5
4
 
@@ -7,26 +6,15 @@ module IsoDoc
7
6
  module NIST
8
7
  # A {Converter} implementation that generates PDF HTML output, and a
9
8
  # document schema encapsulation of the document for validation
10
- class PdfConvert < IsoDoc::PdfConvert
9
+ class PdfConvert < IsoDoc::XslfoPdfConvert
11
10
  def initialize(options)
12
11
  @libdir = File.dirname(__FILE__)
13
12
  super
14
13
  end
15
14
 
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"))
15
+ def pdf_stylesheet(docxml)
16
+ series = docxml&.at(ns("//bibdata/series/abbreviation"))&.text
17
+ series == "NIST CSWP" ? "nist.cswp.xsl" : "nist.sp.xsl"
30
18
  end
31
19
  end
32
20
  end
@@ -0,0 +1,80 @@
1
+ require_relative "init"
2
+ require "isodoc"
3
+
4
+ module IsoDoc
5
+ module NIST
6
+ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
7
+ def convert1(docxml, filename, dir)
8
+ info docxml, nil
9
+ insert_preface_sections(docxml)
10
+ super
11
+ end
12
+
13
+ def insert_preface_sections(docxml)
14
+ insert_keywords(docxml)
15
+ end
16
+
17
+ def wrap_brackets(txt)
18
+ return txt if /^\[.*\]$/.match txt
19
+ "[#{txt}]"
20
+ end
21
+
22
+ def get_linkend(node)
23
+ contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
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)
29
+ non_locality_elems(node).each { |n| n.remove }
30
+ node.add_child(link)
31
+ end
32
+
33
+ def annex1(f)
34
+ lbl = @xrefs.anchor(f['id'], :label)
35
+ if t = f.at(ns("./title"))
36
+ t.children = "<strong>#{t.children.to_xml}</strong>"
37
+ end
38
+ prefix_name(f, " &mdash; ", lbl, "title")
39
+ t = f.at(ns("./title"))
40
+ t["xref"] = lbl.gsub(/<[^>]+>/, "")
41
+ end
42
+
43
+ def keyword_clause(kw)
44
+ <<~END
45
+ <clause id="_#{UUIDTools::UUID.random_create}" type="keyword">
46
+ <title>#{@i18n.keywords}</title>
47
+ #{@i18n.keywords_intro}
48
+ <p>#{@i18n.l10n(kw.join("; "))}</p></clause>
49
+ END
50
+ end
51
+
52
+ def insert_keywords(docxml)
53
+ kw = @meta.get[:keywords]
54
+ kw.empty? and return
55
+ if abstract = docxml.at(ns("//preface/abstract"))
56
+ abstract.next = keyword_clause(kw)
57
+ elsif foreword = docxml.at(ns("//preface/foreword"))
58
+ foreword.next = keyword_clause(kw)
59
+ else
60
+ preface_init_insert_pt(docxml)&.children&.first&.
61
+ add_previous_sibling(keyword_clause(kw))
62
+ end
63
+ end
64
+
65
+ def preface_init_insert_pt(docxml)
66
+ docxml.at(ns("//preface")) ||
67
+ docxml.at(ns("//sections")).
68
+ add_previous_sibling("<preface> </preface>").first
69
+ end
70
+
71
+ def clause1(f)
72
+ return if f.name == "references" && suppress_biblio_title(f)
73
+ super
74
+ end
75
+
76
+ include Init
77
+ end
78
+ end
79
+ end
80
+
@@ -21,8 +21,7 @@ module IsoDoc
21
21
  end
22
22
 
23
23
  def reference_format(b, r)
24
- id = bibitem_ref_code(b)
25
- code = render_identifier(id)
24
+ code = render_identifier(bibitem_ref_code(b))
26
25
  if code[0]
27
26
  r << "#{code[0]} "
28
27
  insert_tab(r, 1)
@@ -35,7 +34,7 @@ module IsoDoc
35
34
  if ftitle = b.at(ns("./formattedref"))
36
35
  ftitle&.children&.each { |n| parse(n, r) }
37
36
  else
38
- title = b.at(ns("./title[@language = '#{@language}']")) || b.at(ns("./title"))
37
+ title = b.at(ns("./title[@language = '#{@lang}']")) || b.at(ns("./title"))
39
38
  r.i do |i|
40
39
  title&.children&.each { |n| parse(n, i) }
41
40
  end
@@ -54,6 +53,11 @@ module IsoDoc
54
53
  end
55
54
 
56
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
57
61
  bibitem = b.dup.to_xml
58
62
  r.parent.add_child ::Iso690Render.render(bibitem, true)
59
63
  end
@@ -62,9 +66,7 @@ module IsoDoc
62
66
  title = node&.at(ns("./title"))&.text || ""
63
67
  out.div do |div|
64
68
  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" }
69
+ clause_parse_title(node, div, node.at(ns("./title")), out)
68
70
  end
69
71
  biblio_list(node, div, true)
70
72
  end
@@ -76,25 +78,12 @@ module IsoDoc
76
78
  isoxml.xpath(ns("//bibliography/clause | //bibliography/references")).each do |f|
77
79
  out.div do |div|
78
80
  div.h1 **{ class: "Section3" } do |h1|
79
- if @bibliographycount == 1 then h1 << "References"
80
- else
81
81
  f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
82
- end
83
82
  end
84
83
  biblio_list(f, div, false)
85
84
  end
86
85
  end
87
86
  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
98
87
  end
99
88
  end
100
89
  end
@@ -212,7 +212,8 @@ module Iso690Render
212
212
  container = doc.at("./relation[@type='includedIn']")
213
213
  if container && !date(doc) && date(container&.at("./bibitem"))
214
214
  doc <<
215
- ( container&.at("./bibitem/date[@type = 'issued' or @type = 'published' or @type = 'circulated']")&.remove )
215
+ ( container&.at("./bibitem/date[@type = 'issued' or @type = 'published' or "\
216
+ "@type = 'circulated']")&.remove )
216
217
  end
217
218
  ser = series_title(doc)
218
219
  dr = draft(doc)
@@ -27,31 +27,6 @@ module Iso690Render
27
27
  date.sub(/^(\d\d\d\d).*$/, "\\1")
28
28
  end
29
29
 
30
- =begin
31
- def self.monthyr(isodate)
32
- return nil if isodate.nil?
33
- arr = isodate.split("-")
34
- date = if arr.size == 2
35
- DateTime.new(*arr.map(&:to_i))
36
- else
37
- DateTime.parse(isodate)
38
- end
39
- date.localize(:en).to_additional_s("yMMMM")
40
- end
41
-
42
- def self.mmddyyyy(isodate)
43
- return nil if isodate.nil?
44
- arr = isodate.split("-")
45
- date = if arr.size == 1 and (/^\d+$/.match isodate)
46
- Date.new(*arr.map(&:to_i)).strftime("%Y")
47
- elsif arr.size == 2
48
- Date.new(*arr.map(&:to_i)).strftime("%m-%Y")
49
- else
50
- Date.parse(isodate).strftime("%m-%d-%Y")
51
- end
52
- end
53
- =end
54
-
55
30
  def self.MMMddyyyy(isodate)
56
31
  return nil if isodate.nil?
57
32
  return isodate if isodate == "--"
@@ -3,14 +3,17 @@ module IsoDoc
3
3
  module BaseConvert
4
4
  def abstract(isoxml, out)
5
5
  f = isoxml.at(ns("//preface/abstract")) || return
6
- #page_break(out)
7
6
  out.div **attr_code(id: f["id"]) do |s|
8
- clause_name(nil, @abstract_lbl, s, class: "AbstractTitle")
7
+ clause_name(nil, f.at(ns("./title")) || @i18n.abstract, s,
8
+ class: "AbstractTitle")
9
9
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
10
10
  end
11
11
  end
12
12
 
13
- # All "[preface]" sections should have class "IntroTitle" to prevent
13
+ FRONT_CLAUSE = "//*[parent::preface][not(local-name() = 'abstract' or "\
14
+ "local-name() = 'foreword') or @type = 'keyword']".freeze
15
+
16
+ # All "[preface]" sections should have class "IntroTitle" to prevent
14
17
  # page breaks, but for the Exec Summary
15
18
  def preface(isoxml, out)
16
19
  isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
@@ -25,7 +28,7 @@ module IsoDoc
25
28
  def preface1(c, title, patent, out)
26
29
  out.div **attr_code(id: c["id"]) do |s|
27
30
  page_break(s) if patent
28
- clause_name(anchor(c['id'], :label), title, s,
31
+ clause_name(nil, title, s,
29
32
  class: (c.name == "executivesummary") ? "NormalTitle" :
30
33
  "IntroTitle")
31
34
  c.elements.reject { |c1| c1.name == "title" }.each do |c1|
@@ -34,13 +37,13 @@ module IsoDoc
34
37
  end
35
38
  end
36
39
 
37
- def middle(isoxml, out)
40
+ def middle(isoxml, out)
38
41
  clause isoxml, out
39
42
  bibliography isoxml, out
40
43
  annex isoxml, out
41
44
  end
42
45
 
43
- def foreword(isoxml, out)
46
+ def foreword(isoxml, out)
44
47
  f = isoxml.at(ns("//foreword")) || return
45
48
  out.div **attr_code(id: f["id"]) do |s|
46
49
  title = f.at(ns("./title"))
@@ -1,8 +1,8 @@
1
1
  require "isodoc"
2
2
  require_relative "metadata"
3
3
  require "fileutils"
4
- require "sassc"
5
4
  require_relative "base_convert"
5
+ require_relative "init"
6
6
  require_relative "word_convert_toc"
7
7
 
8
8
  module IsoDoc
@@ -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|
@@ -68,7 +64,6 @@ module IsoDoc
68
64
  info docxml, div2
69
65
  foreword docxml, div2
70
66
  abstract docxml, div2
71
- keywords docxml, div2
72
67
  boilerplate docxml, div2
73
68
  preface docxml, div2
74
69
  div2.p { |p| p << "&nbsp;" } # placeholder
@@ -77,11 +72,13 @@ module IsoDoc
77
72
  end
78
73
 
79
74
  def authority_cleanup(docxml)
80
- docxml.xpath("//div[@class = 'authority']//h1 | //div[@class = 'authority']//h2").each do |h|
81
- h.name = p
75
+ docxml&.xpath("//div[@class = 'authority']//h1 | "\
76
+ "//div[@class = 'authority']//h2")&.each do |h|
77
+ h.name = "p"
82
78
  h["class"] = "IntroTitle"
83
79
  end
84
- dest1 = docxml.xpath("//div[@class = 'authority6' and not(@id = 'authority6')]")
80
+ dest1 = docxml.xpath("//div[@class = 'authority6' and "\
81
+ "not(@id = 'authority6')]")
85
82
  auth1 = docxml&.at("//div[@id = 'authority6']")&.remove
86
83
  dest1 and auth1 and dest1.each { |d| d.replace(auth1) }
87
84
  insert = docxml.at("//div[@class = 'WordSection2']")
@@ -155,16 +152,6 @@ module IsoDoc
155
152
  docxml
156
153
  end
157
154
 
158
- def keywords(_docxml, out)
159
- kw = @meta.get[:keywords]
160
- kw.empty? and return
161
- #out.div **{ class: "Section3" } do |div|
162
- out.div do |div|
163
- clause_name(nil, "Keywords", div, class: "IntroTitle")
164
- div.p kw.sort.join("; ")
165
- end
166
- end
167
-
168
155
  def termdef_parse(node, out)
169
156
  out.table **{ class: "terms_dl" } do |dl|
170
157
  dl.tr do |tr|
@@ -179,6 +166,7 @@ module IsoDoc
179
166
  end
180
167
 
181
168
  include BaseConvert
169
+ include Init
182
170
  end
183
171
  end
184
172
  end
@@ -35,7 +35,7 @@ module IsoDoc
35
35
  <span lang="EN-GB"><span
36
36
  style='mso-element:field-begin'></span><span
37
37
  style='mso-spacerun:yes'>&#xA0;</span>TOC
38
- \\h \\z \\t &quot;TableTitle,1&quot; <span
38
+ \\h \\z \\t &quot;TableTitle,tabletitle&quot; <span
39
39
  style='mso-element:field-separator'></span></span>
40
40
  TOC
41
41
 
@@ -43,7 +43,7 @@ module IsoDoc
43
43
  <span lang="EN-GB"><span
44
44
  style='mso-element:field-begin'></span><span
45
45
  style='mso-spacerun:yes'>&#xA0;</span>TOC
46
- \\h \\z \\t &quot;FigureTitle,1&quot; <span
46
+ \\h \\z \\t &quot;FigureTitle,figuretitle&quot; <span
47
47
  style='mso-element:field-separator'></span></span>
48
48
  TOC
49
49
 
@@ -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,35 +50,12 @@ module IsoDoc
50
50
  end
51
51
 
52
52
  def annex_name_lbl(clause, num)
53
- l10n("<b>#{@annex_lbl} #{num}</b>")
54
- end
55
-
56
- def annex_name(annex, name, div)
57
- div.h1 **{ class: "Annex" } do |t|
58
- t << "#{anchor(annex['id'], :label)} &mdash; "
59
- t.b do |b|
60
- if @bibliographycount == 1 && annex.at(ns("./references"))
61
- b << "References"
62
- else
63
- name&.children&.each { |c2| parse(c2, b) }
64
- end
65
- end
66
- end
53
+ l10n("<strong>#{@labels['annex']} #{num}</strong>")
67
54
  end
68
55
 
69
56
  def hiersep
70
57
  "-"
71
58
  end
72
-
73
- def terms_parse(node, out)
74
- out.div **attr_code(id: node["id"]) do |div|
75
- node.at(ns("./title")) and
76
- clause_parse_title(node, div, node.at(ns("./title")), out)
77
- node.elements.each do |e|
78
- parse(e, div) unless %w{title source}.include? e.name
79
- end
80
- end
81
- end
82
59
  end
83
60
  end
84
61
  end
@@ -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
@@ -29,18 +29,16 @@ module Metanorma
29
29
  "Metanorma::NIST #{Metanorma::NIST::VERSION}"
30
30
  end
31
31
 
32
- def input_to_isodoc(file, filename)
33
- Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
34
- end
35
-
36
- def output(isodoc_node, outname, format, options={})
32
+ def output(isodoc_node, inname, outname, format, options={})
37
33
  case format
38
34
  when :html
39
- IsoDoc::NIST::HtmlConvert.new(options).convert(outname, isodoc_node)
35
+ IsoDoc::NIST::HtmlConvert.new(options).convert(inname, isodoc_node, nil, outname)
40
36
  when :doc
41
- IsoDoc::NIST::WordConvert.new(options).convert(outname, isodoc_node)
37
+ IsoDoc::NIST::WordConvert.new(options).convert(inname, isodoc_node, nil, outname)
42
38
  when :pdf
43
- IsoDoc::NIST::PdfConvert.new(options).convert(outname, isodoc_node)
39
+ IsoDoc::NIST::PdfConvert.new(options).convert(inname, isodoc_node, nil, outname)
40
+ when :presentation
41
+ IsoDoc::NIST::PresentationXMLConvert.new(options).convert(inname, isodoc_node, nil, outname)
44
42
  else
45
43
  super
46
44
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module NIST
3
- VERSION = "1.0.10"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end