mn-requirements 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd0f29f7ad1df5f2127ec2c47f22d03e50bc6ec18e76459352ba6d873117d049
4
- data.tar.gz: 60f5b1e8cd4463f0d2492731a502b33ea9b9d3930fa5fc09d99b2aa14285f153
3
+ metadata.gz: a12dad7f5d6cb715ade06167544dc2966581c8b9692b4d67de71664ddf401f23
4
+ data.tar.gz: 04cff2ddfd3116155014720376fbcf98c2d88bece77a12c748cd0726814d4c2e
5
5
  SHA512:
6
- metadata.gz: 9028d71bdb94818359b7ebda35103973ce7906eae30aad1b881085fccdde2d78f6a07edb5fdc939c9234738751a48bda2a06bafba6809457808ba5fe563b189c
7
- data.tar.gz: 83e2726e3edeb550d272860a8e477a50629bc298468555cb3fcf251b60b318a4e63a42b750d2812542bf8185007b0da0eb0ad49a926f4e0688c7c2a4b55efd5b
6
+ metadata.gz: dfc9ce13b9304cd254e0d2f941f04d48607041922aa0333417f57d61867495c4c486c2f2be459cbb46de52509a46e0f5b8f5460c6319310ee166864e2aac7797
7
+ data.tar.gz: f7a0989cc2212bc9186acf262a75bac6712bb9e7bdc7ae0d5c417446bce63f40dc7c8af9568b144a59a95914a0ff82f116af49586c75887697b079f7afa386a5
@@ -112,7 +112,7 @@ module Metanorma
112
112
  def unwrap_para(ddef)
113
113
  e = ddef.elements and e.size == 1 && e.first.name == "p" and
114
114
  ddef = e.first
115
- ddef.children.to_xml
115
+ to_xml(ddef.children)
116
116
  end
117
117
 
118
118
  def reqt_dl_to_classif(ins, reqt, dlist)
@@ -6,13 +6,33 @@ module Metanorma
6
6
  end
7
7
 
8
8
  def recommendation_label(elem, type, xrefs)
9
- number = xrefs.anchor(elem["id"], :label, false)
10
- (number.nil? ? type : "#{type} #{number}")
9
+ label, title = recommendation_labels(elem)
10
+ type = "<span class='fmt-element-name'>#{type}</span>"
11
+ num = xrefs.anchor(elem["id"], :label, false)
12
+ num &&= "<semx element='autonum' source='#{elem['id']}'>#{num}</semx>"
13
+ ret = "#{type} #{num}".strip
14
+ label || title and
15
+ ret += recommendation_label_add(elem, label, title)
16
+ ret
17
+ end
18
+
19
+ def recommendation_label_add(elem, label, title)
20
+ r = recommendation_label_caption_delim
21
+ label and
22
+ r += "<semx element='identifier' source='#{elem['id']}'>#{label}</semx>"
23
+ label && title and r += ". "
24
+ title and
25
+ r += "<semx element='title' source='#{elem['id']}'>#{title}</semx>"
26
+ r
27
+ end
28
+
29
+ def recommendation_label_caption_delim
30
+ "<span class='fmt-caption-delim'>:<br/></span>"
11
31
  end
12
32
 
13
33
  def reqt_metadata_node?(node)
14
34
  %w(identifier title subject classification tag value
15
- inherit name).include? node.name
35
+ inherit name fmt-name fmt-xref-label fmt-title).include? node.name
16
36
  end
17
37
 
18
38
  def requirement_render1(node)
@@ -25,35 +45,27 @@ module Metanorma
25
45
  out
26
46
  end
27
47
 
48
+ def recommendation_header(_node, out)
49
+ out
50
+ end
51
+
28
52
  def recommendation_base(node, klass)
29
53
  out = node.document.create_element(klass)
30
54
  node.attributes.each do |k, v|
31
55
  out[k] = v
32
56
  end
57
+ n = node.at(ns("./fmt-name")) and out << n
58
+ n = node.at(ns("./fmt-xref-label")) and out << n
33
59
  out
34
60
  end
35
61
 
36
62
  def recommendation_labels(node)
37
- [node.at(ns("./identifier")), node.at(ns("./title")),
38
- node.at(ns("./name"))]
63
+ [node.at(ns("./identifier")), node.at(ns("./title"))]
39
64
  .map do |n|
