metanorma-ogc 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require_relative "init"
2
+ require_relative "reqt"
2
3
  require "isodoc"
3
4
  require "uuidtools"
4
5
 
@@ -79,7 +80,7 @@ module IsoDoc
79
80
  end
80
81
 
81
82
  def recommendation1(f, type)
82
- type = recommendation_class(f)
83
+ type = recommendation_class_label(f)
83
84
  label = f&.at(ns("./label"))&.text
84
85
  if inject_crossreference_reqt?(f, label)
85
86
  n = @xrefs.anchor(@xrefs.reqtlabels[label], :xref, false)
@@ -98,7 +99,7 @@ module IsoDoc
98
99
  @xrefs.reqtlabels[label]
99
100
  end
100
101
 
101
- def recommendation_class(node)
102
+ def recommendation_class_label(node)
102
103
  case node["type"]
103
104
  when "verification" then @i18n.get["#{node.name}test"]
104
105
  when "class" then @i18n.get["#{node.name}class"]
@@ -130,6 +131,11 @@ module IsoDoc
130
131
  end
131
132
  end
132
133
 
134
+ def block(docxml)
135
+ super
136
+ recommendation_to_table(docxml)
137
+ end
138
+
133
139
  include Init
134
140
  end
135
141
  end
@@ -2,7 +2,7 @@ require "isodoc"
2
2
 
3
3
  module IsoDoc
4
4
  module Ogc
5
- module BaseConvert
5
+ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
6
6
  def recommend_class(node)
7
7
  return "recommendtest" if node["type"] == "verification"
8
8
  return "recommendtest" if node["type"] == "abstracttest"
@@ -11,52 +11,41 @@ module IsoDoc
11
11
  "recommend"
12
12
  end
13
13
 
14
- def recommend_table_attr(node)
15
- attr_code(id: node["id"], class: recommend_class(node),
16
- style: "border-collapse:collapse;border-spacing:0;"\
17
- "#{keep_style(node)}")
14
+ def recommendation_class(node)
15
+ node["type"] == "recommendtest" ?
16
+ "RecommendationTestTitle" : "RecommendationTitle"
18
17
  end
19
18
 
20
- REQ_TBL_ATTR =
21
- { style: "vertical-align:top;", class: "recommend" }.freeze
22
-
23
- def recommendation_class(node)
24
- %w(verification abstracttest).include?(node["type"]) ?
25
- "RecommendationTestTitle" : "RecommendationTitle"
19
+ def recommendation_header(r)
20
+ h = r.add_child("<thead><tr><th scope='colgroup' colspan='2'></th></tr></thead>")
21
+ recommendation_name(r, h.at(ns(".//th")))
26
22
  end
27
23
 
28
- def recommendation_name(node, out, type)
29
- label, title, lbl = recommendation_labels(node)
30
- out.p **{ class: recommendation_class(node) } do |b|
31
- lbl and lbl.children.each { |n| parse(n, b) }
24
+ def recommendation_name(node, out)
25
+ b = out.add_child("<p class='#{recommendation_class(node)}'></p>").first
26
+ if name = node&.at(ns("./name"))&.remove
27
+ name.children.each { |n| b << n }
32
28
  b << l10n(":")
33
- recommendation_name1(title, node, label, b)
34
29
  end
35
- end
36
-
37
- def recommendation_name1(title, node, label, b)
38
- return unless title
39
- b << " "
40
- title.children.each { |n| parse(n,b) }
30
+ if title = node&.at(ns("./title"))&.remove
31
+ b << l10n(" ") if name
32
+ title.children.each { |n| b << n }
33
+ end
41
34
  end
42
35
 
43
36
  def recommend_title(node, out)
44
- label = node.at(ns("./label")) or return
45
- out.tr do |tr|
46
- tr.td **REQ_TBL_ATTR.merge(colspan: 2) do |td|
47
- td.p do |p|
48
- label.children.each { |n| parse(n, p) }
49
- end
50
- end
51
- end
37
+ label = node&.at(ns("./label"))&.remove or return
38
+ b = out.add_child("<tr><td colspan='2'><p></p></td></tr>")
39
+ p = b.at(ns(".//p"))
40
+ p << label.children
52
41
  end
