metanorma-ogc 1.0.4 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +8 -7
  3. data/.github/workflows/ubuntu.yml +12 -9
  4. data/.github/workflows/windows.yml +8 -8
  5. data/lib/asciidoctor/ogc/biblio.rng +143 -38
  6. data/lib/asciidoctor/ogc/boilerplate.xml +7 -22
  7. data/lib/asciidoctor/ogc/converter.rb +5 -10
  8. data/lib/asciidoctor/ogc/isodoc.rng +475 -2
  9. data/lib/asciidoctor/ogc/ogc.rng +0 -4
  10. data/lib/asciidoctor/ogc/reqt.rng +23 -0
  11. data/lib/isodoc/ogc/base_convert.rb +1 -5
  12. data/lib/isodoc/ogc/biblio.rb +6 -5
  13. data/lib/isodoc/ogc/html/html_ogc_titlepage.html +2 -6
  14. data/lib/isodoc/ogc/html/scripts.html +14 -27
  15. data/lib/isodoc/ogc/html/word_ogc_titlepage.html +13 -4
  16. data/lib/isodoc/ogc/html_convert.rb +1 -0
  17. data/lib/isodoc/ogc/metadata.rb +0 -8
  18. data/lib/isodoc/ogc/ogc.abstract-specification-topic.xsl +3387 -0
  19. data/lib/isodoc/ogc/ogc.best-practice.xsl +3387 -0
  20. data/lib/isodoc/ogc/ogc.change-request-supporting-document.xsl +3387 -0
  21. data/lib/isodoc/ogc/ogc.community-practice.xsl +3387 -0
  22. data/lib/isodoc/ogc/ogc.community-standard.xsl +3387 -0
  23. data/lib/isodoc/ogc/ogc.discussion-paper.xsl +3387 -0
  24. data/lib/isodoc/ogc/ogc.engineering-report.xsl +3387 -0
  25. data/lib/isodoc/ogc/ogc.other.xsl +3387 -0
  26. data/lib/isodoc/ogc/ogc.policy.xsl +3387 -0
  27. data/lib/isodoc/ogc/ogc.reference-model.xsl +3387 -0
  28. data/lib/isodoc/ogc/ogc.release-notes.xsl +3387 -0
  29. data/lib/isodoc/ogc/ogc.standard.xsl +3387 -0
  30. data/lib/isodoc/ogc/ogc.test-suite.xsl +3387 -0
  31. data/lib/isodoc/ogc/ogc.user-guide.xsl +3387 -0
  32. data/lib/isodoc/ogc/ogc.white-paper.xsl +3387 -0
  33. data/lib/isodoc/ogc/pdf_convert.rb +18 -77
  34. data/lib/isodoc/ogc/reqt.rb +50 -125
  35. data/lib/isodoc/ogc/reqt_xref.rb +96 -0
  36. data/lib/isodoc/ogc/word_convert.rb +4 -8
  37. data/lib/metanorma/ogc/processor.rb +8 -0
  38. data/lib/metanorma/ogc/version.rb +1 -1
  39. data/metanorma-ogc.gemspec +1 -1
  40. metadata +20 -5
  41. data/lib/isodoc/ogc/html/scripts.pdf.html +0 -72
@@ -1,96 +1,37 @@
1
1
  require_relative "base_convert"
2
- require "fileutils"
3
2
  require "isodoc"
4
- require_relative "metadata"
5
3
 
6
4
  module IsoDoc
7
5
  module Ogc
8
6
  # A {Converter} implementation that generates PDF HTML output, and a
9
7
  # document schema encapsulation of the document for validation
10
- class PdfConvert < IsoDoc::PdfConvert
8
+ class PdfConvert < IsoDoc::XslfoPdfConvert
11
9
  def initialize(options)
12
10
  @libdir = File.dirname(__FILE__)
13
11
  super
14
- #FileUtils.cp html_doc_path('logo.jpg'), "logo.jpg"
15
- #@files_to_delete << "logo.jpg"
16
12
  end
17
13
 
18
- def default_fonts(options)
19
- {
20
- bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Overpass",sans-serif'),
21
- headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Overpass",sans-serif'),
22
- monospacefont: '"Space Mono",monospace'
23
- }
14
+ def pdf_stylesheet(docxml)
15
+ doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text
16
+ doctype = "other" unless %w(abstract-specification-topic best-practice
17
+ change-request-supporting-document community-practice community-standard
18
+ discussion-paper engineering-report policy reference-model release-notes
19
+ standard user-guide test-suite white-paper).include? doctype
20
+ "ogc.#{doctype}.xsl"
24
21
  end
