mn-requirements 0.4.0 → 0.4.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: 01bee8304acc8f185870fb5f6960e2a7393d096acc9cdf9ea4e87918baf297e0
4
- data.tar.gz: 11412398e35579a0e3022250101a3629409b7f784da526d152de6a1a69c00e33
3
+ metadata.gz: 75b1df8d56f422dda0f7d9ad8118a4ec48dd57c2d05994b84119e5f8bbf2d5cd
4
+ data.tar.gz: 436b0b873cdba89c706bbd549ad4aa4bbfd23ff551a017af10b611f340f6f9af
5
5
  SHA512:
6
- metadata.gz: e9d3f86cd517967140e1febd7c7852d55dd3b1b4b8c74d1159c335d42717fc51c960218caf5631d9f135701b8f812b830685ad5224ac9dbc4249ee24a0cfcda9
7
- data.tar.gz: 7cc6c088de6e4ea5ae8050844ccf0d9cf49369bf63b89ffa4892316539d57d5ae89074fe184191a4e78e940d59efef1abc09e3bd88805125ff734aeb7f11f735
6
+ metadata.gz: 1bec02a150e493a2fa71fedeaa42c9d1167c13022a82106c6ab91974e26a0ae6e96088b879d21afc2fbc9bc83d44c88af982579ad3bc2ddfb74a56c7658a50ec
7
+ data.tar.gz: b508da3936b44d98d437c4c7c27b46515a55bcb01671c1040cd282f6472013b7c6426b8c0703ce476ba482671dc7222487ab12d10c5c7efc02f7372ca701dd50
data/lib/isodoc/i18n.rb CHANGED
@@ -5,7 +5,7 @@ module IsoDoc
5
5
  class MnRequirementsI18n < I18n
6
6
  def load_yaml1(lang, script)
7
7
  case lang
8
- when "en", "fr", "ru", "de", "es", "ar"
8
+ when "en", "fr", "ru", "de", "es", "ar", "ja"
9
9
  load_yaml2(lang)
10
10
  when "zh"
11
11
  if script == "Hans" then load_yaml2("zh-Hans")
@@ -0,0 +1,31 @@
1
+ requirements:
2
+ default:
3
+ requirement: 要求
4
+ recommendation: 推奨
5
+ permission: 許可
6
+ obligation: 義務
7
+ subject: 主題
8
+ inherits: 継承
9
+ modspec:
10
+ recommendationtest: 要求テスト
11
+ requirementtest: 要求テスト
12
+ permissiontest: 許可テスト
13
+ recommendationclass: 要求クラス
14
+ requirementclass: 要求クラス
15
+ permissionclass: 許可クラス
16
+ abstracttest: 抽象テスト
17
+ conformanceclass: 適合クラス
18
+ conformancetest: 適合性テスト
19
+ targettype: ターゲットタイプ
20
+ target: ターゲット
21
+ testpurpose: テスト目的
22
+ testmethod: 試験方法
23
+ dependency: 前提条件
24
+ indirectdependency: 間接的な前提条件
25
+ identifier: 識別子
26
+ included_in: 含まれる
27
+ statement: 声明
28
+ description: 説明
29
+ guidance: ガイダンス
30
+ implements: 実装
31
+ provision: 規範的声明
@@ -72,7 +72,7 @@ module Metanorma
72
72
  end
73
73
 
74
74
  def requirement_metadata1_attrs
75
- %w(obligation model type)
75
+ %w(obligation model type class)
76
76
  end
77
77
 
78
78
  def requirement_metadata1_tags
@@ -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)
@@ -65,6 +65,7 @@ module Metanorma
65
65
  obligation: node.attr("obligation"),
66
66
  filename: node.attr("filename"),
67
67
  type: node.attr("type"),
68
+ class: node.attr("class"),
68
69
  ))
69
70
  end
70
71
 
@@ -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
@@ -34,7 +34,7 @@ module Metanorma
34
34
  def requirement_metadata1(reqt, dlist, ins)
35
35
  ins1 = super
36
36
  dlist.xpath("./dt").each do |e|
37
- tag = e.text&.gsub(/ /, "-")&.downcase
37
+ tag = e.text&.tr(" ", "-")&.downcase
38
38
  tag = "description" if tag == "statement"
39
39
  next unless requirement_metadata_component_tags.include?(tag)
40
40
 
@@ -93,7 +93,8 @@ module Metanorma
93
93
  end
94
94
 
95
95
  def requirement_metadata_to_component(reqt)