40
- n&.children&.to_xml
65
+ to_xml(n&.children)
41
66
  end
42
67
  end
43
68
 
44
- def recommendation_header(node, out)
45
- label, title, name = recommendation_labels(node)
46
- ret = name ? [name] : []
47
- if label || title
48
- ret << ":" unless ret.empty?
49
- ret += ["<br/>", label]
50
- ret << ". " if label && title
51
- ret << title
52
- end
53
- out << "<name>#{l10n(ret.compact.join)}</name>"
54
- out
55
- end
56
-
57
69
  def recommendation_attributes1(node, out)
58
70
  oblig = node["obligation"] and
59
71
  out << l10n("#{@labels['default']['obligation']}: #{oblig}")
@@ -70,14 +82,14 @@ module Metanorma
70
82
  end
71
83
 
72
84
  def recommendation_attr_parse(node, label)
73
- l10n("#{label}: #{node.children.to_xml}")
85
+ l10n("#{label}: #{to_xml(node.children)}")
74
86
  end
75
87
 
76
88
  def recommendation_attr_keyvalue(node, key, value)
77
89
  tag = node.at(ns("./#{key}")) or return nil
78
90
  value = node.at(ns("./#{value}")) or return nil
79
91
  l10n("#{Metanorma::Utils.strict_capitalize_first tag.text}: " \
80
- "#{value.children.to_xml}")
92
+ "#{to_xml(value.children)}")
81
93
  end
82
94
 
83
95
  def recommendation_attributes(node, out)
@@ -22,6 +22,11 @@ module Metanorma
22
22
  def ns(xpath)
23
23
  Metanorma::Utils.ns(xpath)
24
24
  end
25
+
26
+ def to_xml(node)
27
+ node&.to_xml(encoding: "UTF-8", indent: 0,
28
+ save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -127,7 +127,7 @@ module Metanorma
127
127
  next if %w(p ol ul dl table component description)
128
128
  .include?(c&.elements&.first&.name)
129
129
 
130
- c.children = "<p>#{c.children.to_xml}</p>"
130
+ c.children = "<p>#{to_xml(c.children)}</p>"
131
131
  end
132
132
  end
133
133
 
@@ -34,7 +34,7 @@ module Metanorma
34
34
  end
35
35
 
36
36
  def recommendation_header(reqt, out)
37
- n = recommendation_name(reqt, nil)
37
+ n = reqt.at(ns("./fmt-name"))
38
38
  x = if reqt.ancestors("requirement, recommendation, permission").empty?
39
39
  <<~THEAD
40
40
  <thead><tr><th scope='colgroup' colspan='2'><p class='#{recommend_name_class(reqt)}'>#{n}</p></th></tr></thead>
@@ -47,10 +47,11 @@ module Metanorma
47
47
  out
48
48
  end
49
49
 
50
+ =begin
50
51
  def recommendation_name(node, _out)
51
52
  ret = ""
52
- name = node.at(ns("./name")) and ret += name.children.to_xml
53
- title = node.at(ns("./title"))
53
+ name = node.at(ns("./fmt-name")) and ret += name.children.to_xml
54
+ title = node.at(ns("./fmt-title"))
54
55
  return ret unless title &&
55
56
  node.ancestors("requirement, recommendation, permission").empty?
56
57
 
@@ -58,6 +59,25 @@ module Metanorma
58
59
  ret += title.children.to_xml
59
60
  l10n(ret)
60
61
  end
62
+ =end
63
+
64
+ def recommendation_label_add(elem, _label, title)
65
+ title or return ""
66
+ r = recommendation_label_caption_delim
67
+ title and
68
+ r += "<semx element='title' source='#{elem['id']}'>#{title}</semx>"
69
+ r
70
+ end
71
+
72
+ def recommendation_label_caption_delim
73
+ "<span class='fmt-caption-delim'>: </span>"
74
+ end
75
+
76
+ def recommendation_labels(node)
77
+ node.ancestors("requirement, recommendation, permission").empty? or
78
+ return [nil, nil]
79
+ super
80
+ end
61
81
 
62
82
  def recommendation_attributes(node, out)
63
83
  ins = out.add_child("<tbody></tbody>").first
@@ -72,7 +92,7 @@ module Metanorma
72
92
  label = node.at(ns("./identifier")) or return
73
93
  ret = <<~OUTPUT
74
94
  <tr><th>#{@labels['modspec']['identifier']}</th>
75
- <td><tt><modspec-ident>#{label.children.to_xml}</modspec-ident></tt></td>
95
+ <td><tt><modspec-ident>#{to_xml(label.children)}</modspec-ident></tt></td>
76
96
  OUTPUT
77
97
  out.add_child(ret)
78
98
  end
@@ -120,7 +140,7 @@ module Metanorma
120
140
  def recommendation_attributes1_inherit(node, head)
121
141
  node.xpath(ns("./inherit")).each do |i|
122
142
  head << [@labels["modspec"]["dependency"],
123
- recommendation_id(i.children.to_xml)]
143
+ recommendation_id(to_xml(i.children))]
124
144
  end
