metanorma-ogc 2.8.4 → 2.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,11 @@
1
1
  require "asciidoctor"
2
2
  require "metanorma/standoc/converter"
3
3
  require "fileutils"
4
+ require "date"
4
5
  require_relative "front"
5
6
  require_relative "validate"
6
7
  require_relative "cleanup"
8
+ require_relative "sections"
7
9
 
8
10
  module Metanorma
9
11
  module Ogc
@@ -17,9 +19,6 @@ module Metanorma
17
19
  @tocrecommendations = true
18
20
  end
19
21
 
20
- # ignore, we generate ToC outside of asciidoctor
21
- def toc(value); end
22
-
23
22
  def default_requirement_model
24
23
  "ogc"
25
24
  end
@@ -45,44 +44,35 @@ module Metanorma
45
44
  d
46
45
  end
47
46
 
48
- def sectiontype(node, level = true)
49
- ret = sectiontype_streamline(sectiontype1(node))
50
- return ret if ret == "terms and definitions" &&
51
- node.attr("style") == "appendix" && node.level == 1
52
-
53
- super
54
- end
55
-
56
- def section(node)
57
- override_style(node)
58
- super
59
- end
60
-
61
- def override_style(node)
62
- s = node.attr("style")
63
- if %w(overview future_outlook value_proposition contributors).include?(s)
64
- node.set_attr("style", "preface")
65
- node.set_attr("type", s)
66
- end
67
- if %w(aims objectives topics outlook security).include?(s)
68
- node.set_attr("type", s)
47
+ def document_scheme(node)
48
+ if r = node.attr("document-scheme")
49
+ r == "2022" ? "current" : "2021"
50
+ elsif r = node.attr("published-date")
51
+ published_date_scheme(r)
52
+ elsif r = node.attr("copyright-year")
53
+ r.to_i >= 2022 ? "current" : "2021"
54
+ else "current"
69
55
  end
70
56
  end
71
57
 
72
- def sectiontype_streamline(ret)
73
- case ret
74
- when "preface" then "foreword"
75
- when "foreword", "introduction" then "donotrecognise-foreword"
76
- when "references" then "normative references"
77
- when "glossary" then "terms and definitions"
78
- else super
79
- end
58
+ def published_date_scheme(date_str)
59
+ published_date = parse_flexible_date(date_str) or return nil
60
+ cutoff_date = Date.new(2021, 11, 8)
61
+ published_date >= cutoff_date ? "current" : "2021"
62
+ rescue Date::Error, ArgumentError
63
+ nil
80
64
  end
81
65
 
82
- # legacy encoding
83
- def sectiontype1(node)
84
- role_style(node, "executive_summary") and return "executivesummary"
85
- super
66
+ def parse_flexible_date(date_str)
67
+ case date_str
68
+ when /^\d{4}$/
69
+ Date.new(date_str.to_i, 1, 1)
70
+ when /^\d{4}-\d{2}$/
71
+ year, month = date_str.split("-").map(&:to_i)
72
+ Date.new(year, month, 1)
73
+ else
74
+ Date.parse(date_str)
75
+ end
86
76
  end
87
77
 
88
78
  def outputs(node, ret)
@@ -96,75 +86,15 @@ module Metanorma
96
86
  false, "#{@filename}.pdf")
97
87
  end
98
88
 
99
- def clause_parse(attrs, xml, node)
100
- %w(overview future_outlook value_proposition
101
- contributors aims objectives topics outlook security)
102
- .include?(node.attr("type")) and
103
- attrs = attrs.merge(type: node.attr("type"))
104
- case node.attr("heading")&.downcase || node.title.downcase
105
- when "submitters"
106
- return submitters_parse(attrs.merge(type: "submitters"), xml, node)
107
- when "contributors"
108
- return submitters_parse(attrs.merge(type: "contributors"), xml, node)
109
- when "conformance" then attrs = attrs.merge(type: "conformance")
110
- when "security considerations"
111
- attrs = attrs.merge(type: "security")
112
- end
113
- super
114
- end
115
-
116
- def submitters_parse(attrs, xml, node)
117
- title = @i18n.submitters
118
- doctype(node) == "engineering-report" ||
119
- attrs[:type] == "contributors" and
120
- title = @i18n.contributors_clause
121
- xml.clause **attr_code(attrs) do |xml_section|
122
- section_title(xml_section, title)
123
- xml_section << node.content
124
- end
125
- end
126
-
127
89
  def style(_node, _text)
