mn-requirements 0.5.1 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d557ae4ed71baabb926e12c579a4c1e07f14f0573caacd8cea6b3f2be33057b
4
- data.tar.gz: 0f2f09d925e1fbe06fbe782545d21823a34f687345b0993aa0e27c2c27436e1e
3
+ metadata.gz: 45bfa485d0ed37004f7be357184feaf264d3f1511c81d4c238fe76efbcb55160
4
+ data.tar.gz: b33033cc464bdd80ff7b504d19484ae2e14ff676d286cb3482f74747fd910201
5
5
  SHA512:
6
- metadata.gz: ee8c23fab75c8bfbfb679942af6053898eb1aa4f0c365fdc7244e6eb39541b05e59b1afa668628d9f6d4a4cb51e61e0d0059446640265717695dbbf61635c29d
7
- data.tar.gz: 4e84dae849f84ab1392e3f25e571e3c0ff8a6328c885b468e834eec9e287e158a72bc4e59c98effe38eeff86e5185f64b04886436c53fe1e81760cabb52ee8a1
6
+ metadata.gz: 81250e40928eb52e237ce4804509a2b4d2278eac1e2238b8b32c2badb16fe29bdecb8b59c76a2c7e441ec5a839a5a51bdbc92a2ecfe5e07d79e895085f5ea4b6
7
+ data.tar.gz: 0b55d47abceb725787f91e85615a01b54e957a713c1ba9aba79278956c0ad8d1f43990e7e1f3ab311f7ec21007b48eb472ea51ef25bc750541609be9179eeaf2
@@ -156,163 +156,119 @@ module Metanorma
156
156
  id ? " id='#{id}'" : ""
157
157
  end
158
158
 
159
- # KILL
160
- def recommendation_stepsX(node)
161
- node.elements.each { |e| recommendation_steps(e) }
162
- node.at(ns("./component[@class = 'step']")) or return node
163
- d = node.at(ns("./component[@class = 'step']"))
159
+ def recommendation_steps(node, ret)
160
+ ret.elements.each_with_index do |e, i|
161
+ e1 = nil
162
+ e.name == "component" && e["class"] == "step" and
163
+ e1 = e.replace(semx_fmt_dup(node.elements[i]))
164
+ recommendation_steps(node.elements[i], e1 || e)
165
+ end
166
+ node.name == "component" && node["class"] == "step" and
167
+ ret["inlist"] = "true"
168
+ d = ret.at(ns("./semx[@inlist]")) or return ret
169
+ d.delete("inlist")
164
170
  d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \
165
- "#{to_xml(d.children)}</li></ol>").first
166
- node.xpath(ns("./component[@class = 'step']")).each do |f|
167
- f = f.replace("<li#{id_attr(f)}>#{to_xml(f.children)}</li>").first
171
+ "#{to_xml(d)}</li></ol>").first
172
+ ret.xpath(ns("./semx[@inlist]")).each do |f|
173
+ f.delete("inlist")
174
+ f = f.replace("<li#{id_attr(f)}>#{to_xml(f)}</li>").first
168
175
  d << f
169
176
  end
170
- node
177
+ ret
171
178
  end
172
179
 
180
+ def recommendation_attributes1_component(node, ret, out)
181
+ node["class"] == "guidance" and return out
182
+ ret = recommendation_steps(node, ret)
183
+ out << "<tr#{id_attr(node)}><th>#{node['label']}</th>" \
184
+ "<td>#{to_xml(ret)}</td></tr>"
185
+ node.delete("label") # inserted in recommendation_component_labels
186
+ out
187
+ end
173
188
 