25
22
 
26
- def default_file_locations(_options)
27
- {
28
- htmlstylesheet: html_doc_path("htmlstyle.scss"),
29
- htmlcoverpage: html_doc_path("html_ogc_titlepage.html"),
30
- htmlintropage: html_doc_path("html_ogc_intro.html"),
31
- scripts_pdf: html_doc_path("scripts.pdf.html"),
32
- }
33
- end
34
-
35
- def metadata_init(lang, script, labels)
36
- @meta = Metadata.new(lang, script, labels)
37
- end
38
-
39
- def googlefonts
40
- <<~HEAD.freeze
41
- <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet" />
42
- <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet" />
43
- <link href="https://fonts.googleapis.com/css?family=Teko:300,400,500" rel="stylesheet">
44
- HEAD
45
- end
46
-
47
- def admonition_class(node)
48
- case node["type"]
49
- when "important" then "Admonition.Important"
50
- when "warning" then "Admonition.Warning"
51
- else
52
- "Admonition"
23
+ def convert(filename, file = nil, debug = false)
24
+ file = File.read(filename, encoding: "utf-8") if file.nil?
25
+ docxml, outname_html, dir = convert_init(file, filename, debug)
26
+ /\.xml$/.match(filename) or
27
+ filename = Tempfile.open([outname_html, ".xml"], encoding: "utf-8") do |f|
28
+ f.write file
29
+ f.path
53
30
  end
31
+ FileUtils.rm_rf dir
32
+ ::Metanorma::Output::XslfoPdf.new.convert(
33
+ filename, outname_html + ".pdf", File.join(@libdir, pdf_stylesheet(docxml)))
54
34
  end
55
-
56
- def make_body(xml, docxml)
57
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
58
- xml.body **body_attr do |body|
59
- make_body1(body, docxml)
60
- make_body2(body, docxml)
61
- make_body3(body, docxml)
62
- end
63
- end
64
-
65
- def html_toc(docxml)
66
- docxml
67
- end
68
-
69
- def make_body3(body, docxml)
70
- body.div **{ class: "main-section" } do |div3|
71
- @prefacenum = 0
72
- boilerplate docxml, div3
73
- abstract docxml, div3
74
- keywords docxml, div3
75
- foreword docxml, div3
76
- introduction docxml, div3
77
- submittingorgs docxml, div3
78
- submitters docxml, div3
79
- preface docxml, div3
80
- acknowledgements docxml, div3
81
- middle docxml, div3
82
- footnotes div3
83
- comments div3
84
- end
85
- end
86
-
87
- def authority_cleanup(docxml)
88
- authority_cleanup1(docxml, "contact")
89
- super
90
- end
91
-
92
- include BaseConvert
93
35
  end
94
36
  end
95
37
  end
96
-
@@ -1,6 +1,5 @@
1
1
  require "isodoc"
2
- require_relative "metadata"
3
- require "fileutils"
2
+ require_relative "reqt_xref"
4
3
 
5
4
  module IsoDoc
6
5
  module Ogc
@@ -14,27 +13,38 @@ module IsoDoc
14
13
  end
15
14
 
16
15
  def recommend_table_attr(node)
17
- attr_code(id: node["id"],
18
- class: recommend_class(node),
19
- style: "border-collapse:collapse;border-spacing:0;")
16
+ attr_code(id: node["id"], class: recommend_class(node),
17
+ style: "border-collapse:collapse;border-spacing:0;"\
18
+ "#{keep_style(node)}")
20
19
  end
21
20
 
22
21
  REQ_TBL_ATTR =
23
22
  { style: "vertical-align:top;", class: "recommend" }.freeze
24
23
 
24
+ def recommendation_class(node)
25
+ %w(verification abstracttest).include?(node["type"]) ?
26
+ "RecommendationTestTitle" : "RecommendationTitle"
27
+ end
28
+
25
29
  def recommendation_name(node, out, type)
26
30
  label, title, lbl = recommendation_labels(node)
27
- out.p **{ class: %w(verification abstracttest).include?(node["type"]) ?
28
- "RecommendationTestTitle" : "RecommendationTitle" } do |b|
29
- lbl = anchor(node['id'], :label, false)
30
- b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:"))
31
- if title
32
- b << " "
33
- title.children.each { |n| parse(n,b) }
31
+ out.p **{ class: recommendation_class(node) } do |b|
32
+ if inject_crossreference_reqt?(node, label)
33
+ lbl = anchor(@reqtlabels[label.text], :xref, false)
34
+ b << (lbl.nil? ? l10n("#{type}:") : l10n("#{lbl}:"))
35
+ else
36
+ b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:"))
34
37
  end
