metanorma-nist 1.1.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +14 -0
  3. data/lib/asciidoctor/nist/basicdoc.rng +23 -0
  4. data/lib/asciidoctor/nist/boilerplate.rb +2 -2
  5. data/lib/asciidoctor/nist/cleanup.rb +34 -4
  6. data/lib/asciidoctor/nist/converter.rb +20 -6
  7. data/lib/asciidoctor/nist/front.rb +37 -46
  8. data/lib/asciidoctor/nist/front_id.rb +1 -1
  9. data/lib/asciidoctor/nist/isodoc.rng +137 -21
  10. data/lib/asciidoctor/nist/nist.rng +26 -1
  11. data/lib/asciidoctor/nist/validate.rb +16 -9
  12. data/lib/isodoc/nist/base_convert.rb +26 -75
  13. data/lib/isodoc/nist/html/nist.css +22 -10
  14. data/lib/isodoc/nist/html/nist.scss +24 -10
  15. data/lib/isodoc/nist/html/nist_cswp.css +21 -9
  16. data/lib/isodoc/nist/html/nist_cswp.scss +23 -9
  17. data/lib/isodoc/nist/html/wordstyle.css +83 -3
  18. data/lib/isodoc/nist/html/wordstyle.scss +74 -3
  19. data/lib/isodoc/nist/html/wordstyle_cswp.css +77 -2
  20. data/lib/isodoc/nist/html/wordstyle_cswp.scss +68 -2
  21. data/lib/isodoc/nist/html_convert.rb +3 -0
  22. data/lib/isodoc/nist/i18n-en.yaml +3 -0
  23. data/lib/isodoc/nist/i18n.rb +10 -0
  24. data/lib/isodoc/nist/init.rb +37 -0
  25. data/lib/isodoc/nist/metadata_id.rb +3 -1
  26. data/lib/isodoc/nist/nist.cswp.xsl +1954 -2232
  27. data/lib/isodoc/nist/nist.sp.xsl +2176 -2217
  28. data/lib/isodoc/nist/pdf_convert.rb +0 -1
  29. data/lib/isodoc/nist/presentation_xml_convert.rb +71 -1
  30. data/lib/isodoc/nist/refs.rb +2 -17
  31. data/lib/isodoc/nist/render.rb +2 -1
  32. data/lib/isodoc/nist/render_contributors.rb +1 -1
  33. data/lib/isodoc/nist/render_dates.rb +0 -25
  34. data/lib/isodoc/nist/section.rb +26 -13
  35. data/lib/isodoc/nist/word_convert.rb +47 -13
  36. data/lib/isodoc/nist/xref.rb +1 -24
  37. data/lib/metanorma/nist/version.rb +1 -1
  38. data/metanorma-nist.gemspec +2 -2
  39. metadata +8 -6
@@ -1,5 +1,4 @@
1
1
  require "isodoc"
2
- require_relative "metadata"
3
2
  require "fileutils"
4
3
  require_relative "base_convert"
5
4
 
@@ -1,9 +1,79 @@
1
- require_relative "base_convert"
1
+ require_relative "init"
2
2
  require "isodoc"
3
3
 
4
4
  module IsoDoc
5
5
  module NIST
6
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
7
77
  end
8
78
  end
9
79
  end
@@ -34,7 +34,7 @@ module IsoDoc
34
34
  if ftitle = b.at(ns("./formattedref"))
35
35
  ftitle&.children&.each { |n| parse(n, r) }
36
36
  else
37
- title = b.at(ns("./title[@language = '#{@language}']")) || b.at(ns("./title"))
37
+ title = b.at(ns("./title[@language = '#{@lang}']")) || b.at(ns("./title"))
38
38
  r.i do |i|
39
39
  title&.children&.each { |n| parse(n, i) }
40
40
  end
@@ -66,9 +66,7 @@ module IsoDoc
66
66
  title = node&.at(ns("./title"))&.text || ""
