metanorma-iso 1.1.5 → 1.2.0

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.
@@ -0,0 +1,190 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require "fileutils"
4
+
5
+ module IsoDoc
6
+ module Iso
7
+ module BaseConvert
8
+ def metadata_init(lang, script, labels)
9
+ @meta = Metadata.new(lang, script, labels)
10
+ end
11
+
12
+ def implicit_reference(b)
13
+ isocode = b.at(ns("./docidentifier")).text
14
+ isocode == "IEV"
15
+ end
16
+
17
+ def introduction(isoxml, out)
18
+ f = isoxml.at(ns("//introduction")) || return
19
+ num = f.at(ns(".//clause")) ? "0" : nil
20
+ title_attr = { class: "IntroTitle" }
21
+ page_break(out)
22
+ out.div **{ class: "Section3", id: f["id"] } do |div|
23
+ # div.h1 "Introduction", **attr_code(title_attr)
24
+ clause_name(num, @introduction_lbl, div, title_attr)
25
+ f.elements.each do |e|
26
+ if e.name == "patent-notice"
27
+ e.elements.each { |e1| parse(e1, div) }
28
+ else
29
+ parse(e, div) unless e.name == "title"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def foreword(isoxml, out)
36
+ f = isoxml.at(ns("//foreword")) || return
37
+ page_break(out)
38
+ out.div **attr_code(id: f["id"]) do |s|
39
+ s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl }
40
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
41
+ end
42
+ end
43
+
44
+ def initial_anchor_names(d)
45
+ super
46
+ introduction_names(d.at(ns("//introduction")))
47
+ end
48
+
49
+ # we can reference 0-number clauses in introduction
50
+ def introduction_names(clause)
51
+ return if clause.nil?
52
+ clause.xpath(ns("./clause")).each_with_index do |c, i|
53
+ section_names1(c, "0.#{i + 1}", 2)
54
+ end
55
+ end
56
+
57
+ # terms not defined in standoc
58
+ def error_parse(node, out)
59
+ case node.name
60
+ when "appendix" then clause_parse(node, out)
61
+ else
62
+ super
63
+ end
64
+ end
65
+
66
+ def annex_names(clause, num)
67
+ appendix_names(clause, num)
68
+ super
69
+ end
70
+
71
+ def appendix_names(clause, num)
72
+ clause.xpath(ns("./appendix")).each_with_index do |c, i|
73
+ @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl, "clause")
74
+ @anchors[c["id"]][:level] = 2
75
+ @anchors[c["id"]][:container] = clause["id"]
76
+ end
77
+ end
78
+
79
+ def section_names1(clause, num, level)
80
+ @anchors[clause["id"]] =
81
+ { label: num, level: level, xref: num }
82
+ # subclauses are not prefixed with "Clause"
83
+ clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).
84
+ each_with_index do |c, i|
85
+ section_names1(c, "#{num}.#{i + 1}", level + 1)
86
+ end
87
+ end
88
+
89
+ def annex_names1(clause, num, level)
90
+ @anchors[clause["id"]] = { label: num, xref: num, level: level }
91
+ clause.xpath(ns("./clause")).each_with_index do |c, i|
92
+ annex_names1(c, "#{num}.#{i + 1}", level + 1)
93
+ end
94
+ end
95
+
96
+ def eref_localities1_zh(target, type, from, to)
97
+ subsection = from&.text&.match(/\./)
98
+ ret = type == "list" ? "" : ","
99
+ ret += " 第#{from.text}" if from
100
+ ret += "&ndash;#{to}" if to
101
+ loc = (@locality[type] || type.sub(/^locality:/, "").capitalize )
102
+ ret += " #{loc}" unless subsection && type == "clause" || type == "list" || target.match(/^IEV$|^IEC 60050-/)
103
+ ret += ")" if type == "list"
104
+ ret
105
+ end
106
+
107
+ def eref_localities1(target, type, from, to, lang = "en")
108
+ subsection = from&.text&.match(/\./)
109
+ type = type.downcase
110
+ return l10n(eref_localities1_zh(target, type, from, to)) if lang == "zh"
111
+ ret = type == "list" ? "" : ","
112
+ loc = @locality[type] || type.sub(/^locality:/, "").capitalize
113
+ ret += " #{loc}" unless subsection && type == "clause" || type == "list" || target.match(/^IEV$|^IEC 60050-/)
114
+ ret += " #{from.text}" if from
115
+ ret += "&ndash;#{to.text}" if to
116
+ ret += ")" if type == "list"
117
+ l10n(ret)
118
+ end
119
+
120
+ def prefix_container(container, linkend, target)
121
+ delim = anchor(target, :type) == "listitem" ? " " : ", "
122
+ l10n(anchor(container, :xref) + delim + linkend)
123
+ end
124
+
125
+ def example_p_parse(node, div)
126
+ div.p do |p|
127
+ p.span **{ class: "example_label" } do |s|
128
+ s << example_label(node)
129
+ end
130
+ insert_tab(p, 1)
131
+ node.first_element_child.children.each { |n| parse(n, p) }
132
+ end
133
+ node.element_children[1..-1].each { |n| parse(n, div) }
134
+ end
135
+
136
+ def example_parse1(node, div)
137
+ div.p do |p|
138
+ p.span **{ class: "example_label" } do |s|
139
+ s << example_label(node)
140
+ end
141
+ insert_tab(p, 1)
142
+ end
143
+ node.children.each { |n| parse(n, div) }
144
+ end
145
+
146
+ def example_parse(node, out)
147
+ out.div **{ id: node["id"], class: "example" } do |div|
148
+ if node.first_element_child.name == "p"
149
+ example_p_parse(node, div)
150
+ else
151
+ example_parse1(node, div)
152
+ end
153
+ end
154
+ end
155
+
156
+ def termexamples_before_termnotes(node)
157
+ return unless node.at(ns("./termnote")) && node.at(ns("./termexample"))
158
+ return unless insert = node.at(ns("./definition"))
159
+ insert = insertall_after_here(node, insert, "termexample")
160
+ insert = insertall_after_here(node, insert, "termnote")
161
+ end
162
+
163
+ def term_parse(node, out)
164
+ termexamples_before_termnotes(node)
165
+ out.p **{ class: "Terms", style:"text-align:left;" } do |p|
166
+ node.children.each { |c| parse(c, p) }
167
+ end
168
+ end
169
+
170
+ def clausedelim
171
+ ""
172
+ end
173
+
174
+ def load_yaml(lang, script)
175
+ y = if @i18nyaml then YAML.load_file(@i18nyaml)
176
+ elsif lang == "en"
177
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
178
+ elsif lang == "fr"
179
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-fr.yaml"))
180
+ elsif lang == "zh" && script == "Hans"
181
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
182
+ else
183
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
184
+ end
185
+ super.merge(y)
186
+ end
187
+
188
+ end
189
+ end
190
+ end
@@ -1,13 +1,10 @@
1
+ require_relative "base_convert"
1
2
  require "isodoc"