38
+ recommendation_name1(title, node, label, b)
35
39
  end
36
40
  end
37
41
 
42
+ def recommendation_name1(title, node, label, b)
43
+ return unless title && !inject_crossreference_reqt?(node, label)
44
+ b << " "
45
+ title.children.each { |n| parse(n,b) }
46
+ end
47
+
38
48
  def recommend_title(node, out)
39
49
  label = node.at(ns("./label")) or return
40
50
  out.tr do |tr|
@@ -46,6 +56,12 @@ module IsoDoc
46
56
  end
47
57
  end
48
58
 
59
+ # embedded reqts xref to top level reqts via label lookup
60
+ def inject_crossreference_reqt?(node, label)
61
+ !node.ancestors("requirement, recommendation, permission").empty? &&
62
+ @reqtlabels[label&.text]
63
+ end
64
+
49
65
  def recommendation_attributes1(node)
50
66
  out = []
51
67
  oblig = node["obligation"] and out << ["Obligation", oblig]
@@ -61,7 +77,7 @@ module IsoDoc
61
77
 
62
78
  def rec_subj(node)
63
79
  %w(class conformanceclass).include?(node["type"]) ?
64
- "Target Type" : "Subject"
80
+ "Target Type" : "Subject"
65
81
  end
66
82
 
67
83
  def recommendation_attr_parse(node, label)
@@ -78,9 +94,7 @@ module IsoDoc
78
94
  end
79
95
 
80
96
  def recommendation_attributes(node, out)
81
- ret = recommendation_attributes1(node)
82
- return if ret.empty?
83
- ret.each do |i|
97
+ recommendation_attributes1(node).each do |i|
84
98
  out.tr do |tr|
85
99
  tr.td **REQ_TBL_ATTR do |td|
86
100
  td << i[0]
@@ -92,12 +106,17 @@ module IsoDoc
92
106
  end
93
107
  end
94
108
 
109
+ def reqt_component_attrs(node)
110
+ attr_code(style: keep_style(node))
111
+ end
112
+
95
113
  def requirement_component_parse(node, out)
96
114
  return if node["exclude"] == "true"
97
115
  node.elements.size == 1 && node.first_element_child.name == "dl" and
98
116
  return reqt_dl(node.first_element_child, out)
99
117
  out.tr do |tr|
100
- tr.td **REQ_TBL_ATTR.merge(colspan: 2) do |td|
118
+ tr.td **REQ_TBL_ATTR.merge(colspan: 2).
119
+ merge(reqt_component_attrs(node)) do |td|
101
120
  node.children.each { |n| parse(n, td) }
102
121
  end
103
122
  end
@@ -141,125 +160,31 @@ module IsoDoc
141
160
  end
142
161
 
143
162
  def recommendation_parse(node, out)
144
- label = case node["type"]
145
- when "verification" then @labels["recommendationtest"]
146
- when "class" then @labels["recommendationclass"]
147
- when "abstracttest" then @labels["abstracttest"]
148
- when "conformanceclass" then @labels["conformanceclass"]
149
- else
150
- @recommendation_lbl
151
- end
152
- recommendation_parse1(node, out, label)
153
- end
154
-
155
- def requirement_parse(node, out)
156
- label = case node["type"]
157
- when "verification" then @labels["requirementtest"]
158
- when "class" then @labels["requirementclass"]
159
- when "abstracttest" then @labels["abstracttest"]
160
- when "conformanceclass" then @labels["conformanceclass"]
161
- else
162
- @requirement_lbl
163
- end
164
- recommendation_parse1(node, out, label)
163
+ recommendation_parse0(node, out, "recommendation")
165
164
  end
166
165
 
167
- def permission_parse(node, out)
166
+ def recommendation_parse0(node, out, r)
168
167
  label = case node["type"]
169
- when "verification" then @labels["permissiontest"]
170
- when "class" then @labels["permissionclass"]
168
+ when "verification" then @labels["#{r}test"]
169
+ when "class" then @labels["#{r}class"]
171
170
  when "abstracttest" then @labels["abstracttest"]
172
171
  when "conformanceclass" then @labels["conformanceclass"]