67
67
  out.div do |div|
68
68
  unless suppress_biblio_title(node)
69
- @xrefs.anchor(node['id'], :label, false) and
70
- clause_parse_title(node, div, node.at(ns("./title")), out) or
71
- div.h2 title, **{ class: "Section3" }
69
+ clause_parse_title(node, div, node.at(ns("./title")), out)
72
70
  end
73
71
  biblio_list(node, div, true)
74
72
  end
@@ -80,25 +78,12 @@ module IsoDoc
80
78
  isoxml.xpath(ns("//bibliography/clause | //bibliography/references")).each do |f|
81
79
  out.div do |div|
82
80
  div.h1 **{ class: "Section3" } do |h1|
83
- if @bibliographycount == 1 then h1 << "References"
84
- else
85
81
  f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
86
- end
87
82
  end
88
83
  biblio_list(f, div, false)
89
84
  end
90
85
  end
91
86
  end
92
-
93
- def suppress_biblio_title(node)
94
- return false unless node.parent.name == "annex"
95
- return false if node.parent.xpath("./references | ./clause | "\
96
- "./terms | ./definitions").size > 1
97
- title1 = node&.at(ns("./title"))&.text
98
- return true unless title1
99
- title2 = node&.parent&.at(ns("./title"))&.text
100
- title1&.casecmp(title2) == 0
101
- end
102
87
  end
103
88
  end
104
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)
@@ -37,7 +37,7 @@ module Iso690Render
37
37
  completename = person.at("./name/completename")
38
38
  return completename.text if completename
39
39
  surname = person.at("./name/surname")
40
- initials = person.xpath("./name/initials")
40
+ initials = person.xpath("./name/initial")
41
41
  forenames = person.xpath("./name/forename")
42
42
  #given = []
43
43
  #forenames.each { |x| given << x.text }
@@ -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 == "--"
@@ -1,20 +1,35 @@
1
1
  module IsoDoc
2
2
  module NIST
3
3
  module BaseConvert
4
+ def keywords(docxml, out)
5
+ f = docxml.at(ns("//preface/clause[@type = 'keyword']")) || return
6
+ preface1(f, f&.at(ns("./title")), false, out)
7
+ end
8
+
9
+ def skip_render(c, isoxml)
10
+ return false unless c.name == "reviewernote"
11
+ status = isoxml&.at(ns("//bibdata/status/stage"))&.text
12
+ return true if status.nil?
13
+ /^final/.match status
14
+ end
15
+
4
16
  def abstract(isoxml, out)
5
17
  f = isoxml.at(ns("//preface/abstract")) || return
6
- #page_break(out)
7
18
  out.div **attr_code(id: f["id"]) do |s|
8
- clause_name(nil, @abstract_lbl, s, class: "AbstractTitle")
19
+ clause_name(nil, f.at(ns("./title")) || @i18n.abstract, s,
20
+ class: "AbstractTitle")
9
21
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
10
22
  end
11
23
  end
12
24
 
13
- # All "[preface]" sections should have class "IntroTitle" to prevent
25
+ FRONT_CLAUSE = "//*[parent::preface][not(local-name() = 'abstract' or "\
26
+ "local-name() = 'foreword' or @type = 'keyword')]".freeze
27
+
28
+ # All "[preface]" sections should have class "IntroTitle" to prevent
14
29
  # page breaks, but for the Exec Summary
15
30
  def preface(isoxml, out)
16
31
  isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
17
- next if skip_render(c, isoxml)
32
+ next if skip_render(c, isoxml) || !is_clause?(c.name)
18
33
  title = c&.at(ns("./title"))
19
34
  patent = ["Call for Patent Claims",
20
35
  "Patent Disclosure Notice"].include? title&.text
@@ -25,7 +40,7 @@ module IsoDoc
25
40
  def preface1(c, title, patent, out)
26
41
  out.div **attr_code(id: c["id"]) do |s|
27
42
  page_break(s) if patent