96
- xpath = requirement_metadata_component_tags - %w(statement description) -
96
+ xpath = requirement_metadata_component_tags - %w(statement
97
+ description) -
97
98
  requirement_metadata_requirement_tags
98
99
  reqt.xpath(xpath.map { |x| ".//#{x}" }.join(" | ")).each do |c|
99
100
  c["class"] = c.name
@@ -126,7 +127,7 @@ module Metanorma
126
127
  next if %w(p ol ul dl table component description)
127
128
  .include?(c&.elements&.first&.name)
128
129
 
129
- c.children = "<p>#{c.children.to_xml}</p>"
130
+ c.children = "<p>#{to_xml(c.children)}</p>"
130
131
  end
131
132
  end
132
133
 
@@ -8,7 +8,9 @@ module Metanorma
8
8
  def requirement_render1(node)
9
9
  init_lookups(node.document)
10
10
  ret = requirement_guidance_parse(node, super)
11
- requirement_table_cleanup(node, ret)
11
+ out = requirement_table_cleanup(node, ret)
12
+ out["class"] = "modspec" # deferred; node["class"] is labelling class
13
+ out
12
14
  end
13
15
 
14
16
  def recommendation_base(node, _klass)
@@ -17,7 +19,6 @@ module Metanorma
17
19
  %w(id keep-with-next keep-lines-together unnumbered).each do |x|
18
20
  out[x] = node[x] if node[x]
19
21
  end
20
- out["class"] = "modspec"
21
22
  out["type"] = recommend_class(node)
22
23
  recommendation_component_labels(node)
23
24
  out
@@ -33,11 +34,11 @@ module Metanorma
33
34
  end
34
35
 
35
36
  def recommendation_header(reqt, out)
36
- n = recommendation_name(reqt, nil)
37
+ n = reqt.at(ns("./fmt-name"))
37
38
  x = if reqt.ancestors("requirement, recommendation, permission").empty?
38
- "<thead><tr><th scope='colgroup' colspan='2'>" \
39
- "<p class='#{recommend_name_class(reqt)}'>#{n}</p>" \
40
- "</th></tr></thead>"
39
+ <<~THEAD
40
+ <thead><tr><th scope='colgroup' colspan='2'><p class='#{recommend_name_class(reqt)}'>#{n}</p></th></tr></thead>
41
+ THEAD
41
42
  else
42
43
  "<thead><tr><th>#{recommendation_class_label(reqt)}</th>" \
43
44
  "<td>#{n}</td></tr></thead>"
@@ -46,10 +47,11 @@ module Metanorma
46
47
  out
47
48
  end
48
49
 
50
+ =begin
49
51
  def recommendation_name(node, _out)
50
52
  ret = ""
51
- name = node.at(ns("./name")) and ret += name.children.to_xml
52
- 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"))
53
55
  return ret unless title &&
54
56
  node.ancestors("requirement, recommendation, permission").empty?
55
57
 
@@ -57,6 +59,25 @@ module Metanorma
57
59
  ret += title.children.to_xml
58
60
  l10n(ret)
59
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
60
81
 
61
82
  def recommendation_attributes(node, out)
62
83
  ins = out.add_child("<tbody></tbody>").first
@@ -71,7 +92,7 @@ module Metanorma
71
92
  label = node.at(ns("./identifier")) or return
72
93
  ret = <<~OUTPUT
73
94
  <tr><th>#{@labels['modspec']['identifier']}</th>
74
- <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>
75
96
  OUTPUT
76
97
  out.add_child(ret)
77
98
  end
@@ -119,7 +140,7 @@ module Metanorma
119
140
  def recommendation_attributes1_inherit(node, head)
120
141
  node.xpath(ns("./inherit")).each do |i|
121
142
  head << [@labels["modspec"]["dependency"],
122
- recommendation_id(i.children.to_xml)]
143
+ recommendation_id(to_xml(i.children))]
123
144
  end
124
145
  head
125
146
  end
@@ -128,8 +149,8 @@ module Metanorma
128
149
  %w(indirect-dependency implements).each do |x|
129
150
  node.xpath(ns("./classification[tag][value]")).each do |c|
130
151
  c.at(ns("./tag")).text.casecmp(x).zero? or next
131
- xref = recommendation_id(c.at(ns("./value")).children.to_xml) and
132
- head << [@labels["modspec"][x.gsub(/-/, "")], xref]
152
+ xref = recommendation_id(to_xml(c.at(ns("./value")).children)) and
153
+ head << [@labels["modspec"][x.delete("-")], xref]
133
154
  end