173
- else
174
- @permission_lbl
172
+ else
173
+ case r
174
+ when "recommendation" then @recommendation_lbl
175
+ when "requirement" then @requirement_lbl
176
+ when "permission" then @permission_lbl
177
+ end
175
178
  end
176
179
  recommendation_parse1(node, out, label)
177
180
  end
178
181
 
179
- FIRST_LVL_REQ = IsoDoc::Function::XrefGen::FIRST_LVL_REQ
180
-
181
- def sequential_permission_names(clause, klass, label)
182
- c = ::IsoDoc::Function::XrefGen::Counter.new
183
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
184
- next if t["id"].nil? || t["id"].empty?
185
- id = c.increment(t).print
186
- @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
187
- sequential_permission_children(t, id)
188
- end
189
- end
190
-
191
- def req_class_paths
192
- {
193
- "class" => "@type = 'class'",
194
- "test" => "@type = 'verification'",
195
- "" => "not(@type = 'verification' or @type = 'class' or @type = 'abstracttest' or @type = 'conformanceclass')",
196
- }
197
- end
198
-
199
- def req_class_paths2
200
- {
201
- "abstracttest" => "@type = 'abstracttest'",
202
- "conformanceclass" => "@type = 'conformanceclass'",
203
- }
204
- end
205
-
206
- def sequential_permission_children(t, id)
207
- req_class_paths.each do |k, v|
208
- sequential_permission_names1(t, id, "permission[#{v}]", @labels["permission#{k}"])
209
- sequential_permission_names1(t, id, "requirement[#{v}]", @labels["requirement#{k}"])
210
- sequential_permission_names1(t, id, "recommendation[#{v}]", @labels["recommendation#{k}"])
211
- end
212
- req_class_paths2.each do |k, v|
213
- sequential_permission_names1(t, id, "*[#{v}]", @labels[k])
214
- end
215
- end
216
-
217
- def sequential_permission_names1(block, lbl, klass, label)
218
- c = ::IsoDoc::Function::XrefGen::Counter.new
219
- block.xpath(ns("./#{klass}")).each do |t|
220
- next if t["id"].nil? || t["id"].empty?
221
- id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
222
- @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
223
- sequential_permission_children(t, id)
224
- end
225
- end
226
-
227
- def sequential_asset_names(clause)
228
- sequential_table_names(clause)
229
- sequential_figure_names(clause)
230
- sequential_formula_names(clause)
231
- req_class_paths.each do |k, v|
232
- sequential_permission_names(clause, "permission[#{v}]", @labels["permission#{k}"])
233
- sequential_permission_names(clause, "requirement[#{v}]", @labels["requirement#{k}"])
234
- sequential_permission_names(clause, "recommendation[#{v}]", @labels["recommendation#{k}"])
235
- end
236
- req_class_paths2.each do |k, v|
237
- sequential_permission_names(clause, "*[#{v}]", @labels[k])
238
- end
239
- end
240
-
241
- def hierarchical_asset_names(clause, num)
242
- hierarchical_table_names(clause, num)
243
- hierarchical_figure_names(clause, num)
244
- hierarchical_formula_names(clause, num)
245
- req_class_paths.each do |k, v|
246
- hierarchical_permission_names(clause, num, "permission[#{v}]", @labels["permission#{k}"])
247
- hierarchical_permission_names(clause, num, "requirement[#{v}]", @labels["requirement#{k}"])
248
- hierarchical_permission_names(clause, num, "recommendation[#{v}]", @labels["recommendation#{k}"])
249
- end
250
- req_class_paths2.each do |k, v|
251
- hierarchical_permission_names(clause, num, "*[#{v}]", @labels[k])
252
- end
182
+ def requirement_parse(node, out)
183
+ recommendation_parse0(node, out, "requirement")
253
184
  end
254
185
 
255
- def hierarchical_permission_names(clause, num, klass, label)
256
- c = ::IsoDoc::Function::XrefGen::Counter.new
257
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
258
- next if t["id"].nil? || t["id"].empty?
259
- lbl = "#{num}#{hiersep}#{c.increment(t).print}"
260
- @anchors[t["id"]] = anchor_struct(lbl, t, label, klass, t["unnumbered"])
261
- sequential_permission_children(t, lbl)
262
- end
186
+ def permission_parse(node, out)
187
+ recommendation_parse0(node, out, "permission")
263
188
  end
264
189
  end
265
190
  end