2
3
  require_relative "metadata"
3
4
 
4
5
  module IsoDoc
5
6
  module Iso
6
7
  class HtmlConvert < IsoDoc::HtmlConvert
7
- def metadata_init(lang, script, labels)
8
- @meta = Metadata.new(lang, script, labels)
9
- end
10
-
11
8
  def initialize(options)
12
9
  @libdir = File.dirname(__FILE__)
13
10
  super
@@ -30,150 +27,6 @@ module IsoDoc
30
27
  }
31
28
  end
32
29
 
33
- def implicit_reference(b)
34
- isocode = b.at(ns("./docidentifier")).text
35
- isocode == "IEV"
36
- end
37
-
38
- def introduction(isoxml, out)
39
- f = isoxml.at(ns("//introduction")) || return
40
- num = f.at(ns(".//clause")) ? "0" : nil
41
- title_attr = { class: "IntroTitle" }
42
- page_break(out)
43
- out.div **{ class: "Section3", id: f["id"] } do |div|
44
- # div.h1 "Introduction", **attr_code(title_attr)
45
- clause_name(num, @introduction_lbl, div, title_attr)
46
- f.elements.each do |e|
47
- if e.name == "patent-notice"
48
- e.elements.each { |e1| parse(e1, div) }
49
- else
50
- parse(e, div) unless e.name == "title"
51
- end
52
- end
53
- end
54
- end
55
-
56
- def foreword(isoxml, out)
57
- f = isoxml.at(ns("//foreword")) || return
58
- page_break(out)
59
- out.div **attr_code(id: f["id"]) do |s|
60
- s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl }
61
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
62
- end
63
- end
64
-
65
- def initial_anchor_names(d)
66
- super
67
- introduction_names(d.at(ns("//introduction")))
68
- end
69
-
70
- # we can reference 0-number clauses in introduction
71
- def introduction_names(clause)
72
- return if clause.nil?
73
- clause.xpath(ns("./clause")).each_with_index do |c, i|
74
- section_names1(c, "0.#{i + 1}", 2)
75
- end
76
- end
77
-
78
- # terms not defined in standoc
79
- def error_parse(node, out)
80
- case node.name
81
- when "appendix" then clause_parse(node, out)
82
- else
83
- super
84
- end
85
- end
86
-
87
- def annex_names(clause, num)
88
- appendix_names(clause, num)
89
- super
90
- end
91
-
92
- def appendix_names(clause, num)
93
- clause.xpath(ns("./appendix")).each_with_index do |c, i|
94
- @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl, "clause")
95
- @anchors[c["id"]][:level] = 2
96
- @anchors[c["id"]][:container] = clause["id"]
97
- end
98
- end
99
-
100
- def section_names1(clause, num, level)
101
- @anchors[clause["id"]] =
102
- { label: num, level: level, xref: num }
103
- # subclauses are not prefixed with "Clause"
104
- clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).
105
- each_with_index do |c, i|
106
- section_names1(c, "#{num}.#{i + 1}", level + 1)
107
- end
108
- end
109
-
110
- def annex_names1(clause, num, level)
111
- @anchors[clause["id"]] = { label: num, xref: num, level: level }
112
- clause.xpath(ns("./clause")).each_with_index do |c, i|
113
- annex_names1(c, "#{num}.#{i + 1}", level + 1)
114
- end
115
- end
116
-
117
- def eref_localities1_zh(target, type, from, to)
118
- subsection = from&.text&.match(/\./)
119
- ret = type == "list" ? "" : ","
120
- ret += " 第#{from.text}" if from
121
- ret += "&ndash;#{to}" if to
122
- loc = (@locality[type] || type.sub(/^locality:/, "").capitalize )
123
- ret += " #{loc}" unless subsection && type == "clause" || type == "list" || target.match(/^IEV$|^IEC 60050-/)
124
- ret += ")" if type == "list"
125
- ret
126
- end
127
-
128
- def eref_localities1(target, type, from, to, lang = "en")
129
- subsection = from&.text&.match(/\./)
130
- type = type.downcase
131
- return l10n(eref_localities1_zh(target, type, from, to)) if lang == "zh"
132
- ret = type == "list" ? "" : ","
133
- loc = @locality[type] || type.sub(/^locality:/, "").capitalize
134
- ret += " #{loc}" unless subsection && type == "clause" || type == "list" || target.match(/^IEV$|^IEC 60050-/)
135
- ret += " #{from.text}" if from
136
- ret += "&ndash;#{to.text}" if to
137
- ret += ")" if type == "list"
138
- l10n(ret)
139
- end
140
-
141
- def prefix_container(container, linkend, target)
142
- delim = get_anchors[target][:type] == "listitem" ? " " : ", "
143
- l10n(get_anchors[container][:xref] + delim + linkend)
144
- end
145
-
146
- def example_p_parse(node, div)
147
- div.p do |p|
148
- p.span **{ class: "example_label" } do |s|
149
- s << example_label(node)
150
- end
151
- insert_tab(p, 1)
152
- node.first_element_child.children.each { |n| parse(n, p) }
153
- end
154
- node.element_children[1..-1].each { |n| parse(n, div) }
155
- end
156
-
157
- def example_parse1(node, div)
158
- div.p do |p|
159
- p.span **{ class: "example_label" } do |s|
160
- s << example_label(node)
161
- end
162
- insert_tab(p, 1)
163
- end
164
- node.children.each { |n| parse(n, div) }
165
- end
166
-
167
- def example_parse(node, out)
168
- out.div **{ id: node["id"], class: "example" } do |div|
169
- if node.first_element_child.name == "p"
170
- example_p_parse(node, div)
171
- else
172
- example_parse1(node, div)
173
- end
174
- end
175
- end
176
-
177
30
  def insertall_after_here(node, insert, name)