134
155
  end
135
156
  head
@@ -145,9 +166,9 @@ module Metanorma
145
166
 
146
167
  d = node.at(ns("./component[@class = 'step']"))
147
168
  d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \
148
- "#{d.children.to_xml}</li></ol>").first
169
+ "#{to_xml(d.children)}</li></ol>").first
149
170
  node.xpath(ns("./component[@class = 'step']")).each do |f|
150
- 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
151
172
  d << f
152
173
  end
153
174
  node
@@ -202,7 +223,7 @@ module Metanorma
202
223
  recommend_class(node.parent) == "recommend" and
203
224
  lbl = "statement"
204
225
  out << "<tr><th>#{@labels['modspec'][lbl]}</th>" \
205
- "<td>#{node.children.to_xml}</td></tr>"
226
+ "<td>#{to_xml(node.children)}</td></tr>"
206
227
  out
207
228
  end
208
229
 
@@ -219,8 +240,8 @@ module Metanorma
219
240
  node.xpath(ns("./dt")).each do |dt|
220
241
  dd = dt.next_element
221
242
  dd&.name == "dd" or next
222
- out.add_child("<tr><th>#{dt.children.to_xml}</th>" \
223
- "<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>")
224
245
  end
225
246
  out
226
247
  end
@@ -1,7 +1,11 @@
1
- class Nokogiri::XML::Document
2
- def reqt_iter(&block)
3
- xpath("//xmlns:requirement | //xmlns:recommendation | //xmlns:permission")
4
- .each_with_object({}, &block)
1
+ module Nokogiri
2
+ module XML
3
+ class Document
4
+ def reqt_iter(&block)
5
+ xpath("//xmlns:requirement | //xmlns:recommendation | //xmlns:permission")
6
+ .each_with_object({}, &block)
7
+ end
8
+ end
5
9
  end
6
10
  end
7
11
 
@@ -23,10 +27,11 @@ module Metanorma
23
27
  def recommendation_label_xref(elem, label, xrefs, type)
24
28
  id = @reqtlabels[label]
25
29
  number = xrefs.anchor(id, :modspec, false)
26
- number.nil? and return type
30
+ number.nil? and return "<span class='fmt-element-name'>#{type}</span>"
27
31
  elem.ancestors("requirement, recommendation, permission").empty? and
28
32
  return number
29
- "<xref target='#{id}'>#{number}</xref>"
33
+ #"<xref target='#{id}'>#{number}</xref>"
34
+ number
30
35
  end
31
36
 
32
37
  def init_lookups(doc)
@@ -54,17 +59,13 @@ module Metanorma
54
59
  end
55
60
 
56
61
  def recommendation_class_label(node)
62
+ node["class"] and return node["class"]
57
63
  case node["type"]
58
- when "verification" then @labels["modspec"]["conformancetest"]
59
64
  when "class" then @labels["modspec"]["#{node.name}class"]
60
- when "abstracttest" then @labels["modspec"]["abstracttest"]
61
- when "conformanceclass" then @labels["modspec"]["conformanceclass"]
62
- else
63
- case node.name
64
- when "recommendation" then @labels["default"]["recommendation"]
65
- when "requirement" then @labels["default"]["requirement"]
66
- when "permission" then @labels["default"]["permission"]
67
- end
65
+ when "verification" then @labels["modspec"]["conformancetest"]
66
+ when "abstracttest", "conformanceclass"
67
+ @labels["modspec"][node["type"]]
68
+ else @labels["default"][node.name]
68
69
  end
69
70
  end
70
71
 
@@ -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,7 +96,7 @@ 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|
99
101
  ref = @xrefs.anchor(x["target"], :xref, false) or next
100
102
  x << ref
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  class Requirements
3
- VERSION = "0.4.0".freeze
3
+ VERSION = "0.4.2".freeze
4
4
  end
5
5
  end
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.0
4
+ version: 0.4.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: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2024-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: isodoc-i18n
@@ -226,6 +226,7 @@ files:
226
226
  - lib/isodoc-yaml/i18n-en.yaml
227
227
  - lib/isodoc-yaml/i18n-es.yaml
228
228
  - lib/isodoc-yaml/i18n-fr.yaml
229
+ - lib/isodoc-yaml/i18n-ja.yaml
229
230
  - lib/isodoc-yaml/i18n-ru.yaml
230
231
  - lib/isodoc-yaml/i18n-zh-Hans.yaml
231
232
  - lib/isodoc/i18n.rb