@@ -0,0 +1,96 @@
1
+ module IsoDoc
2
+ module Ogc
3
+ module BaseConvert
4
+ FIRST_LVL_REQ = IsoDoc::Function::XrefGen::FIRST_LVL_REQ
5
+
6
+ def sequential_permission_names(clause, klass, label)
7
+ c = ::IsoDoc::Function::XrefGen::Counter.new
8
+ clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
9
+ next if t["id"].nil? || t["id"].empty?
10
+ id = c.increment(t).print
11
+ @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
12
+ l = t.at(ns("./label"))&.text and @reqtlabels[l] = t["id"]
13
+ sequential_permission_children(t, id)
14
+ end
15
+ end
16
+
17
+ def req_class_paths
18
+ { "class" => "@type = 'class'",
19
+ "test" => "@type = 'verification'",
20
+ "" => "not(@type = 'verification' or @type = 'class' or "\
21
+ "@type = 'abstracttest' or @type = 'conformanceclass')", }
22
+ end
23
+
24
+ def req_class_paths2
25
+ { "abstracttest" => "@type = 'abstracttest'",
26
+ "conformanceclass" => "@type = 'conformanceclass'", }
27
+ end
28
+
29
+ def sequential_permission_children(t, id)
30
+ req_class_paths.each do |k, v|
31
+ %w(permission requirement recommendation).each do |r|
32
+ sequential_permission_names1(t, id, "#{r}[#{v}]", @labels["#{r}#{k}"])
33
+ sequential_permission_names1(t, id, "#{r}[#{v}]", @labels["#{r}#{k}"])
34
+ sequential_permission_names1(t, id, "#{r}[#{v}]", @labels["#{r}#{k}"])
35
+ end
36
+ end
37
+ req_class_paths2.each do |k, v|
38
+ sequential_permission_names1(t, id, "*[#{v}]", @labels[k])
39
+ end
40
+ end
41
+
42
+ def sequential_permission_names1(block, lbl, klass, label)
43
+ c = ::IsoDoc::Function::XrefGen::Counter.new
44
+ block.xpath(ns("./#{klass}")).each do |t|
45
+ next if t["id"].nil? || t["id"].empty?
46
+ id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
47
+ @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
48
+ sequential_permission_children(t, id)
49
+ end
50
+ end
51
+
52
+ def sequential_asset_names(clause)
53
+ sequential_table_names(clause)
54
+ sequential_figure_names(clause)
55
+ sequential_formula_names(clause)
56
+ req_class_paths.each do |k, v|
57
+ %w(permission requirement recommendation).each do |r|
58
+ sequential_permission_names(clause, "#{r}[#{v}]", @labels["#{r}#{k}"])
59
+ sequential_permission_names(clause, "#{r}[#{v}]", @labels["#{r}#{k}"])
60
+ sequential_permission_names(clause, "#{r}[#{v}]", @labels["#{r}#{k}"])
61
+ end
62
+ end
63
+ req_class_paths2.each do |k, v|
64
+ sequential_permission_names(clause, "*[#{v}]", @labels[k])
65
+ end
66
+ end
67
+
68
+ def hierarchical_asset_names(clause, num)
69
+ hierarchical_table_names(clause, num)
70
+ hierarchical_figure_names(clause, num)
71
+ hierarchical_formula_names(clause, num)
72
+ req_class_paths.each do |k, v|
73
+ %w(permission requirement recommendation).each do |r|
74
+ hierarchical_permission_names(clause, num, "#{r}[#{v}]", @labels["#{r}#{k}"])
75
+ hierarchical_permission_names(clause, num, "#{r}[#{v}]", @labels["#{r}#{k}"])
76
+ hierarchical_permission_names(clause, num, "#{r}[#{v}]", @labels["#{r}#{k}"])
77
+ end
78
+ end
79
+ req_class_paths2.each do |k, v|
80
+ hierarchical_permission_names(clause, num, "*[#{v}]", @labels[k])
81
+ end
82
+ end
83
+
84
+ def hierarchical_permission_names(clause, num, klass, label)
85
+ c = ::IsoDoc::Function::XrefGen::Counter.new
86
+ clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
87
+ next if t["id"].nil? || t["id"].empty?
88
+ lbl = "#{num}#{hiersep}#{c.increment(t).print}"
89
+ @anchors[t["id"]] = anchor_struct(lbl, t, label, klass, t["unnumbered"])
90
+ l = t.at(ns("./label"))&.text and @reqtlabels[l] = t["id"]
91
+ sequential_permission_children(t, lbl)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end