metanorma-nist 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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)
@@ -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(@xrefs.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,14 +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
- require "byebug"; byebug
40
42
  bibliography isoxml, out
41
43
  annex isoxml, out
42
44
  end
43
45
 
44
- def foreword(isoxml, out)
46
+ def foreword(isoxml, out)
45
47
  f = isoxml.at(ns("//foreword")) || return
46
48
  out.div **attr_code(id: f["id"]) do |s|
47
49
  title = f.at(ns("./title"))
@@ -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
@@ -63,7 +64,6 @@ module IsoDoc
63
64
  info docxml, div2
64
65
  foreword docxml, div2
65
66
  abstract docxml, div2
66
- keywords docxml, div2
67
67
  boilerplate docxml, div2
68
68
  preface docxml, div2
69
69
  div2.p { |p| p << "&nbsp;" } # placeholder
@@ -72,11 +72,13 @@ module IsoDoc
72
72
  end
73
73
 
74
74
  def authority_cleanup(docxml)
75
- docxml.xpath("//div[@class = 'authority']//h1 | //div[@class = 'authority']//h2").each do |h|
76
- h.name = p
75
+ docxml&.xpath("//div[@class = 'authority']//h1 | "\
76
+ "//div[@class = 'authority']//h2")&.each do |h|
77
+ h.name = "p"
77
78
  h["class"] = "IntroTitle"
78
79
  end
79
- dest1 = docxml.xpath("//div[@class = 'authority6' and not(@id = 'authority6')]")
80
+ dest1 = docxml.xpath("//div[@class = 'authority6' and "\
81
+ "not(@id = 'authority6')]")
80
82
  auth1 = docxml&.at("//div[@id = 'authority6']")&.remove
81
83
  dest1 and auth1 and dest1.each { |d| d.replace(auth1) }
82
84
  insert = docxml.at("//div[@class = 'WordSection2']")
@@ -150,16 +152,6 @@ module IsoDoc
150
152
  docxml
151
153
  end
152
154
 
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
155
  def termdef_parse(node, out)
164
156
  out.table **{ class: "terms_dl" } do |dl|
165
157
  dl.tr do |tr|
@@ -174,6 +166,7 @@ module IsoDoc
174
166
  end
175
167
 
176
168
  include BaseConvert
169
+ include Init
177
170
  end
178
171
  end
179
172
  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.0"
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.5.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.0
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-07-29 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.5.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.5.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