178
31
  node.children.each do |n|
179
32
  next unless n.name == name
@@ -183,23 +36,7 @@ module IsoDoc
183
36
  insert
184
37
  end
185
38
 
186
- def termexamples_before_termnotes(node)
187
- return unless node.at(ns("./termnote")) && node.at(ns("./termexample"))
188
- return unless insert = node.at(ns("./definition"))
189
- insert = insertall_after_here(node, insert, "termexample")
190
- insert = insertall_after_here(node, insert, "termnote")
191
- end
192
-
193
- def term_parse(node, out)
194
- termexamples_before_termnotes(node)
195
- out.p **{ class: "Terms", style:"text-align:left;" } do |p|
196
- node.children.each { |c| parse(c, p) }
197
- end
198
- end
199
-
200
- def clausedelim
201
- ""
202
- end
39
+ include BaseConvert
203
40
  end
204
41
  end
205
42
  end
@@ -0,0 +1,11 @@
1
+ term_def_boilerplate: |
2
+ <p>ISO and IEC maintain terminological databases for use in
3
+ standardization at the following addresses:</p>
4
+
5
+ <ul>
6
+ <li> <p>ISO Online browsing platform: available at
7
+ <a href=http://www.iso.org/obp>http://www.iso.org/obp</a></p> </li>
8
+ <li> <p>IEC Electropedia: available at
9
+ <a href=http://www.electropedia.org>http://www.electropedia.org</a>
10
+ </p> </li> </ul>
11
+
@@ -0,0 +1,10 @@
1
+ term_def_boilerplate: |
2
+ <p>L'ISO et l'IEC tiennent à jour des bases de données terminologiques
3
+ destinées à être utilisées en normalisation, consultables aux adresses
4
+ suivantes:</p>
5
+ <ul>
6
+ <li> <p>ISO Online browsing platform: disponible à l'adresse
7
+ <a href=http://www.iso.org/obp>http://www.iso.org/obp</a></p> </li>
8
+ <li> <p>IEC Electropedia: disponible à l'adresse
9
+ <a href=http://www.electropedia.org>http://www.electropedia.org</a>
10
+ </p> </li> </ul>
@@ -0,0 +1,8 @@
1
+ term_def_boilerplate: |
2
+ <p>ISO和IEC用于标准化的术语数据库地址如下:</p>
3
+ <ul>
4
+ <li> <p>ISO在线浏览平台:
5
+ 位于<a href=http://www.iso.org/obp>http://www.iso.org/obp</a></p> </li>
6
+ <li> <p>IEC Electropedia:
7
+ 位于<a href=http://www.electropedia.org>http://www.electropedia.org</a>
8
+ </p> </li> </ul>
@@ -5,6 +5,15 @@ module IsoDoc
5
5
  class Metadata < IsoDoc::Metadata