125
145
  head
126
146
  end
@@ -129,7 +149,7 @@ module Metanorma
129
149
  %w(indirect-dependency implements).each do |x|
130
150
  node.xpath(ns("./classification[tag][value]")).each do |c|
131
151
  c.at(ns("./tag")).text.casecmp(x).zero? or next
132
- xref = recommendation_id(c.at(ns("./value")).children.to_xml) and
152
+ xref = recommendation_id(to_xml(c.at(ns("./value")).children)) and
133
153
  head << [@labels["modspec"][x.delete("-")], xref]
134
154
  end
135
155
  end
@@ -146,9 +166,9 @@ module Metanorma
146
166
 
147
167
  d = node.at(ns("./component[@class = 'step']"))
148
168
  d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \
149
- "#{d.children.to_xml}</li></ol>").first
169
+ "#{to_xml(d.children)}</li></ol>").first
150
170
  node.xpath(ns("./component[@class = 'step']")).each do |f|
151
- f = f.replace("<li#{id_attr(f)}>#{f.children.to_xml}</li>").first
171
+ f = f.replace("<li#{id_attr(f)}>#{to_xml(f.children)}</li>").first
152
172
  d << f
153
173
  end
154
174
  node
@@ -203,7 +223,7 @@ module Metanorma
203
223
  recommend_class(node.parent) == "recommend" and
204
224
  lbl = "statement"
205
225
  out << "<tr><th>#{@labels['modspec'][lbl]}</th>" \
206
- "<td>#{node.children.to_xml}</td></tr>"
226
+ "<td>#{to_xml(node.children)}</td></tr>"
207
227
  out
208
228
  end
209
229
 
@@ -220,8 +240,8 @@ module Metanorma
220
240
  node.xpath(ns("./dt")).each do |dt|
221
241
  dd = dt.next_element
222
242
  dd&.name == "dd" or next
223
- out.add_child("<tr><th>#{dt.children.to_xml}</th>" \
224
- "<td>#{dd.children.to_xml}</td></tr>")
243
+ out.add_child("<tr><th>#{to_xml(dt.children)}</th>" \
244
+ "<td>#{to_xml(dd.children)}</td></tr>")
225
245
  end
226
246
  out
227
247
  end
@@ -27,10 +27,11 @@ module Metanorma
27
27
  def recommendation_label_xref(elem, label, xrefs, type)
28
28
  id = @reqtlabels[label]
29
29
  number = xrefs.anchor(id, :modspec, false)
30
- number.nil? and return type
30
+ number.nil? and return "<span class='fmt-element-name'>#{type}</span>"
31
31
  elem.ancestors("requirement, recommendation, permission").empty? and
32
32
  return number
33
- "<xref target='#{id}'>#{number}</xref>"
33
+ #"<xref target='#{id}'>#{number}</xref>"
34
+ number
34
35
  end
35
36
 
36
37
  def init_lookups(doc)
@@ -103,7 +104,8 @@ module Metanorma
103
104
 
104
105
  def recommendation_link_test(ident)
105
106
  test = @reqt_links_test[ident&.strip] or return nil
106
- "<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
107
+ #"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
108
+ test[:lbl]
107
109
  end
108
110
 
109
111
  # we have not implemented multiple levels of nesting of classes
@@ -155,12 +157,15 @@ module Metanorma
155
157
 
156
158
  def recommendation_link_class(ident)
157
159
  test = @reqt_links_class[ident&.strip] or return nil
158
- "<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
160
+ #"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
161
+ test[:lbl]
159
162
  end
160
163
 
161
164
  def recommendation_id(ident)
162
165
  test = @reqt_ids[ident&.strip] or return ident&.strip