174
- def recommendation_steps(node, ret)
175
- ret.elements.each_with_index do |e, i|
176
- e1 = nil
177
- #require "debug"; e.name == "component" && e["class"] == "step" and binding.b
178
- e.name == "component" && e["class"] == "step" and
179
- e1 = e.replace(semx_fmt_dup(node.elements[i]))
180
- #require "debug"; e.name == "component" && e["class"] == "step" and binding.b
181
- recommendation_steps(node.elements[i], e1 || e)
182
- end
183
- node.name == "component" && node["class"] == "step" and ret["inlist"] = "true"
184
- #require "debug"; node.name == "component" && node["class"] == "step" and binding.b
185
- d = ret.at(ns("./semx[@inlist]")) or return ret
186
- d.delete("inlist")
187
- d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \
188
- "#{to_xml(d)}</li></ol>").first
189
- ret.xpath(ns("./semx[@inlist]")).each do |f|
190
- f.delete("inlist")
191
- f = f.replace("<li#{id_attr(f)}>#{to_xml(f)}</li>").first
192
- d << f
193
- end
194
- ret
195
- end
196
-
197
- def recommendation_attributes1_component(node, ret, out)
198
- node["class"] == "guidance" and return out
199
- ret = recommendation_steps(node, ret)
200
- out << "<tr#{id_attr(node)}><th>#{node['label']}</th>" \
201
- "<td>#{to_xml(ret)}</td></tr>"
202
- node.delete("label") # inserted in recommendation_component_labels
203
- out
204
- end
205
-
206
- def recommendation_attr_keyvalue(node, key, value)
207
- tag = node.at(ns("./#{key}")) or return nil
208
- value = node.at(ns("./#{value}")) or return nil
209
- !%w(target indirect-dependency identifier-base
189
+ def recommendation_attr_keyvalue(node, key, value)
190
+ tag = node.at(ns("./#{key}")) or return nil
191
+ value = node.at(ns("./#{value}")) or return nil
192
+ !%w(target indirect-dependency identifier-base
210
193
  implements).include?(tag.text.downcase) or
211
- return nil
212
- lbl = semx_fmt_dup(tag)
213
- lbl.children = Metanorma::Utils.strict_capitalize_first(lbl.text)
214
- [to_xml(lbl), semx_fmt_dup(value)]
215
- end
216
-
217
- def reqt_component_type(node)
218
- klass = node.name
219
- klass == "component" and klass = node["class"]
220
- "requirement-#{klass}"
221
- end
222
-
223
- # KILL
224
- def preserve_in_nested_table?(node)
225
- %w(recommendation requirement permission
226
- table ol dl ul).include?(node.name)
227
- end
194
+ return nil
195
+ lbl = semx_fmt_dup(tag)
196
+ lbl.children = Metanorma::Utils.strict_capitalize_first(lbl.text)
197
+ [to_xml(lbl), semx_fmt_dup(value)]
198
+ end
228
199
 
229
- # KILL
230
- def requirement_component_parse(node, out)
231
- node["exclude"] == "true" and return out
232
- ret = semx_fmt_dup(node)
233
- descr_classif_render(node, ret)
234
- ret.elements.size == 1 && ret.first_element_child.name == "dl" and
235
- return reqt_dl(ret.first_element_child, out)
236
- node.name == "component" and
237
- return recommendation_attributes1_component(node, ret, out)
238
- node.name == "description" and
239
- return requirement_description_parse(node, ret, out)
240
- id = node["id"] || node["original-id"]
241
- !preserve_in_nested_table?(node) && id and attr = " id='#{id}'"
242
- out.add_child("<tr#{id_attr(node)}><td colspan='2'#{attr}></td></tr>").first
243
- .at(ns(".//td")) <<
244
- (preserve_in_nested_table?(node) ? node.dup : ret)
245
- out
246
- end
200
+ def reqt_component_type(node)
201
+ klass = node.name
202
+ klass == "component" and klass = node["class"]
203
+ "requirement-#{klass}"
204
+ end
247
205
 
248
- def preserve_in_nested_table?(node)
249
- #%w(recommendation requirement permission table ol dl ul hr br p).include?(node.name)
250
- !%w(subject inherit identifier measurement-target specification verification import description component).include?(node.name)
251
- end
206
+ def preserve_in_nested_table?(node)
207
+ !%w(subject inherit identifier measurement-target specification
208
+ verification import description component).include?(node.name)
209
+ end
252
210
 
253
- def requirement_component_parse(node, out)
254
- node["exclude"] == "true" and return out
255
- ret = semx_fmt_dup(node)
256
- descr_classif_render(node, ret)
257
- id = node["id"] || node["original-id"]
258
- id and attr = " id='#{id}'"
259
- preserve = preserve_in_nested_table?(node)
260
- if id == node["id"]
261
- if node["original-id"]
262
- attr = " id='#{node["original-id"]}'"
263
- else
211
+ def requirement_component_parse(node, out)
212
+ node["exclude"] == "true" and return out
213
+ ret = semx_fmt_dup(node)
214
+ descr_classif_render(node, ret)
215
+ id = node["id"] || node["original-id"]
216
+ id and attr = " id='#{id}'"
217
+ preserve = preserve_in_nested_table?(node)
218
+ if id == node["id"]
219
+ if node["original-id"]
220
+ attr = " id='#{node['original-id']}'"
221
+ else
264
222
  node["original-id"] = node["id"]
265
- end
266
- node.delete("id")
267
223
  end
268
- if preserve
269
- n = Nokogiri::XML::Node.new(node.name, node.document)
270
- node.attributes.each { |k, v| n[k] = v }
271
- node.children.empty? or n << ret
272
- ret = n
273
- end
274
- ret.elements.size == 1 && ret.first_element_child.name == "dl" and
275
- return reqt_dl(ret.first_element_child, out)
276
- node.name == "component" and
277
- return recommendation_attributes1_component(node, ret, out)
278
- node.name == "description" and
279
- return requirement_description_parse(node, ret, out)
280
- #!preserve_in_nested_table?(node) && id and attr = " id='#{id}'"
281
- out.add_child("<tr#{attr}><td colspan='2'></td></tr>").first
282
- .at(ns(".//td")) << (%(permission requirement recommendation).include?(node.name) ? node.dup : ret)
283
- #(preserve_in_nested_table?(node) ? node.dup : ret)
284
- out
224
+ node.delete("id")
285
225
  end
286
-
287
- def requirement_description_parse(node, ret, out)
288
- lbl = "description"
289
- recommend_class(node.parent) == "recommend" and
290
- lbl = "statement"
291
- out << "<tr><th>#{@labels['modspec'][lbl]}</th>" \
292
- "<td>#{to_xml(ret)}</td></tr>"
293
- out
226
+ if preserve
227
+ n = Nokogiri::XML::Node.new(node.name, node.document)
228
+ node.attributes.each { |k, v| n[k] = v }
229
+ node.children.empty? or n << ret
230
+ ret = n
294
231
  end
232
+ ret.elements.size == 1 && ret.first_element_child.name == "dl" and
233
+ return reqt_dl(ret.first_element_child, out)
234
+ node.name == "component" and
235
+ return recommendation_attributes1_component(node, ret, out)
236
+ node.name == "description" and
237
+ return requirement_description_parse(node, ret, out)
238
+ out.add_child("<tr#{attr}><td colspan='2'></td></tr>").first
239
+ .at(ns(".//td")) << (%(permission requirement recommendation).include?(node.name) ? node.dup : ret)
240
+ out
241
+ end
295
242
 
296
- def requirement_guidance_parse(node, out)
297
- ins = out.at(ns("./fmt-provision/table/tbody"))
298
- origs = node.xpath(ns("./component[@class = 'guidance']"))
299
- out.xpath(ns("./component[@class = 'guidance']")).each_with_index do |f, i|
300
- f.delete("label")
301
- ins << "<tr#{id_attr(f)}><th>#{@labels['modspec']['guidance']}</th>" \
302
- "<td>#{to_xml(semx_fmt_dup(origs[i]))}</td></tr>"
303
- end
304
- out
243
+ def requirement_description_parse(node, ret, out)
244
+ lbl = "description"
245
+ recommend_class(node.parent) == "recommend" and
246
+ lbl = "statement"
247
+ out << "<tr><th>#{@labels['modspec'][lbl]}</th>" \
248
+ "<td>#{to_xml(ret)}</td></tr>"
249
+ out
250
+ end
251
+
252
+ def requirement_guidance_parse(node, out)
253
+ ins = out.at(ns("./fmt-provision/table/tbody"))
254
+ origs = node.xpath(ns("./component[@class = 'guidance']"))
255
+ out.xpath(ns("./component[@class = 'guidance']")).each_with_index do |f, i|
256
+ f.delete("label")
257
+ ins << "<tr#{id_attr(f)}><th>#{@labels['modspec']['guidance']}</th>" \
258
+ "<td>#{to_xml(semx_fmt_dup(origs[i]))}</td></tr>"
305
259
  end
260
+ out
261
+ end
306
262
 
307
- def reqt_dl(node, out)
308
- node.xpath(ns("./dt")).each do |dt|
309
- dd = dt.next_element
310
- dd&.name == "dd" or next
311
- out.add_child("<tr><th>#{to_xml(dt.children)}</th>" \
312
- "<td>#{to_xml(dd.children)}</td></tr>")
313
- end
314
- out
263
+ def reqt_dl(node, out)
264
+ node.xpath(ns("./dt")).each do |dt|
265
+ dd = dt.next_element
266
+ dd&.name == "dd" or next
267
+ out.add_child("<tr><th>#{to_xml(dt.children)}</th>" \
268
+ "<td>#{to_xml(dd.children)}</td></tr>")
315
269
  end
270
+ out
316
271
  end
317
272
  end
318
273
  end
274
+ end
@@ -74,33 +74,29 @@ module Metanorma
74
74
  ret
75
75
  end
76
76
 
77
- # KILL
78
77
  def requirement_table_nested_cleanup(node, out, table)
79
- table.xpath(ns("./tbody/tr/td/table")).each do |t|
80
- x = t.at(ns("./thead/tr")) or next
81
- x.at(ns("./th")).children =
82
- requirement_table_nested_cleanup_hdr(node)
83
- f = x.at(ns("./td/fmt-name")) and
84
- f.replace(f.children)
85
- t.parent.parent.replace(x)
86
- end
87
- table
88
- end
89
-
90
- def requirement_table_nested_cleanup(node, out, table)
91
- table.xpath(ns("./tbody/tr/td/*/fmt-provision/table")).each do |t|
92
- x = t.at(ns("./thead/tr")) or next
93
- x.at(ns("./th")).children =
94
- requirement_table_nested_cleanup_hdr(node)
95
- f = x.at(ns("./td/fmt-name")) and
96
- f.parent.children = to_xml(f.children).strip
97
- td = x.at(ns("./td"))
98
- td["id"] = t["original-id"] || t["id"]
99
- if desc = t.at(ns("./tbody/tr/td/semx[@element = 'description']"))
100
- p = desc.at(ns("./p")) and p.replace(p.children)
101
- td << " #{to_xml(desc)}"
78
+ rows = []
79
+ table.xpath(ns("./tbody/tr/td/*/fmt-provision/table"))
80
+ .sort_by do |t|
81
+ [t.at(ns(".//fmt-name//span[@class = 'fmt-element-name']"))&.text,
82
+ t.at(ns(".//fmt-name//semx[@element = 'autonum']"))&.text&.to_i]
83
+ end.each do |t|
84
+ x = t.at(ns("./thead/tr")) or next
85
+ x.at(ns("./th")).children =
86
+ requirement_table_nested_cleanup_hdr(node)
87
+ f = x.at(ns("./td/fmt-name")) and
88
+ f.parent.children = to_xml(f.children).strip
89
+ td = x.at(ns("./td"))
90
+ td["id"] = t["original-id"] || t["id"]
91
+ if desc = t.at(ns("./tbody/tr/td/semx[@element = 'description']"))
92
+ p = desc.at(ns("./p")) and p.replace(p.children)
93
+ td << " #{to_xml(desc)}"
94
+ end
95
+ rows << x
102
96
  end
103
- t.parent.parent.parent.parent.replace(x)
97
+ table.xpath(ns("./tbody/tr[./td/*/fmt-provision/table]"))
98
+ .each_with_index do |t, i|
99
+ t.replace(rows[i])
104
100
  end
105
101
  out.xpath(ns("./*/fmt-provision")).each(&:remove)
106
102
  table
@@ -135,10 +131,10 @@ td << " #{to_xml(desc)}"
135
131
  def expand_xrefs_in_reqt(table)
136
132
  table.xpath(ns(".//xref[not(@style)][string-length() = 0]"))
137
133
  .each do |x|
138
- @xrefs.anchor(x["target"], :modspec, false) or next # modspec xrefs only
139
- ref = @xrefs.anchor(x["target"], :xref, false) or next
140
- x << ref
141
- end
134
+ @xrefs.anchor(x["target"], :modspec, false) or next # modspec xrefs only
135
+ ref = @xrefs.anchor(x["target"], :xref, false) or next
136
+ x << ref
137
+ end
142
138
  end
143
139
 
144
140
  def truncate_id_base_in_reqt(table)
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  class Requirements
3
- VERSION = "0.5.1".freeze
3
+ VERSION = "0.5.2".freeze
4
4
  end
5
5
  end
@@ -37,8 +37,9 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "metanorma-standoc", ">= 2.8.0"
38
38
  spec.add_development_dependency "rake", "~> 13.0"
39
39
  spec.add_development_dependency "rspec", "~> 3.6"
40
- spec.add_development_dependency "rubocop", "~> 1.5.2"
41
- spec.add_development_dependency "sassc", "2.4.0"
40
+ spec.add_development_dependency "rubocop", "~> 1"
41
+ spec.add_development_dependency "rubocop-performance"
42
+ spec.add_development_dependency "sassc-embedded", "~> 1"
42
43
  spec.add_development_dependency "simplecov", "~> 0.15"
43
44
  spec.add_development_dependency "timecop", "~> 0.9"
44
45
  spec.add_development_dependency "xml-c14n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mn-requirements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
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-02-25 00:00:00.000000000 Z
11
+ date: 2025-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: isodoc-i18n
@@ -156,28 +156,42 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.5.2
159
+ version: '1'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.5.2
166
+ version: '1'
167
167
  - !ruby/object:Gem::Dependency
168
- name: sassc
168
+ name: rubocop-performance
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 2.4.0
173
+ version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '='
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: sassc-embedded
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: 2.4.0
194
+ version: '1'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: simplecov
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -279,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
293
  - !ruby/object:Gem::Version
280
294
  version: '0'
281
295
  requirements: []
282
- rubygems_version: 3.3.27
296
+ rubygems_version: 3.5.22
283
297
  signing_key:
284
298
  specification_version: 4
285
299
  summary: Requirements processing and rendering according to different models