28
- clause_name(@xrefs.anchor(c['id'], :label), title, s,
43
+ clause_name(nil, title, s,
29
44
  class: (c.name == "executivesummary") ? "NormalTitle" :
30
45
  "IntroTitle")
31
46
  c.elements.reject { |c1| c1.name == "title" }.each do |c1|
@@ -34,14 +49,7 @@ module IsoDoc
34
49
  end
35
50
  end
36
51
 
37
- def middle(isoxml, out)
38
- clause isoxml, out
39
- require "byebug"; byebug
40
- bibliography isoxml, out
41
- annex isoxml, out
42
- end
43
-
44
- def foreword(isoxml, out)
52
+ def foreword(isoxml, out)
45
53
  f = isoxml.at(ns("//foreword")) || return
46
54
  out.div **attr_code(id: f["id"]) do |s|
47
55
  title = f.at(ns("./title"))
@@ -51,6 +59,11 @@ module IsoDoc
51
59
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
52
60
  end
53
61
  end
62
+
63
+ def is_clause?(name)
64
+ return true if %w(reviewernote executivesummary).include? name
65
+ super
66
+ end
54
67
  end
55
68
  end
56
69
  end
@@ -2,6 +2,7 @@ require "isodoc"
2
2
  require_relative "metadata"
3
3
  require "fileutils"
4
4
  require_relative "base_convert"
5
+ require_relative "init"
5
6
  require_relative "word_convert_toc"
6
7
 
7
8
  module IsoDoc
@@ -13,6 +14,10 @@ module IsoDoc
13
14
  def initialize(options)
14
15
  @libdir = File.dirname(__FILE__)
15
16
  super
17
+ @wordToClevels = options[:doctoclevels].to_i
18
+ @wordToClevels = 3 if @wordToClevels.zero?
19
+ @htmlToClevels = options[:htmltoclevels].to_i
20
+ @htmlToClevels = 3 if @htmlToClevels.zero?
16
21
  end
17
22
 
18
23
  def convert1(docxml, filename, dir)
@@ -61,6 +66,7 @@ module IsoDoc
61
66
  body.div **{ class: "WordSection2" } do |div2|
62
67
  @prefacenum = 0
63
68
  info docxml, div2
69
+ preface_block docxml, div2
64
70
  foreword docxml, div2
65
71
  abstract docxml, div2
66
72
  keywords docxml, div2
@@ -71,12 +77,32 @@ module IsoDoc
71
77
  section_break(body)
72
78
  end
73
79
 
80
+ def toWord(result, filename, dir, header)
81
+ result = populate_template(result, :word)
82
+ result = from_xhtml(word_cleanup(to_xhtml(result)))
83
+ unless @landscapestyle.nil? || @landscapestyle.empty?
84
+ @wordstylesheet&.open
85
+ @wordstylesheet&.write(@landscapestyle)
86
+ @wordstylesheet&.close
87
+ end
88
+ Html2Doc.process(result, filename: filename,
89
+ stylesheet: @wordstylesheet&.path,
90
+ header_file: header&.path, dir: dir,
91
+ asciimathdelims: [@openmathdelim, @closemathdelim],
92
+ liststyles: { ul: @ulstyle, ol: @olstyle,
93
+ steps: "l4" })
94
+ header&.unlink
95
+ @wordstylesheet&.unlink
96
+ end
97
+
74
98
  def authority_cleanup(docxml)
75
- docxml.xpath("//div[@class = 'authority']//h1 | //div[@class = 'authority']//h2").each do |h|
76
- h.name = p
99
+ docxml&.xpath("//div[@class = 'authority']//h1 | "\
100
+ "//div[@class = 'authority']//h2")&.each do |h|
101
+ h.name = "p"
77
102
  h["class"] = "IntroTitle"
78
103
  end
79
- dest1 = docxml.xpath("//div[@class = 'authority6' and not(@id = 'authority6')]")
104
+ dest1 = docxml.xpath("//div[@class = 'authority6' and "\
105
+ "not(@id = 'authority6')]")
80
106
  auth1 = docxml&.at("//div[@id = 'authority6']")&.remove
81
107
  dest1 and auth1 and dest1.each { |d| d.replace(auth1) }
82
108
  insert = docxml.at("//div[@class = 'WordSection2']")
@@ -123,6 +149,7 @@ module IsoDoc
123
149
  end
124
150
 
125
151
  def word_annex_cleanup(docxml)
152
+ word_annex_cleanup1(docxml, 1)
126
153
  word_annex_cleanup1(docxml, 2)
127
154
  word_annex_cleanup1(docxml, 3)
128
155
  word_annex_cleanup1(docxml, 4)
@@ -150,16 +177,6 @@ module IsoDoc
150
177
  docxml
151
178
  end
152
179
 
153
- def keywords(_docxml, out)
154
- kw = @meta.get[:keywords]
155
- kw.empty? and return
156
- #out.div **{ class: "Section3" } do |div|
157
- out.div do |div|
158
- clause_name(nil, "Keywords", div, class: "IntroTitle")
159
- div.p kw.sort.join("; ")
160
- end
161
- end
162
-
163
180
  def termdef_parse(node, out)
164
181
  out.table **{ class: "terms_dl" } do |dl|
165
182
  dl.tr do |tr|
@@ -173,7 +190,24 @@ module IsoDoc
173
190
  end
174
191
  end
175
192
 
193
+ def glossary_parse(node, out)
194
+ out.table **attr_code(id: node["id"], class: "terms_dl") do |t|
195
+ node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
196
+ t.tr do |v|
197
+ v.td **attr_code(id: dt["id"], valign: "top", align: "left") do |term|
198
+ dt_parse(dt, term)
199
+ end
200
+ v.td **attr_code(id: dd["id"], valign: "top") do |listitem|
201
+ dd.children.each { |n| parse(n, listitem) }
202
+ end
203
+ end
204
+ end
205
+ end
206
+ node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, out) }
207
+ end
208
+
176
209
  include BaseConvert