6
6
  def initialize(lang, script, labels)
7
7
  super
8
+ @metadata = {
9
+ tc: "XXXX",
10
+ sc: "XXXX",
11
+ wg: "XXXX",
12
+ editorialgroup: [],
13
+ secretariat: "XXXX",
14
+ obsoletes: nil,
15
+ obsoletes_part: nil
16
+ }
8
17
  end
9
18
 
10
19
  STAGE_ABBRS = {
@@ -19,9 +28,10 @@ module IsoDoc
19
28
  "95": "(Withdrawal)",
20
29
  }.freeze
21
30
 
22
- def stage_abbrev(stage, iter, draft)
31
+ def stage_abbrev(stage, substage, iter, draft)
23
32
  return "" unless stage
24
33
  stage = STAGE_ABBRS[stage.to_sym] || "??"
34
+ stage = "PRF" if stage == "IS" && substage == "00"
25
35
  stage += iter if iter
26
36
  stage = "Pre" + stage if draft =~ /^0\./
27
37
  stage
@@ -34,7 +44,9 @@ module IsoDoc
34
44
  set(:stage, docstatus.text)
35
45
  set(:stage_int, docstatus.text.to_i)
36
46
  set(:unpublished, docstatus.text.to_i > 0 && docstatus.text.to_i < 60)
