mn-requirements 0.5.0 → 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: 0badc555e06715baca7220440eb81778bf749207c6ff43e15e1c8e0417679cd3
4
- data.tar.gz: dff076524388287b831304ea8abb1806880d0e960335991bd27b395f58ffdec8
3
+ metadata.gz: 45bfa485d0ed37004f7be357184feaf264d3f1511c81d4c238fe76efbcb55160
4
+ data.tar.gz: b33033cc464bdd80ff7b504d19484ae2e14ff676d286cb3482f74747fd910201
5
5
  SHA512:
6
- metadata.gz: 1cb0ad289dd8ffef0bf50e94b70cf8cbb08b52132dd7326fbda1ee4e23c13f3836af0ec23532ef3a88537e1621e82625a0a09d0fcde8e24e30a9eee87dbf0812
7
- data.tar.gz: 1870ea682f4e7120da000da28e6473bf064161bb8c54fcc30e0a8f1679f77a9b6a3981eadca48b5b316ceaa3239f420e0acdd6458f3a365f9d2ec290ee7e299b
6
+ metadata.gz: 81250e40928eb52e237ce4804509a2b4d2278eac1e2238b8b32c2badb16fe29bdecb8b59c76a2c7e441ec5a839a5a51bdbc92a2ecfe5e07d79e895085f5ea4b6
7
+ data.tar.gz: 0b55d47abceb725787f91e85615a01b54e957a713c1ba9aba79278956c0ad8d1f43990e7e1f3ab311f7ec21007b48eb472ea51ef25bc750541609be9179eeaf2
@@ -152,125 +152,123 @@ module Metanorma
152
152
  end
153
153
 
154
154
  def id_attr(node)
155
- node["id"] ? " id='#{node['id']}'" : ""
155
+ id = node["id"] || node["original-id"]
156
+ id ? " id='#{id}'" : ""
156
157
  end
157
158
 
158
- # KILL
159
- def recommendation_stepsX(node)
160
- node.elements.each { |e| recommendation_steps(e) }
161
- node.at(ns("./component[@class = 'step']")) or return node
162
- 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")
163
170
  d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \
164
- "#{to_xml(d.children)}</li></ol>").first
165
- node.xpath(ns("./component[@class = 'step']")).each do |f|
166
- 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
167
175
  d << f
168
176
  end
169
- node
177
+ ret
170
178
  end
171
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
172
188
 
173
- def recommendation_steps(node, ret)
174
- ret.elements.each_with_index do |e, i|
175
- e1 = nil
176
- #require "debug"; e.name == "component" && e["class"] == "step" and binding.b
177
- e.name == "component" && e["class"] == "step" and
178
- e1 = e.replace(semx_fmt_dup(node.elements[i]))
179
- #require "debug"; e.name == "component" && e["class"] == "step" and binding.b
180
- recommendation_steps(node.elements[i], e1 || e)
181
- end
182
- node.name == "component" && node["class"] == "step" and ret["inlist"] = "true"
183
- #require "debug"; node.name == "component" && node["class"] == "step" and binding.b
184
- d = ret.at(ns("./semx[@inlist]")) or return ret
185
- d.delete("inlist")
186
- d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \
187
- "#{to_xml(d)}</li></ol>").first
188
- ret.xpath(ns("./semx[@inlist]")).each do |f|
189
- f.delete("inlist")
190
- f = f.replace("<li#{id_attr(f)}>#{to_xml(f)}</li>").first
191
- d << f
192
- end
193
- ret
194
- end
195
-
196
- def recommendation_attributes1_component(node, ret, out)
197
- node["class"] == "guidance" and return out
198
- ret = recommendation_steps(node, ret)
199
- out << "<tr#{id_attr(node)}><th>#{node['label']}</th>" \
200
- "<td>#{to_xml(ret)}</td></tr>"
201
- node.delete("label") # inserted in recommendation_component_labels
202
- out
203
- end
204
-
205
- def recommendation_attr_keyvalue(node, key, value)
206
- tag = node.at(ns("./#{key}")) or return nil
207
- value = node.at(ns("./#{value}")) or return nil
208
- !%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
209
193
  implements).include?(tag.text.downcase) or
210
- return nil
211
- lbl = semx_fmt_dup(tag)
212
- lbl.children = Metanorma::Utils.strict_capitalize_first(lbl.text)
213
- [to_xml(lbl), semx_fmt_dup(value)]
214
- 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
215
199
 
216
- def reqt_component_type(node)
217
- klass = node.name
218
- klass == "component" and klass = node["class"]
219
- "requirement-#{klass}"
220
- end
200
+ def reqt_component_type(node)
201
+ klass = node.name
202
+ klass == "component" and klass = node["class"]
203
+ "requirement-#{klass}"
204
+ end
221
205
 
222
- def preserve_in_nested_table?(node)
223
- %w(recommendation requirement permission
224
- table ol dl ul).include?(node.name)
225
- 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
226
210
 
227
- def requirement_component_parse(node, out)
228
- node["exclude"] == "true" and return out
229
- ret = semx_fmt_dup(node)
230
- descr_classif_render(node, ret)
231
- ret.elements.size == 1 && ret.first_element_child.name == "dl" and
232
- return reqt_dl(ret.first_element_child, out)
233
- node.name == "component" and
234
- return recommendation_attributes1_component(node, ret, out)
235
- node.name == "description" and
236
- return requirement_description_parse(node, ret, out)
237
- id = node["id"] || node["original-id"]
238
- !preserve_in_nested_table?(node) && id and attr = " id='#{id}'"
239
- out.add_child("<tr#{id_attr(node)}><td colspan='2'#{attr}></td></tr>").first
240
- .at(ns(".//td")) <<
241
- (preserve_in_nested_table?(node) ? node.dup : ret)
242
- out
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
222
+ node["original-id"] = node["id"]
223
+ end
224
+ node.delete("id")
243
225
  end
244
-
245
- def requirement_description_parse(node, ret, out)
246
- lbl = "description"
247
- recommend_class(node.parent) == "recommend" and
248
- lbl = "statement"
249
- out << "<tr><th>#{@labels['modspec'][lbl]}</th>" \
250
- "<td>#{to_xml(ret)}</td></tr>"
251
- 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
252
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
253
242
 
254
- def requirement_guidance_parse(node, out)
255
- ins = out.at(ns("./fmt-provision/table/tbody"))
256
- origs = node.xpath(ns("./component[@class = 'guidance']"))
257
- out.xpath(ns("./component[@class = 'guidance']")).each_with_index do |f, i|
258
- f.delete("label")
259
- ins << "<tr#{id_attr(f)}><th>#{@labels['modspec']['guidance']}</th>" \
260
- "<td>#{to_xml(semx_fmt_dup(origs[i]))}</td></tr>"
261
- end
262
- 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>"
263
259
  end
260
+ out
261
+ end
264
262
 
265
- def reqt_dl(node, out)
266
- node.xpath(ns("./dt")).each do |dt|
267
- dd = dt.next_element
268
- dd&.name == "dd" or next
269
- out.add_child("<tr><th>#{to_xml(dt.children)}</th>" \
270
- "<td>#{to_xml(dd.children)}</td></tr>")
271
- end
272
- 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>")
273
269
  end
270
+ out
274
271
  end
275
272
  end
276
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.0".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.0
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-13 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