210
+ include Init
177
211
  end
178
212
  end
179
213
  end
@@ -50,35 +50,12 @@ module IsoDoc
50
50
  end
51
51
 
52
52
  def annex_name_lbl(clause, num)
53
- l10n("<b>#{@labels['annex']} #{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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module NIST
3
- VERSION = "1.1.3"
3
+ VERSION = "1.2.4"
4
4
  end
5
5
  end
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "iso-639"
31
31
  spec.add_dependency "tzinfo-data" # we need this for windows only
32
32
 
33
- spec.add_dependency "metanorma-standoc", "~> 1.4.0"
34
- spec.add_dependency "isodoc", "~> 1.1.0"
33
+ spec.add_dependency "metanorma-standoc", "~> 1.6.0"
34
+ spec.add_dependency "isodoc", "~> 1.2.0"
35
35
  #spec.add_dependency "relaton-nist", "~> 0.3.0"
36
36
 
37
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.1.3
4
+ version: 1.2.4
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-07-26 00:00:00.000000000 Z
11
+ date: 2020-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.4.0
89
+ version: 1.6.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.4.0
96
+ version: 1.6.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isodoc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.1.0
103
+ version: 1.2.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.1.0
110
+ version: 1.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: byebug
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -313,6 +313,8 @@ files:
313
313
  - lib/isodoc/nist/html/wordstyle_cswp.scss
314
314
  - lib/isodoc/nist/html_convert.rb
315
315
  - lib/isodoc/nist/i18n-en.yaml
316
+ - lib/isodoc/nist/i18n.rb
317
+ - lib/isodoc/nist/init.rb
316
318
  - lib/isodoc/nist/metadata.rb
317
319
  - lib/isodoc/nist/metadata_id.rb
318
320
  - lib/isodoc/nist/nist.cswp.xsl