53
42
 
54
43
  def recommendation_attributes1(node)
55
44
  out = []
56
45
  oblig = node["obligation"] and out << ["Obligation", oblig]
57
- subj = node&.at(ns("./subject"))&.text and out << [rec_subj(node), subj]
46
+ subj = node&.at(ns("./subject"))&.remove&.children and out << [rec_subj(node), subj]
58
47
  node.xpath(ns("./inherit")).each do |i|
59
- out << recommendation_attr_parse(i, "Dependency")
48
+ out << ["Dependency", i.remove.children]
60
49
  end
61
50
  node.xpath(ns("./classification")).each do |c|
62
51
  line = recommendation_attr_keyvalue(c, "tag", "value") and out << line
@@ -65,103 +54,103 @@ module IsoDoc
65
54
  end
66
55
 
67
56
  def rec_subj(node)
68
- %w(class conformanceclass).include?(node["type"]) ?
69
- "Target Type" : "Subject"
70
- end
71
-
72
- def recommendation_attr_parse(node, label)
73
- text = noko do |xml|
74
- node.children.each { |n| parse(n, xml) }
75
- end.join
76
- [label, text]
57
+ node["type"] == "recommendclass" ? "Target Type" : "Subject"
77
58
  end
78
59
 
79
60
  def recommendation_attr_keyvalue(node, key, value)
80
- tag = node.at(ns("./#{key}")) or return nil
81
- value = node.at(ns("./#{value}")) or return nil
82
- [tag.text.capitalize, value.text]
61
+ tag = node&.at(ns("./#{key}"))&.remove
62
+ value = node.at(ns("./#{value}"))&.remove
63
+ tag && value or return nil
64
+ node.remove
65
+ [tag.text.capitalize, value.children]
83
66
  end
84
67
 
85
68
  def recommendation_attributes(node, out)
86
69
  recommendation_attributes1(node).each do |i|
87
- out.tr do |tr|
88
- tr.td **REQ_TBL_ATTR do |td|
89
- td << i[0]
90
- end
91
- tr.td **REQ_TBL_ATTR do |td|
92
- td << i[1]
93
- end
94
- end
70
+ out.add_child("<tr><td>#{i[0]}</td><td>#{i[1]}</td></tr>")
95
71
  end
96
72
  end
97
73
 
98
- def reqt_component_attrs(node)
99
- attr_code(style: keep_style(node))
74
+ def preserve_in_nested_table?(node)
75
+ return true if %w(recommendation requirement permission table).include?(node.name)
76
+ false
100
77
  end
101
78
 
102
79
  def requirement_component_parse(node, out)
80
+ node.remove
103
81
  return if node["exclude"] == "true"
104
82
  node.elements.size == 1 && node.first_element_child.name == "dl" and
105
83
  return reqt_dl(node.first_element_child, out)
106
- out.tr do |tr|
107
- tr.td **REQ_TBL_ATTR.merge(colspan: 2).
108
- merge(reqt_component_attrs(node)) do |td|
109
- node.children.each { |n| parse(n, td) }
110
- end
111
- end
84
+ b = out.add_child("<tr><td colspan='2'></td></tr>").first
85
+ b.at(ns(".//td")) << (preserve_in_nested_table?(node) ? node : node.children)
112
86
  end
113
87
 
114
88
  def reqt_dl(node, out)
115
89
  node.xpath(ns("./dt")).each do |dt|
116
- out.tr do |tr|
117
- tr.td **REQ_TBL_ATTR do |td|
118
- dt.children.each { |n| parse(n, td) }
119
- end
120
- dd = dt&.next_element and dd.name == "dd" or next
121
- tr.td **REQ_TBL_ATTR do |td|
122
- dd.children.each { |n| parse(n, td) }
123
- end
124
- end
90
+ dd = dt&.next_element
91
+ dt.remove
92
+ dd&.name == "dd" or next
93
+ b = out.add_child("<tr><td></td><td></td></tr>")
94
+ b.at(ns(".//td[1]")) << dt.children
95
+ b.at(ns(".//td[2]")) << dd.remove.children
125
96
  end