128
90
  nil
129
91
  end
130
92
 
131
- def term_def_parse(attrs, xml, node, _toplevel)
132
- if node.attr("style") == "appendix" && node.level == 1
133
- terms_annex_parse(attrs, xml, node)
134
- else
135
- super
136
- end
137
- end
138
-
139
93
  def table_cell(node, xml_tr, tblsec)
140
94
  node.set_attr("valign", "middle")
141
95
  super
142
96
  end
143
97
 
144
- def terms_annex_parse(attrs, xml, node)
145
- attrs1 = attrs.merge(id: "_#{UUIDTools::UUID.random_create}")
146
- xml.annex **attr_code(attrs1) do |xml_section|
147
- section_title(xml_section, node.title)
148
- attrs.delete(:anchor)
149
- xml_section.terms **attr_code(attrs) do |terms|
150
- (s = node.attr("source")) && s.split(",").each do |s1|
151
- terms.termdocsource(nil, **attr_code(bibitemid: s1))
152
- end
153
- terms << node.content
154
- end
155
- end
156
- end
157
-
158
- def set_obligation(attrs, node)
159
- if node.attr("style") == "appendix" && node.level == 1
160
- attrs[:obligation] = if node.attributes.has_key?("obligation")
161
- node.attr("obligation")
162
- else "informative"
163
- end
164
- else super
165
- end
166
- end
167
-
168
98
  OGC_COLORS = {
169
99
  "text": "rgb(88, 89, 91)",
170
100
  "secondary-shade-1": "rgb(237, 193, 35)",
@@ -202,7 +132,7 @@ module Metanorma
202
132
 
203
133
  def update_colors(node)
204
134
  c = OGC_COLORS.dup
205
- if document_scheme(node) == "2022"
135
+ if document_scheme(node) == "current"
206
136
  c[:"secondary-shade-1"] = "rgb(0, 177, 255)"
207
137
  c[:"secondary-shade-2"] = "rgb(0, 177, 255)"
208
138
  end
@@ -236,11 +166,12 @@ module Metanorma
236
166
  # preempt subdoctype warning
237
167
  def adoc2xml(text, flavour)
238
168
  Nokogiri::XML(text).root and return text
239
- c = Asciidoctor
240
- .convert("= X\nA\n:semantic-metadata-headless: true\n" \
169
+ c = isolated_asciidoctor_convert(
170
+ "= X\nA\n:semantic-metadata-headless: true\n" \
241
171
  ":novalid:\n:docsubtype: implementation\n" \
242
172
  ":doctype: standard\n\n#{text}\n",
243
- backend: flavour, header_footer: true)
173
+ backend: flavour, header_footer: true,
174
+ )
244
175
  Nokogiri::XML(c).at("//xmlns:sections")
245
176
  end
246
177
  end
@@ -0,0 +1,110 @@
1
+ module Metanorma
2
+ module Ogc
3
+ class Converter < Standoc::Converter
4
+ # ignore, we generate ToC outside of asciidoctor
5
+ def toc(value); end
6
+
7
+ def sectiontype(node, level = true)
8
+ ret = sectiontype_streamline(sectiontype1(node))
9
+ return ret if ret == "terms and definitions" &&
10
+ node.attr("style") == "appendix" && node.level == 1
11
+
12
+ super
13
+ end
14
+
15
+ def section(node)
16
+ override_style(node)
17
+ super
18
+ end
19
+
20
+ def override_style(node)
21
+ s = node.attr("style")
22
+ if %w(overview future_outlook value_proposition
23
+ contributors).include?(s)
24
+ node.set_attr("style", "preface")
25
+ node.set_attr("type", s)
26
+ end
27
+ if %w(aims objectives topics outlook security).include?(s)
28
+ node.set_attr("type", s)
29
+ end
30
+ end
31
+
32
+ def sectiontype_streamline(ret)
33
+ case ret
34
+ when "preface" then "foreword"
35
+ when "foreword", "introduction" then "donotrecognise-foreword"
36
+ when "references" then "normative references"
37
+ when "glossary" then "terms and definitions"
38
+ else super
39
+ end
40
+ end
41
+
42
+ # legacy encoding
43
+ def sectiontype1(node)
44
+ role_style(node, "executive_summary") and return "executivesummary"
45
+ super
46
+ end
47
+
48
+ def clause_parse(attrs, xml, node)
49
+ %w(overview future_outlook value_proposition
50
+ contributors aims objectives topics outlook security)
51
+ .include?(node.attr("type")) and
52
+ attrs = attrs.merge(type: node.attr("type"))
53
+ case node.attr("heading")&.downcase || node.title.downcase
54
+ when "submitters"
55
+ return submitters_parse(attrs.merge(type: "submitters"), xml, node)
56
+ when "contributors"
57
+ return submitters_parse(attrs.merge(type: "contributors"), xml, node)
58
+ when "conformance" then attrs = attrs.merge(type: "conformance")
59
+ when "security considerations"
60
+ attrs = attrs.merge(type: "security")
61
+ end
62
+ super
63
+ end
64
+
65
+ def submitters_parse(attrs, xml, node)
66
+ title = @i18n.submitters
67
+ doctype(node) == "engineering-report" ||
68
+ attrs[:type] == "contributors" and
69
+ title = @i18n.contributors_clause
70
+ xml.clause **attr_code(attrs) do |xml_section|
71
+ section_title(xml_section, title)
72
+ xml_section << node.content
73
+ end
74
+ end
75
+
76
+ def term_def_parse(attrs, xml, node, _toplevel)
77
+ if node.attr("style") == "appendix" && node.level == 1
78
+ terms_annex_parse(attrs, xml, node)
79
+ else
80
+ super
81
+ end
82
+ end
83
+
84
+ def terms_annex_parse(attrs, xml, node)
85
+ attrs1 = attrs.merge(id: "_#{UUIDTools::UUID.random_create}")
86
+ xml.annex **attr_code(attrs1) do |xml_section|
87
+ section_title(xml_section, node.title)
88
+ attrs.delete(:anchor)
89
+ xml_section.terms **attr_code(attrs) do |terms|
90
+ (s = node.attr("source")) && s.split(",").each do |s1|
91
+ terms.termdocsource(nil, **attr_code(bibitemid: s1))
92
+ end
93
+ terms << node.content
94
+ end
95
+ end
96
+ end
97
+
98
+ def set_obligation(attrs, node)
99
+ if node.attr("style") == "appendix" && node.level == 1
100
+ attrs[:obligation] = if node.attributes.has_key?("obligation")
101
+ node.attr("obligation")
102
+ else "informative"
103
+ end
104
+ else
105
+ super
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ogc
3
- VERSION = "2.8.4".freeze
3
+ VERSION = "2.8.5".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ogc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.4
4
+ version: 2.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-15 00:00:00.000000000 Z
11
+ date: 2025-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iso-639
@@ -303,6 +303,7 @@ files:
303
303
  - lib/metanorma/ogc/processor.rb
304
304
  - lib/metanorma/ogc/relaton-ogc.rng
305
305
  - lib/metanorma/ogc/reqt.rng
306
+ - lib/metanorma/ogc/sections.rb
306
307
  - lib/metanorma/ogc/validate.rb
307
308
  - lib/metanorma/ogc/version.rb
308
309
  - lib/relaton/render/config.yml