mn-requirements 0.2.0 → 0.2.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 +4 -4
- data/lib/metanorma/modspec/cleanup.rb +38 -3
- data/lib/metanorma/modspec/isodoc.rb +6 -3
- data/lib/metanorma/modspec/modspec.rb +4 -0
- data/lib/metanorma/modspec/reqt_label.rb +60 -5
- data/lib/metanorma/modspec/table_cleanup.rb +33 -0
- data/lib/metanorma/modspec/xrefs.rb +2 -1
- data/lib/metanorma/requirements/selector.rb +2 -1
- data/lib/metanorma/requirements/version.rb +1 -1
- data/mn-requirements.gemspec +3 -2
- metadata +4 -10
- data/.github/workflows/rake.yml +0 -15
- data/.github/workflows/release.yml +0 -27
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/rspec +0 -17
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30c82855931f4c0fb8b033a7fcb15583826ef041cee6ff1c4630570abd42a074
|
4
|
+
data.tar.gz: c3765be67270e9fdad7d61b30654ce5a7ed5a7327d3b77598170354cd930c91a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '098e5bd08fdb6628f7b493e5cbdde2ff793168008837f5b0184034ed79e202a31295d29ba8e5707aa56c2abfdee7bf31c8a7677ed7deb3f7fc2732e9f731cb6e'
|
7
|
+
data.tar.gz: ddcd729ae096912a304b1763092c135d5967f1a21d35f5f907dc16b408c75e8c64c3ba1864fd5941d08b36e77e6051e339353b6f19e92244e700f775c4dd5c21
|
@@ -21,7 +21,7 @@ module Metanorma
|
|
21
21
|
|
22
22
|
def requirement_metadata_component_tags
|
23
23
|
%w(test-purpose test-method test-method-type conditions part description
|
24
|
-
reference step guidance) +
|
24
|
+
statement reference step guidance) +
|
25
25
|
requirement_metadata_requirement_tags
|
26
26
|
end
|
27
27
|
|
@@ -35,6 +35,7 @@ module Metanorma
|
|
35
35
|
ins1 = super
|
36
36
|
dlist.xpath("./dt").each do |e|
|
37
37
|
tag = e.text&.gsub(/ /, "-")&.downcase
|
38
|
+
tag = "description" if tag == "statement"
|
38
39
|
next unless requirement_metadata_component_tags.include?(tag)
|
39
40
|
|
40
41
|
ins1.next = requirement_metadata1_component(e, tag)
|
@@ -75,7 +76,7 @@ module Metanorma
|
|
75
76
|
|
76
77
|
def requirement_target_identifiers(reqt)
|
77
78
|
reqt.xpath("./classification[tag][value/link]").each do |c|
|
78
|
-
%w(target indirect-dependency implements)
|
79
|
+
%w(target indirect-dependency implements identifier-base)
|
79
80
|
.include?(c.at("./tag").text.downcase) or next
|
80
81
|
v = c.at("./value[link]")
|
81
82
|
v.children = v.at("./link/@target").text
|
@@ -83,7 +84,7 @@ module Metanorma
|
|
83
84
|
end
|
84
85
|
|
85
86
|
def requirement_metadata_to_component(reqt)
|
86
|
-
xpath = requirement_metadata_component_tags - %w(description) -
|
87
|
+
xpath = requirement_metadata_component_tags - %w(statement description) -
|
87
88
|
requirement_metadata_requirement_tags
|
88
89
|
reqt.xpath(xpath.map { |x| ".//#{x}" }.join(" | ")).each do |c|
|
89
90
|
c["class"] = c.name
|
@@ -119,6 +120,40 @@ module Metanorma
|
|
119
120
|
c.children = "<p>#{c.children.to_xml}</p>"
|
120
121
|
end
|
121
122
|
end
|
123
|
+
|
124
|
+
def add_misc_container(xmldoc)
|
125
|
+
unless ins = xmldoc.at("//misc-container")
|
126
|
+
a = xmldoc.at("//termdocsource") || xmldoc.at("//bibdata")
|
127
|
+
a.next = "<misc-container/>"
|
128
|
+
ins = xmldoc.at("//misc-container")
|
129
|
+
end
|
130
|
+
ins
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_misccontainer_anchor_aliases(xmldoc)
|
134
|
+
m = add_misc_container(xmldoc)
|
135
|
+
x = ".//table[@id = '_misccontainer_anchor_aliases']/tbody"
|
136
|
+
unless ins = m.at(x)
|
137
|
+
m << "<table id = '_misccontainer_anchor_aliases'><tbody/></table>"
|
138
|
+
ins = m.at(x)
|
139
|
+
end
|
140
|
+
ins
|
141
|
+
end
|
142
|
+
|
143
|
+
def requirement_anchor_aliases(reqt)
|
144
|
+
x = reqt.xpath("./identifier")
|
145
|
+
x.empty? and return
|
146
|
+
table = add_misccontainer_anchor_aliases(reqt.document)
|
147
|
+
ids = x.each_with_object([]) do |i, m|
|
148
|
+
m << "<td>#{i.text}</td>"
|
149
|
+
end
|
150
|
+
table << "<tr><th>#{reqt['id']}</th>#{ids.join}</tr>"
|
151
|
+
end
|
152
|
+
|
153
|
+
def requirement_identifier_cleanup(reqt)
|
154
|
+
super
|
155
|
+
requirement_anchor_aliases(reqt)
|
156
|
+
end
|
122
157
|
end
|
123
158
|
end
|
124
159
|
end
|
@@ -69,8 +69,11 @@ module Metanorma
|
|
69
69
|
|
70
70
|
def recommend_title(node, out)
|
71
71
|
label = node.at(ns("./identifier")) or return
|
72
|
-
|
73
|
-
|
72
|
+
ret = <<~OUTPUT
|
73
|
+
<tr><th>#{@labels['modspec']['identifier']}</th>
|
74
|
+
<td><tt><modspec-ident>#{label.children.to_xml}</modspec-ident></tt></td>
|
75
|
+
OUTPUT
|
76
|
+
out.add_child(ret)
|
74
77
|
end
|
75
78
|
|
76
79
|
def recommendation_attributes1(node)
|
@@ -162,7 +165,7 @@ module Metanorma
|
|
162
165
|
def recommendation_attr_keyvalue(node, key, value)
|
163
166
|
tag = node.at(ns("./#{key}")) or return nil
|
164
167
|
value = node.at(ns("./#{value}")) or return nil
|
165
|
-
!%w(target indirect-dependency
|
168
|
+
!%w(target indirect-dependency identifier-base
|
166
169
|
implements).include?(tag.text.downcase) or
|
167
170
|
return nil
|
168
171
|
[Metanorma::Utils.strict_capitalize_first(tag.text), value.children]
|
@@ -31,6 +31,8 @@ module Metanorma
|
|
31
31
|
@reqt_ids = reqt_ids(doc)
|
32
32
|
@reqt_links_class = reqt_links_class(doc)
|
33
33
|
@reqt_links_test = reqt_links_test(doc)
|
34
|
+
@reqt_id_base = reqt_id_base(doc)
|
35
|
+
truncate_id_base_outside_reqts(doc)
|
34
36
|
end
|
35
37
|
|
36
38
|
def reqtlabels(doc)
|
@@ -95,11 +97,18 @@ module Metanorma
|
|
95
97
|
end&.at(ns("./value"))
|
96
98
|
end
|
97
99
|
|
100
|
+
def reqt_extract_id_base(reqt)
|
101
|
+
reqt.xpath(ns("./classification[tag][value]")).detect do |x|
|
102
|
+
x.at(ns("./tag")).text.casecmp("identifier-base").zero?
|
103
|
+
end&.at(ns("./value"))
|
104
|
+
end
|
105
|
+
|
98
106
|
def recommendation_link_test(ident)
|
99
107
|
test = @reqt_links_test[ident&.strip] or return nil
|
100
108
|
"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
|
101
109
|
end
|
102
110
|
|
111
|
+
# we have not implemented multiple levels of nesting of classes
|
103
112
|
def reqt_links_class(docxml)
|
104
113
|
docxml.xpath(ns("//requirement | //recommendation | //permission"))
|
105
114
|
.each_with_object({}) do |r, m|
|
@@ -108,15 +117,50 @@ module Metanorma
|
|
108
117
|
id = r.at(ns("./identifier")) or next
|
109
118
|
r.xpath(ns("./requirement | ./recommendation | ./permission"))
|
110
119
|
.each do |r1|
|
111
|
-
|
112
|
-
lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :xref, false)
|
113
|
-
next unless lbl
|
114
|
-
|
115
|
-
m[id1.text] = { lbl: lbl, id: r["id"] }
|
120
|
+
m = reqt_links_class1(id, r, r1, m)
|
116
121
|
end
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
125
|
+
def reqt_links_class1(id, parent_reqt, reqt, acc)
|
126
|
+
id1 = reqt.at(ns("./identifier")) or return acc
|
127
|
+
lbl = @xrefs.anchor(@reqt_ids[id.text.strip][:id], :xref, false)
|
128
|
+
return acc unless lbl
|
129
|
+
|
130
|
+
acc[id1.text] = { lbl: lbl, id: parent_reqt["id"] }
|
131
|
+
acc
|
132
|
+
end
|
133
|
+
|
134
|
+
def reqt_hierarchy_extract
|
135
|
+
@reqt_links_class.each_with_object({}) do |(k, v), m|
|
136
|
+
m[v[:id]] ||= []
|
137
|
+
m[v[:id]] << @reqt_ids[k][:id]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def reqt_id_base_init(docxml)
|
142
|
+
docxml.xpath(ns("//requirement | //recommendation | //permission"))
|
143
|
+
.each_with_object({}) do |r, m|
|
144
|
+
m[r["id"]] = reqt_extract_id_base(r)&.text
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def reqt_id_base_inherit(ret, class2reqt)
|
149
|
+
ret.each_key do |k|
|
150
|
+
class2reqt[k]&.each do |k1|
|
151
|
+
ret[k1] ||= ret[k]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
ret
|
155
|
+
end
|
156
|
+
|
157
|
+
def reqt_id_base(docxml)
|
158
|
+
ret = reqt_id_base_init(docxml)
|
159
|
+
ret = reqt_id_base_inherit(ret, reqt_hierarchy_extract)
|
160
|
+
@modspecidentifierbase or return ret
|
161
|
+
ret.each_key { |k| ret[k] ||= @modspecidentifierbase }
|
162
|
+
end
|
163
|
+
|
120
164
|
def recommendation_link_class(ident)
|
121
165
|
test = @reqt_links_class[ident&.strip] or return nil
|
122
166
|
"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
|
@@ -143,6 +187,17 @@ module Metanorma
|
|
143
187
|
ret
|
144
188
|
end
|
145
189
|
|
190
|
+
def truncate_id_base_outside_reqts(docxml)
|
191
|
+
@modspecidentifierbase or return
|
192
|
+
|
193
|
+
(docxml.xpath(ns("//xref[@style = 'id']")) - docxml
|
194
|
+
.xpath(ns("//requirement//xref | //permission//xref | " \
|
195
|
+
"//recommendation//xref"))).each do |x|
|
196
|
+
@reqt_id_base[x["target"]] or next # is a modspec requirement
|
197
|
+
x.children = x.children.to_xml.delete_prefix(@modspecidentifierbase)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
146
201
|
def rec_subj(node)
|
147
202
|
case node["type"]
|
148
203
|
when "class" then @labels["modspec"]["targettype"]
|
@@ -4,6 +4,8 @@ module Metanorma
|
|
4
4
|
def requirement_table_cleanup(node, table)
|
5
5
|
table = requirement_table_nested_cleanup(node, table)
|
6
6
|
requirement_table_consec_rows_cleanup(node, table)
|
7
|
+
node.ancestors("requirement, recommendation, permission").empty? and
|
8
|
+
truncate_id_base_in_reqt(table)
|
7
9
|
table
|
8
10
|
end
|
9
11
|
|
@@ -57,6 +59,37 @@ module Metanorma
|
|
57
59
|
node["type"] == "conformanceclass" and label = "conformancetest"
|
58
60
|
@i18n.get["requirements"]["modspec"][label]
|
59
61
|
end
|
62
|
+
|
63
|
+
def strip_id_base(elem, base)
|
64
|
+
return elem.children if base.nil?
|
65
|
+
|
66
|
+
elem.children.to_xml.delete_prefix(base)
|
67
|
+
end
|
68
|
+
|
69
|
+
def truncate_id_base_in_reqt1(table, base)
|
70
|
+
table.xpath(ns(".//xref[@style = 'id']")).each do |x|
|
71
|
+
@reqt_id_base[x["target"]] or next # is a modspec requirement
|
72
|
+
x.children = strip_id_base(x, base)
|
73
|
+
end
|
74
|
+
table.xpath(ns(".//modspec-ident")).each do |x|
|
75
|
+
x.replace(strip_id_base(x, base))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# any xrefs not yet expanded out to rendering need to be expanded out,
|
80
|
+
# so that the identifier instances they contain can be truncated
|
81
|
+
def expand_xrefs_in_reqt(table)
|
82
|
+
table.xpath(ns(".//xref[not(@style)][normalize-space(text()) = '']"))
|
83
|
+
.each do |x|
|
84
|
+
x << @xrefs.anchor(x["target"], :xref, false)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def truncate_id_base_in_reqt(table)
|
89
|
+
base = @reqt_id_base[table["id"]]
|
90
|
+
expand_xrefs_in_reqt(table)
|
91
|
+
truncate_id_base_in_reqt1(table, base)
|
92
|
+
end
|
60
93
|
end
|
61
94
|
end
|
62
95
|
end
|
@@ -73,7 +73,8 @@ module Metanorma
|
|
73
73
|
super
|
74
74
|
anchor[:xref_bare] = anchor[:xref]
|
75
75
|
if l = block.at(ns("./identifier"))&.text
|
76
|
-
anchor[:xref] += l10n(": ") +
|
76
|
+
anchor[:xref] += l10n(": ") +
|
77
|
+
"<tt><xref style='id' target='#{block['id']}'>#{l}</xref></tt>"
|
77
78
|
end
|
78
79
|
anchor
|
79
80
|
end
|
@@ -5,7 +5,7 @@ require "metanorma-utils"
|
|
5
5
|
|
6
6
|
module Metanorma
|
7
7
|
class Requirements
|
8
|
-
attr_accessor :i18n, :labels
|
8
|
+
attr_accessor :i18n, :labels, :modspecidentifierbase
|
9
9
|
|
10
10
|
Hash.include Metanorma::Utils::Hash
|
11
11
|
|
@@ -17,6 +17,7 @@ module Metanorma
|
|
17
17
|
options[:labels])
|
18
18
|
# @labels = @i18n.get.deep_merge(options[:labels] || {})["requirements"]
|
19
19
|
@labels = @i18n.get["requirements"]
|
20
|
+
@modspecidentifierbase = options[:modspecidentifierbase]
|
20
21
|
@models =
|
21
22
|
model_names.each_with_object({}) { |k, m| m[k] = create(k) }
|
22
23
|
end
|
data/mn-requirements.gemspec
CHANGED
@@ -17,12 +17,13 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.license = "BSD-2-Clause"
|
18
18
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
-
f.match(%r{^(test|spec|features)/})
|
20
|
+
f.match(%r{^(test|spec|features|bin|.github)/}) \
|
21
|
+
|| f.match(%r{Rakefile|bin/rspec})
|
21
22
|
end
|
22
23
|
spec.bindir = "exe"
|
23
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
25
|
spec.require_paths = ["lib"]
|
25
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
26
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
26
27
|
|
27
28
|
spec.add_dependency "isodoc-i18n", "~> 1.1.2"
|
28
29
|
spec.add_dependency "metanorma-utils", "~> 1.4.0"
|
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.2.
|
4
|
+
version: 0.2.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: 2022-
|
11
|
+
date: 2022-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: isodoc-i18n
|
@@ -201,18 +201,12 @@ executables: []
|
|
201
201
|
extensions: []
|
202
202
|
extra_rdoc_files: []
|
203
203
|
files:
|
204
|
-
- ".github/workflows/rake.yml"
|
205
|
-
- ".github/workflows/release.yml"
|
206
204
|
- ".hound.yml"
|
207
205
|
- ".rubocop.yml"
|
208
206
|
- CODE_OF_CONDUCT.md
|
209
207
|
- Gemfile
|
210
208
|
- LICENSE
|
211
209
|
- README.adoc
|
212
|
-
- Rakefile
|
213
|
-
- bin/console
|
214
|
-
- bin/rspec
|
215
|
-
- bin/setup
|
216
210
|
- lib/isodoc-yaml/i18n-ar.yaml
|
217
211
|
- lib/isodoc-yaml/i18n-de.yaml
|
218
212
|
- lib/isodoc-yaml/i18n-en.yaml
|
@@ -249,14 +243,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
249
243
|
requirements:
|
250
244
|
- - ">="
|
251
245
|
- !ruby/object:Gem::Version
|
252
|
-
version: 2.
|
246
|
+
version: 2.7.0
|
253
247
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
254
248
|
requirements:
|
255
249
|
- - ">="
|
256
250
|
- !ruby/object:Gem::Version
|
257
251
|
version: '0'
|
258
252
|
requirements: []
|
259
|
-
rubygems_version: 3.
|
253
|
+
rubygems_version: 3.3.7
|
260
254
|
signing_key:
|
261
255
|
specification_version: 4
|
262
256
|
summary: Requirements processing and rendering according to different models
|
data/.github/workflows/rake.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
-
# See https://github.com/metanorma/cimas
|
3
|
-
name: rake
|
4
|
-
|
5
|
-
on:
|
6
|
-
push:
|
7
|
-
branches: [ master, main ]
|
8
|
-
tags: [ v* ]
|
9
|
-
pull_request:
|
10
|
-
|
11
|
-
jobs:
|
12
|
-
rake:
|
13
|
-
uses: metanorma/ci/.github/workflows/generic-rake.yml@main
|
14
|
-
secrets:
|
15
|
-
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
-
# See https://github.com/metanorma/cimas
|
3
|
-
name: release
|
4
|
-
|
5
|
-
on:
|
6
|
-
workflow_dispatch:
|
7
|
-
inputs:
|
8
|
-
next_version:
|
9
|
-
description: |
|
10
|
-
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
11
|
-
required: true
|
12
|
-
default: 'skip'
|
13
|
-
push:
|
14
|
-
tags: [ v* ]
|
15
|
-
|
16
|
-
jobs:
|
17
|
-
release:
|
18
|
-
uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
|
19
|
-
with:
|
20
|
-
next_version: ${{ github.event.inputs.next_version }}
|
21
|
-
release_command: rake release
|
22
|
-
bundler_cache: false
|
23
|
-
post_install: gem install bundler rake rspec
|
24
|
-
secrets:
|
25
|
-
rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
|
26
|
-
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
27
|
-
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "metanorma/ogc"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/rspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# This file was generated by Bundler.
|
4
|
-
#
|
5
|
-
# The application 'rspec' is installed as part of a gem, and
|
6
|
-
# this file is here to facilitate running it.
|
7
|
-
#
|
8
|
-
|
9
|
-
require "pathname"
|
10
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
|
11
|
-
"../../Gemfile", Pathname.new(__FILE__).realpath
|
12
|
-
)
|
13
|
-
|
14
|
-
require "rubygems"
|
15
|
-
require "bundler/setup"
|
16
|
-
|
17
|
-
load Gem.bin_path("rspec-core", "rspec")
|