126
97
  end
127
98
 
128
- def recommendation_header(node, out, label)
129
- out.thead do |h|
130
- h.tr do |tr|
131
- tr.th **REQ_TBL_ATTR.merge(colspan: 2) do |td|
132
- recommendation_name(node, td, label)
133
- end
134
- end
135
- end
99
+ def recommendation_base(node, klass)
100
+ node.name = "table"
101
+ node["class"] = klass
102
+ node["type"] = recommend_class(node)
136
103
  end
137
104
 
138
- def recommendation_parse1(node, out, label)
139
- out.table **recommend_table_attr(node) do |t|
140
- recommendation_header(node, out, label)
141
- t.tbody do |b|
142
- recommend_title(node, b)
143
- recommendation_attributes(node, b)
144
- node.children.each do |n|
145
- parse(n, t) unless reqt_metadata_node(n)
146
- end
147
- end
105
+ def recommendation_parse1(node, klass)
106
+ recommendation_base(node, klass)
107
+ recommendation_header(node)
108
+ b = node.add_child("<tbody></tbody>").first
109
+ recommend_title(node, b)
110
+ recommendation_attributes(node, b)
111
+ node.elements.each do |n|
112
+ next if %w(thead tbody).include?(n.name)
113
+ requirement_component_parse(n, b)
148
114
  end
149
115
  end
150
116
 
151
- def recommendation_parse(node, out)
152
- recommendation_parse0(node, out, "recommendation")
153
- end
154
-
155
- def recommendation_parse0(node, out, r)
156
- recommendation_parse1(node, out, nil)
157
- end
158
-
159
- def requirement_parse(node, out)
160
- recommendation_parse0(node, out, "requirement")
161
- end
162
-
163
- def permission_parse(node, out)
164
- recommendation_parse0(node, out, "permission")
117
+ def recommendation_to_table(docxml)
118
+ docxml.xpath(ns("//recommendation")).each do |r|
119
+ recommendation_parse1(r, "recommendation")
120
+ end
121
+ docxml.xpath(ns("//requirement")).each do |r|
122
+ recommendation_parse1(r, "requirement")
123
+ end
124
+ docxml.xpath(ns("//permission")).each do |r|
125
+ recommendation_parse1(r, "permission")
126
+ end
127
+ requirement_table_cleanup(docxml)
128
+ end
129
+
130
+ # table nested in table: merge label and caption into a single row
131
+ def requirement_table_cleanup1(x, y)
132
+ x.delete("colspan")
133
+ x.delete("scope")
134
+ y.delete("colspan")
135
+ y.delete("scope")
136
+ x.name = "td"
137
+ p = x.at(ns("./p[@class = 'RecommendationTitle']")) and
138
+ p.delete("class")
139
+ x.parent << y.dup
140
+ y.parent.remove
141
+ end
142
+
143
+ def requirement_table_cleanup(docxml)
144
+ docxml.xpath(ns("//table[@type = 'recommendclass']/tbody/tr/td/table")).each do |t|
145
+ x = t.at(ns("./thead")) and x.replace(x.children)
146
+ x = t.at(ns("./tbody")) and x.replace(x.children)
147
+ x = t.at(ns("./tfoot")) and x.replace(x.children)
148
+ if x = t.at(ns("./tr/th[@colspan = '2']")) and
149
+ y = t.at(ns("./tr/td[@colspan = '2']"))
150
+ requirement_table_cleanup1(x, y)
151
+ end
152
+ t.parent.parent.replace(t.children)
153
+ end
165
154
  end
166
155
  end
167
156
  end
@@ -139,6 +139,7 @@ module IsoDoc
139
139
  @prefacenum = 0
140
140
  info docxml, div2
141
141
  boilerplate docxml, div2
142
+ preface_block docxml, div2
142
143
  abstract docxml, div2
143
144
  keywords docxml, div2
144
145
  foreword docxml, div2
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ogc
3
- VERSION = "1.2.1"
3
+ VERSION = "1.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ogc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.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: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-standoc