37
- abbr = stage_abbrev(docstatus.text, isoxml&.at(ns("//bibdata/status/iteration"))&.text,
47
+ abbr = stage_abbrev(docstatus.text,
48
+ isoxml&.at(ns("//bibdata/status/substage"))&.text,
49
+ isoxml&.at(ns("//bibdata/status/iteration"))&.text,
38
50
  isoxml&.at(ns("//version/draft"))&.text)
39
51
  set(:stageabbr, abbr)
40
52
  end
@@ -83,9 +95,9 @@ module IsoDoc
83
95
  end
84
96
 
85
97
  def title(isoxml, _out)
86
- intro = isoxml.at(ns("//bibdata//title-intro[@language='en']"))
87
- main = isoxml.at(ns("//bibdata//title-main[@language='en']"))
88
- part = isoxml.at(ns("//bibdata//title-part[@language='en']"))
98
+ intro = isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='en']"))
99
+ main = isoxml.at(ns("//bibdata//title[@type='title-main' and @language='en']"))
100
+ part = isoxml.at(ns("//bibdata//title[@type='title-part' and @language='en']"))
89
101
  partnumber = isoxml.at(ns("//bibdata//project-number/@part"))
90
102
  subpartnumber = isoxml.at(ns("//bibdata//project-number/@subpart"))
91
103
 
@@ -98,9 +110,9 @@ module IsoDoc
98
110
  end
99
111
 
100
112
  def subtitle(isoxml, _out)
101
- intro = isoxml.at(ns("//bibdata//title-intro[@language='fr']"))
102
- main = isoxml.at(ns("//bibdata//title-main[@language='fr']"))
103
- part = isoxml.at(ns("//bibdata//title-part[@language='fr']"))
113
+ intro = isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='fr']"))
114
+ main = isoxml.at(ns("//bibdata//title[@type='title-main' and @language='fr']"))
115
+ part = isoxml.at(ns("//bibdata//title[@type='title-part' and @language='fr']"))
104
116
  partnumber = isoxml.at(ns("//bibdata//project-number/@part"))
105
117
  subpartnumber = isoxml.at(ns("//bibdata//project-number/@subpart"))
106
118
  set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
@@ -110,6 +122,57 @@ module IsoDoc
110
122
  set(:docsubtitlepartlabel, part_prefix(partnumber, subpartnumber, "fr"))
111
123
  set(:docsubtitlepart, @c.encode(part.text, :hexadecimal)) if part
112
124
  end
125
+
126
+ def author(xml, _out)
127
+ super
128
+ tc(xml)
129
+ sc(xml)
130
+ wg(xml)
131
+ secretariat(xml)
132
+ end
133
+
134
+ def tc(xml)
135
+ tc_num = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@number"))
136
+ tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@type"))&.
137
+ text || "TC"
138
+ if tc_num
139
+ tcid = "#{tc_type} #{tc_num.text}"
140
+ set(:tc, tcid)
141
+ set(:editorialgroup, get[:editorialgroup] << tcid)
142
+ end
143
+ end
144
+
145
+ def sc(xml)
146
+ sc_num = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@number"))
147
+ sc_type = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@type"))&.text || "SC"
148
+ if sc_num
149
+ scid = "#{sc_type} #{sc_num.text}"
150
+ set(:sc, scid)
151
+ set(:editorialgroup, get[:editorialgroup] << scid)
152
+ end
153
+ end
154
+
155
+ def wg(xml)
156
+ wg_num = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@number"))
157
+ wg_type = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@type"))&.text || "WG"
158
+ if wg_num
159
+ wgid = "#{wg_type} #{wg_num.text}"
160
+ set(:wg, wgid)
161
+ set(:editorialgroup, get[:editorialgroup] << wgid)
162
+ end
163
+ end
164
+
165
+ def secretariat(xml)
166
+ sec = xml.at(ns("//bibdata/ext/editorialgroup/secretariat"))
167
+ set(:secretariat, sec.text) if sec
168
+ end
169
+
170
+ def doctype(isoxml, _out)
171
+ super
172
+ ics = []
173
+ isoxml.xpath(ns("//bibdata/ext/ics/code")).each { |i| ics << i.text }
174
+ set(:ics, ics.empty? ? "XXX" : ics.join(", "))
175
+ end
113
176
  end
114
177
  end
115
178
  end