163
- "<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
166
+ #require "debug"; binding.b if test.include?("<xref")
167
+ #"<xref target='#{test[:id]}'>#{test[:lbl]}</xref>"
168
+ test[:lbl]
164
169
  end
165
170
 
166
171
  def recommendation_backlinks_test(node, id, ret)
@@ -185,7 +190,7 @@ module Metanorma
185
190
  .xpath(ns("//requirement//xref | //permission//xref | " \
186
191
  "//recommendation//xref"))).each do |x|
187
192
  @reqt_id_base[x["target"]] or next # is a modspec requirement
188
- x.children = x.children.to_xml.delete_prefix(@modspecidentifierbase)
193
+ x.children = to_xml(x.children).delete_prefix(@modspecidentifierbase)
189
194
  end
190
195
  end
191
196
 
@@ -46,7 +46,7 @@ module Metanorma
46
46
  hdr = th.text
47
47
  th.children = @i18n.inflect(hdr, number: "pl")
48
48
  td = th.next_element
49
- res = [td.children.to_xml]
49
+ res = [to_xml(td.children)]
50
50
  res += gather_consec_table_rows(trow, hdr)
51
51
  td.children = res.join("<br/>")
52
52
  end
@@ -55,7 +55,7 @@ module Metanorma
55
55
  ret = []
56
56
  trow.xpath("./following-sibling::xmlns:tr").each do |r|
57
57
  r.at(ns("./th[text() = '#{hdr}']")) or break
58
- ret << r.remove.at(ns("./td")).children.to_xml
58
+ ret << to_xml(r.remove.at(ns("./td")).children)
59
59
  end
60
60
  ret
61
61
  end
@@ -65,6 +65,8 @@ module Metanorma
65
65
  x = t.at(ns("./thead/tr")) or next
66
66
  x.at(ns("./th")).children =
67
67
  requirement_table_nested_cleanup_hdr(node)
68
+ f = x.at(ns("./td/fmt-name")) and
69
+ f.replace(f.children)
68
70
  t.parent.parent.replace(x)
69
71
  end
70
72
  table
@@ -78,7 +80,7 @@ module Metanorma
78
80
 
79
81
  def strip_id_base(elem, base)
80
82
  base.nil? and return elem.children
81
- elem.children.to_xml.delete_prefix(base)
83
+ to_xml(elem.children).delete_prefix(base)
82
84
  end
83
85
 
84
86
  def truncate_id_base_in_reqt1(table, base)
@@ -94,8 +96,9 @@ module Metanorma
94
96
  # any xrefs not yet expanded out to rendering need to be expanded out,
95
97
  # so that the identifier instances they contain can be truncated
96
98
  def expand_xrefs_in_reqt(table)
97
- table.xpath(ns(".//xref[not(@style)][normalize-space(text()) = '']"))
99
+ table.xpath(ns(".//xref[not(@style)][string-length() = 0]"))
98
100
  .each do |x|
101
+ @xrefs.anchor(x["target"], :modspec, false) or next # modspec xrefs only
99
102
  ref = @xrefs.anchor(x["target"], :xref, false) or next
100
103
  x << ref
101
104
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  class Requirements
3
- VERSION = "0.4.1".freeze
3
+ VERSION = "0.4.3".freeze
4
4
  end
5
5
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  # precise version is on relaton-render
29
29
  spec.add_dependency "isodoc-i18n", ">= 1.1.0"
30
30
  spec.add_dependency "metanorma-utils", ">= 0.10.0"
31
+ spec.add_dependency "relaton-render", ">= 0.9.0"
31
32
 
32
33
  spec.add_development_dependency "debug"
33
34
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
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.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-14 00:00:00.000000000 Z
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: isodoc-i18n
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: relaton-render
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: debug
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -250,7 +264,7 @@ homepage: https://github.com/metanorma/mn-requirements
250
264
  licenses:
251
265
  - BSD-2-Clause
252
266
  metadata: {}
253
- post_install_message:
267
+ post_install_message:
254
268
  rdoc_options: []
255
269
  require_paths:
256
270
  - lib
@@ -266,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
280
  version: '0'
267
281
  requirements: []
268
282
  rubygems_version: 3.3.27
269
- signing_key:
283
+ signing_key:
270
284
  specification_version: 4
271
285
  summary: Requirements processing and rendering according to different models
272
286
  test_files: []