metanorma-gb 1.4.3 → 1.5.0

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: 61424361f137760e81ac2be44d0612606ff8d5e7073e6d7f06d3036d15030798
4
- data.tar.gz: 5b16f50829090ae682162ed84713fc21290dd864440fe54cc07e9c55e42e7738
3
+ metadata.gz: fe9a20b1e4d09c3ed8151c2021f51c1b8e412f823f0363db5bf0b9e4eb182908
4
+ data.tar.gz: 6601454ed383cbb484434deebc8195d280a50f36282e0d84a096c1406751e322
5
5
  SHA512:
6
- metadata.gz: d0ce63e59a9f544d136615b857e326d0a3ac2985f66eef19eb194e727033c205dc1f4c7e7cfb7a076576666088c537c5ca164bf560a4ba0b1c6e638e4bbc594b
7
- data.tar.gz: d6e5ab147c8b47a65fd7c47a6f1a107837e001bd2801e9a81b50ab40865c189ad9d768000f65e881612feda144eb72090acb81f09800632699ac9fdab9db2bcf
6
+ metadata.gz: fd3154c799e5794a5b9a7a13b8cfe3eb2d70a0a1b1bb36ea6e1d85a9b14d8a5658726320734105f5abfcf1f0c8990ce2e9ce681cbc8d600d0702430f8416f048
7
+ data.tar.gz: 8f90f5d26fe2601454ad8f6a27d6103d494443ce9948a25d2b2d697b9eb562018802cb08e529855916f2d8e7b4c0296e1e7001af8201374eda350ee4bf2fece0
@@ -0,0 +1,130 @@
1
+ module Asciidoctor
2
+ module Gb
3
+ class Converter < ISO::Converter
4
+ def termdef_cleanup(xmldoc)
5
+ super
6
+ # TODO this should become variant tag
7
+ localisedstr(xmldoc)
8
+ end
9
+
10
+ ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
11
+ HAN_TEXT = /\s*[\u4e00-\u9fff]+/
12
+
13
+ LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
14
+ "//initial | //addition | //surname | //forename | //name | "\
15
+ "//abbreviation | //role/description | //affiliation/description | "\
16
+ "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
17
+ "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
18
+ "//bibdata/abstract | //bibitem/note ".freeze
19
+
20
+ MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
21
+
22
+ def localisedstr(xmldoc)
23
+ xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
24
+ if zh.at("./string")
25
+ extract_localisedstrings(zh)
26
+ elsif MUST_LOCALISE_ELEMS.include? zh.name
27
+ duplicate_localisedstrings(zh)
28
+ end
29
+ end
30
+ end
31
+
32
+ # element consists solely of localised strings, with no attributes
33
+ def extract_localisedstrings(elem)
34
+ elem.xpath("./string").each do |s|
35
+ s.name = elem.name
36
+ end
37
+ elem.replace(elem.children)
38
+ end
39
+
40
+ def text_clean(text)
41
+ text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
42
+ end
43
+
44
+ def duplicate_localisedstrings(zh)
45
+ en = zh.dup.remove
46
+ zh.after(en).after(" ")
47
+ zh["language"] = "zh"
48
+ en["language"] = "en"
49
+ en.traverse do |c|
50
+ c.text? && c.content = text_clean(c.text.gsub(HAN_TEXT, ""))
51
+ end
52
+ zh.traverse do |c|
53
+ c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
54
+ end
55
+ end
56
+
57
+ def termdef_boilerplate_cleanup(xmldoc)
58
+ return if @keepboilerplate
59
+ super
60
+ end
61
+
62
+ def cleanup(xmldoc)
63
+ lang = xmldoc.at("//language")&.text
64
+ @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
65
+ super
66
+ contributor_cleanup(xmldoc)
67
+ xmldoc
68
+ end
69
+
70
+ def docidentifier_cleanup(xmldoc)
71
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return
72
+ scope = xmldoc.at("//gbscope")&.text
73
+ prefix = xmldoc.at("//gbprefix")&.text
74
+ mand = xmldoc.at("//gbmandate")&.text || "mandatory"
75
+ idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
76
+ id.content = idtext&.gsub(/\&#x2002;/, " ")
77
+ id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
78
+ "project-number") or return
79
+ idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
80
+ id.content = idtext&.gsub(/\&#x2002;/, " ")
81
+ end
82
+
83
+ def committee_cleanup(xmldoc)
84
+ xmldoc.xpath("//gbcommittee").each do |c|
85
+ xmldoc.at("//bibdata/contributor").next =
86
+ "<contributor><role type='technical-committee'/><organization>"\
87
+ "<name>#{c.text}</name></organization></contributor>"
88
+ end
89
+ end
90
+
91
+ def agency_value(issuer, scope, prefix, mandate)
92
+ agency = issuer.content
93
+ agency == "GB" and
94
+ agency = @agencyclass.standard_agency1(scope, prefix, mandate)
95
+ agency = "GB" if agency.nil? || agency.empty?
96
+ agency
97
+ end
98
+
99
+ def contributor_cleanup(xmldoc)
100
+ issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
101
+ "organization/name")
102
+ scope = xmldoc.at("//gbscope")&.text
103
+ prefix = xmldoc.at("//gbprefix")&.text
104
+ mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
105
+ agency = agency_value(issuer, scope, prefix, mandate)
106
+ owner = xmldoc.at("//copyright/owner/organization/name")
107
+ owner.content = agency
108
+ issuer.content = agency
109
+ committee_cleanup(xmldoc)
110
+ end
111
+
112
+ def omit_docid_prefix(prefix)
113
+ IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
114
+ end
115
+
116
+ def boilerplate_cleanup(xmldoc)
117
+ isodoc = boilerplate_isodoc(xmldoc)
118
+ initial_boilerplate(xmldoc, isodoc)
119
+ return if @keepboilerplate
120
+ xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
121
+ term_defs_boilerplate(f.at("./title"),
122
+ xmldoc.xpath(".//termdocsource"),
123
+ f.at(".//term"), f.at(".//p"), isodoc)
124
+ end
125
+ f = xmldoc.at(self.class::NORM_REF) and
126
+ norm_ref_preface(f)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,6 +1,5 @@
1
1
  require "asciidoctor"
2
2
  require "asciidoctor/iso/converter"
3
- require "metanorma/gb/version"
4
3
  require "isodoc/gb/common"
5
4
  require "isodoc/gb/word_convert"
6
5
  require "isodoc/gb/pdf_convert"
@@ -9,6 +8,7 @@ require "gb_agencies"
9
8
  require_relative "./section_input.rb"
10
9
  require_relative "./front.rb"
11
10
  require_relative "./validate.rb"
11
+ require_relative "cleanup.rb"
12
12
  require "fileutils"
13
13
 
14
14
  module Asciidoctor
@@ -74,62 +74,15 @@ module Asciidoctor
74
74
  def outputs(node, ret)
75
75
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
76
76
  presentation_xml_converter(node).convert(@filename + ".xml")
77
- html_compliant_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}_compliant.html")
78
- html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
79
- doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
80
- pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf")
81
- end
82
-
83
- def termdef_cleanup(xmldoc)
84
- super
85
- localisedstr(xmldoc)
86
- end
87
-
88
- ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
89
- HAN_TEXT = /\s*[\u4e00-\u9fff]+/
90
-
91
- LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
92
- "//initial | //addition | //surname | //forename | //name | "\
93
- "//abbreviation | //role/description | //affiliation/description | "\
94
- "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
95
- "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
96
- "//bibdata/abstract | //bibitem/note ".freeze
97
-
98
- MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
99
-
100
- def localisedstr(xmldoc)
101
- xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
102
- if zh.at("./string")
103
- extract_localisedstrings(zh)
104
- elsif MUST_LOCALISE_ELEMS.include? zh.name
105
- duplicate_localisedstrings(zh)
106
- end
107
- end
108
- end
109
-
110
- # element consists solely of localised strings, with no attributes
111
- def extract_localisedstrings(elem)
112
- elem.xpath("./string").each do |s|
113
- s.name = elem.name
114
- end
115
- elem.replace(elem.children)
116
- end
117
-
118
- def text_clean(text)
119
- text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
120
- end
121
-
122
- def duplicate_localisedstrings(zh)
123
- en = zh.dup.remove
124
- zh.after(en).after(" ")
125
- zh["language"] = "zh"
126
- en["language"] = "en"
127
- en.traverse do |c|
128
- c.text? && c.content = text_clean(c.text.gsub(HAN_TEXT, ""))
129
- end
130
- zh.traverse do |c|
131
- c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
132
- end
77
+ html_compliant_converter(node).
78
+ convert(@filename + ".presentation.xml",
79
+ nil, false, "#{@filename}_compliant.html")
80
+ html_converter(node).convert(@filename + ".presentation.xml",
81
+ nil, false, "#{@filename}.html")
82
+ doc_converter(node).convert(@filename + ".presentation.xml",
83
+ nil, false, "#{@filename}.doc")
84
+ pdf_converter(node)&.convert(@filename + ".presentation.xml",
85
+ nil, false, "#{@filename}.pdf")
133
86
  end
134
87
 
135
88
  def inline_quoted(node)
@@ -149,11 +102,6 @@ module Asciidoctor
149
102
  super
150
103
  end
151
104
 
152
- def termdef_boilerplate_cleanup(xmldoc)
153
- return if @keepboilerplate
154
- super
155
- end
156
-
157
105
  GBCODE = "((AQ|BB|CB|CH|CJ|CY|DA|DB|DL|DZ|EJ|FZ|GA|GH|GM|GY|HB|HG|"\
158
106
  "HJ|HS|HY|JB|JC|JG|JR|JT|JY|LB|LD|LS|LY|MH|MT|MZ|NY|QB|QC|QJ|"\
159
107
  "QZ|SB|SC|SH|SJ|SN|SY|TB|TD|TJ|TY|WB|WH|WJ|WM|WS|WW|XB|YB|YC|"\
@@ -186,71 +134,12 @@ module Asciidoctor
186
134
  super
187
135
  end
188
136
 
189
- def cleanup(xmldoc)
190
- lang = xmldoc.at("//language")&.text
191
- @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
137
+ def init(node)
138
+ node.attr("language") or node.set_attr("language", "zh")
139
+ node.attr("script") or
140
+ node.set_attr("script", node.attr("language") == "zh" ?
141
+ "Hans" : "Latn")
192
142
  super
193
- contributor_cleanup(xmldoc)
194
- xmldoc
195
- end
196
-
197
- def docidentifier_cleanup(xmldoc)
198
- id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return
199
- scope = xmldoc.at("//gbscope")&.text
200
- prefix = xmldoc.at("//gbprefix")&.text
201
- mand = xmldoc.at("//gbmandate")&.text || "mandatory"
202
- idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
203
- id.content = idtext&.gsub(/\&#x2002;/, " ")
204
- id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
205
- "project-number") or return
206
- idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
207
- id.content = idtext&.gsub(/\&#x2002;/, " ")
208
- end
209
-
210
- def committee_cleanup(xmldoc)
211
- xmldoc.xpath("//gbcommittee").each do |c|
212
- xmldoc.at("//bibdata/contributor").next =
213
- "<contributor><role type='technical-committee'/><organization>"\
214
- "<name>#{c.text}</name></organization></contributor>"
215
- end
216
- end
217
-
218
- def agency_value(issuer, scope, prefix, mandate)
219
- agency = issuer.content
220
- agency == "GB" and
221
- agency = @agencyclass.standard_agency1(scope, prefix, mandate)
222
- agency = "GB" if agency.nil? || agency.empty?
223
- agency
224
- end
225
-
226
- def contributor_cleanup(xmldoc)
227
- issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
228
- "organization/name")
229
- scope = xmldoc.at("//gbscope")&.text
230
- prefix = xmldoc.at("//gbprefix")&.text
231
- mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
232
- agency = agency_value(issuer, scope, prefix, mandate)
233
- owner = xmldoc.at("//copyright/owner/organization/name")
234
- owner.content = agency
235
- issuer.content = agency
236
- committee_cleanup(xmldoc)
237
- end
238
-
239
- def omit_docid_prefix(prefix)
240
- IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
241
- end
242
-
243
- def boilerplate_cleanup(xmldoc)
244
- isodoc = boilerplate_isodoc(xmldoc)
245
- initial_boilerplate(xmldoc, isodoc)
246
- return if @keepboilerplate
247
- xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
248
- term_defs_boilerplate(f.at("./title"),
249
- xmldoc.xpath(".//termdocsource"),
250
- f.at(".//term"), f.at(".//p"), isodoc)
251
- end
252
- f = xmldoc.at(self.class::NORM_REF) and
253
- norm_ref_preface(f)
254
143
  end
255
144
  end
256
145
  end
@@ -1,7 +1,7 @@
1
1
  module Asciidoctor
2
2
  module Gb
3
3
  class Converter < ISO::Converter
4
- STAGE_ABBRS_CN = {
4
+ STAGE_ABBRS_CN = {
5
5
  "00": "新工作项目建议",
6
6
  "10": "新工作项目",
7
7
  "20": "标准草案工作组讨论稿",
@@ -43,7 +43,7 @@ module Asciidoctor
43
43
 
44
44
  def id_stage_prefix(dn, node)
45
45
  if node.attr("docstage") && node.attr("docstage").to_i < 60
46
- abbr = IsoDoc::Gb::Metadata.new("en", "Latn", {}).
46
+ abbr = IsoDoc::Gb::Metadata.new("en", "Latn", @i18n).
47
47
  status_abbrev(node.attr("docstage"), nil, node.attr("iteration"),
48
48
  node.attr("draft"), node.attr("doctype"))
49
49
  dn = "/#{abbr} #{dn}" # prefixes added in cleanup
@@ -922,6 +922,9 @@
922
922
  <optional>
923
923
  <attribute name="script"/>
924
924
  </optional>
925
+ <optional>
926
+ <attribute name="type"/>
927
+ </optional>
925
928
  <optional>
926
929
  <attribute name="obligation">
927
930
  <choice>
@@ -961,9 +964,6 @@
961
964
  </define>
962
965
  <define name="content-subsection">
963
966
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
967
  <ref name="Content-Section"/>
968
968
  </element>
969
969
  </define>
@@ -992,6 +992,9 @@
992
992
  </choice>
993
993
  </attribute>
994
994
  </optional>
995
+ <optional>
996
+ <attribute name="type"/>
997
+ </optional>
995
998
  <optional>
996
999
  <ref name="section-title"/>
997
1000
  </optional>
@@ -1011,9 +1014,6 @@
1011
1014
  </define>
1012
1015
  <define name="clause">
1013
1016
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1017
  <ref name="Clause-Section"/>
1018
1018
  </element>
1019
1019
  </define>
@@ -1042,6 +1042,9 @@
1042
1042
  </choice>
1043
1043
  </attribute>
1044
1044
  </optional>
1045
+ <optional>
1046
+ <attribute name="type"/>
1047
+ </optional>
1045
1048
  <optional>
1046
1049
  <ref name="section-title"/>
1047
1050
  </optional>
@@ -1180,6 +1183,9 @@
1180
1183
  <optional>
1181
1184
  <attribute name="script"/>
1182
1185
  </optional>
1186
+ <optional>
1187
+ <attribute name="type"/>
1188
+ </optional>
1183
1189
  <optional>
1184
1190
  <attribute name="obligation">
1185
1191
  <choice>
@@ -8,6 +8,8 @@ module Asciidoctor
8
8
  class Converter < ISO::Converter
9
9
  def sectiontype_streamline(ret)
10
10
  case ret
11
+ when "前言" then "foreword"
12
+ when "致謝" then "acknowledgements"
11
13
  when "引言" then "introduction"
12
14
  when "范围" then "scope"
13
15
  when "规范性引用文件" then "normative references"
@@ -21,6 +23,15 @@ module Asciidoctor
21
23
  end
22
24
  end
23
25
 
26
+ def symbols_attrs(node, a)
27
+ case sectiontype1(node)
28
+ when "符号" then a.merge(type: "symbols")
29
+ when "代号和缩略语" then a.merge(type: "abbreviated_terms")
30
+ else
31
+ super
32
+ end
33
+ end
34
+
24
35
  def appendix_parse(attrs, xml, node)
25
36
  # UNSAFE, there is no unset_option() in asciidoctor
26
37
  node.remove_attr("appendix-option")
@@ -1,7 +1,6 @@
1
1
  module Asciidoctor
2
2
  module Gb
3
3
  class Converter < ISO::Converter
4
-
5
4
  def validate(doc)
6
5
  content_validate(doc)
7
6
  schema_validate(formattedstr_strip(doc.dup),
@@ -1,7 +1,6 @@
1
1
  require_relative "common"
2
2
  require "gb_agencies"
3
3
  require_relative "cleanup"
4
- require_relative "metadata"
5
4
  require "fileutils"
6
5
 
7
6
  module IsoDoc
@@ -16,18 +15,9 @@ module IsoDoc
16
15
  "$titlefont: #{t};\n"
17
16
  end
18
17
 
19
- def metadata_init(lang, script, labels)
20
- unless ["en", "zh"].include? lang
21
- lang = "zh"
22
- script = "Hans"
23
- end
24
- @meta = Metadata.new(lang, script, labels)
25
- @meta.set(:standardclassimg, @standardclassimg)
26
- @common.meta = @meta
27
- end
28
-
29
18
  def cleanup(docxml)
30
- @cleanup = Cleanup.new(@script, @deprecated_lbl)
19
+ @i18n ||= i18n_init(@lang, @script)
20
+ @cleanup = Cleanup.new(@script, @i18n.deprecated)
31
21
  super
32
22
  @cleanup.cleanup(docxml)
33
23
  docxml
@@ -38,43 +28,26 @@ module IsoDoc
38
28
  @cleanup.example_cleanup(docxml)
39
29
  end
40
30
 
41
- def i18n_init(lang, script)
42
- super
43
- y = if lang == "en"
44
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
45
- elsif lang == "zh" && script == "Hans"
46
- YAML.load_file(File.join(File.dirname(__FILE__),
47
- "i18n-zh-Hans.yaml"))
48
- else
49
- YAML.load_file(File.join(File.dirname(__FILE__),
50
- "i18n-zh-Hans.yaml"))
51
- end
52
- @labels = @labels.merge(y)
53
- end
54
-
55
31
  def omit_docid_prefix(prefix)
56
32
  super || prefix == "Chinese Standard"
57
33
  end
58
34
 
59
- def formula_parse(node, out)
60
- out.div **formula_attrs(node) do |div1|
61
- div1.div **attr_code(class: "formula") do |div|
35
+ def formula_parse1(node, out)
36
+ out.div **attr_code(class: "formula") do |div|
62
37
  insert_tab(div, 1)
63
38
  parse(node.at(ns("./stem")), div)
64
- lbl = @xrefs.anchor(node['id'], :label, false)
39
+ lbl = node&.at(ns("./name"))&.text
65
40
  unless lbl.nil?
66
41
  insert_tab(div, 1)
67
42
  div << "(#{lbl})"
68
43
  end
69
44
  end
70
- formula_where(node.at(ns("./dl")), div1)
71
- end
72
45
  end
73
46
 
74
47
  def formula_where(dl, out)
75
48
  return unless dl
76
49
  out.p **{ style: "page-break-after:avoid;"} do |p|
77
- p << @where_lbl
50
+ p << @i18n.where
78
51
  end
79
52
  formula_dl_parse(dl, out)
80
53
  end
@@ -99,32 +72,37 @@ module IsoDoc
99
72
  { class: "example_label",
100
73
  style: "padding:2pt 2pt 2pt 2pt;vertical-align:top;" }.freeze
101
74
 
102
- def example_label(node)
103
- l10n(super + ":")
75
+ def note_delim
76
+ l10n(": ")
104
77
  end
105
78
 
106
79
  def note_parse(node, out)
107
- note_parse_table(node, out, note_label(node) + ":")
80
+ note_parse_table(node, out)
108
81
  end
109
82
 
110
- def note_parse_table(node, out, label)
83
+ def note_parse_table(node, out)
111
84
  @note = true
85
+ name = node&.at(ns("./name"))&.remove
86
+ note_parse_table1(node, out, name)
87
+ @note = false
88
+ end
89
+
90
+ def note_parse_table1(node, out, name)
112
91
  out.table **note_attrs(node) do |t|
113
92
  t.tr do |tr|
114
- @libdir = File.dirname(__FILE__)
115
93
  tr.td **EXAMPLE_TBL_ATTR do |td|
116
- td << l10n(label)
94
+ name and name.children.each { |n| parse(n, td) }
95
+ td << note_delim
117
96
  end
118
97
  tr.td **{ style: "vertical-align:top;", class: "Note" } do |td|
119
98
  node.children.each { |n| parse(n, td) }
120
99
  end
121
100
  end
122
101
  end
123
- @note = false
124
102
  end
125
103
 
126
104
  def termnote_parse(node, out)
127
- note_parse_table(node, out, "#{@xrefs.anchor(node['id'], :label)}:")
105
+ note_parse_table(node, out)
128
106
  end
129
107
 
130
108
  def middle(isoxml, out)
@@ -157,19 +135,19 @@ module IsoDoc
157
135
 
158
136
  def deprecated_term_parse(node, out)
159
137
  out.p **{ class: "DeprecatedTerms" } do |p|
160
- p << l10n("#{@deprecated_lbl}: ")
138
+ p << l10n("#{@i18n.deprecated}: ")
161
139
  node.children.each { |c| parse(c, p) }
162
140
  end
163
141
  end
164
142
 
165
143
  def termref_render(x)
166
- x.sub!(%r{\s*\[MODIFICATION\]\s*$}m, l10n(", #{@modified_lbl}"))
144
+ x.sub!(%r{\s*\[MODIFICATION\]\s*$}m, l10n(", #{@i18n.modified}"))
167
145
  parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m)
168
- parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 &&
169
- parts[1] == "," && !/^\s*#{@modified_lbl}/.match(parts[2])
146
+ parts[1] = l10n(", #{@i18n.source}") if parts.size > 1 &&
147
+ parts[1] == "," && !/^\s*#{@i18n.modified}/.match(parts[2])
170
148
  parts.map do |p|
171
149
  /\s*\[MODIFICATION\]/.match(p) ?
172
- l10n(", #{@modified_lbl} &mdash; ") : p
150
+ l10n(", #{@i18n.modified} &mdash; ") : p
173
151
  end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]"))
174
152
  end
175
153
 
@@ -181,42 +159,12 @@ module IsoDoc
181
159
  end.join
182
160
  end
183
161
 
184
- def foreword(isoxml, out)
185
- f = isoxml.at(ns("//foreword")) || return
186
- page_break(out)
187
- out.div do |s|
188
- s.h1 **{ class: "ForewordTitle" } do |h1|
189
- h1 << "#{@foreword_lbl}&nbsp;"
190
- # insert_tab(h1, 1)
191
- end
192
- f.elements.each { |e| parse(e, s) unless e.name == "title" }
193
- end
194
- end
195
-
196
162
  def clausedelimspace(out)
197
163
  out << "&#x3000;"
198
164
  end
199
165
 
200
- def clause_name(num, title, div, header_class)
201
- header_class = {} if header_class.nil?
202
- div.h1 **attr_code(header_class) do |h1|
203
- if num && !@suppressheadingnumbers
204
- h1 << "#{num}."
205
- h1 << "&#x3000;"
206
- end
207
- title.is_a?(String) ? h1 << title :
208
- title&.children&.each { |c2| parse(c2, h1) }
209
- end
210
- div.parent.at(".//h1")
211
- end
212
-
213
166
  def example_span_label(node, div, name)
214
- n = @xrefs.get[node["id"]]
215
167
  div.span **{ class: "example_label" } do |p|
216
- lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl :
217
- l10n("#{@example_lbl} #{n[:label]}")
218
- p << l10n(lbl + ":")
219
- name and !lbl.nil? and p << "&nbsp;&mdash; "
220
168
  name and name.children.each { |n| parse(n, div) }
221
169
  end
222
170
  end
@@ -74,17 +74,6 @@ module IsoDoc
74
74
  term_merge(docxml, "DeprecatedTerms")
75
75
  docxml
76
76
  end
77
-
78
- =begin
79
- def intro_cleanup(docxml)
80
- # insert tab for purposes of ToC lining up
81
- docxml.xpath("//h1[@class = 'IntroTitle']").each do |h1|
82
- if h1.content == "引言"
83
- h1.add_child('<span style="mso-tab-count:1">&#xA0; </span>')
84
- end
85
- end
86
- end
87
- =end
88
77
  end
89
78
  end
90
79
  end
@@ -1,3 +1,4 @@
1
+ require_relative "init"
1
2
  require_relative "base_convert"
2
3
  require "isodoc"
3
4
 
@@ -47,31 +48,23 @@ module IsoDoc
47
48
  end
48
49
 
49
50
  def populate_template(docxml, format)
50
- meta = @meta.get.merge(@labels).merge(@meta.fonts_options || {})
51
+ meta = @meta.get.merge(@i18n.get).merge(@meta.fonts_options || {})
51
52
  logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format, @localdir)
52
53
  logofile = @meta.standard_logo(meta[:gbprefix])
53
54
  meta[:standard_agency_formatted] =
54
55
  @common.format_agency(meta[:standard_agency], format, @localdir)
55
56
  meta[:standard_logo] = logo
56
-
57
57
  template = Liquid::Template.parse(docxml)
58
58
  template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
59
-
60
- #template = liquid(docxml)
61
- #template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h).
62
- #gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;')
63
59
  end
64
60
 
65
- def annex_name(annex, name, div)
66
- div.h1 **{ class: "Annex" } do |t|
67
- t << "#{@xrefs.anchor(annex['id'], :label)}<br/><br/>"
68
- t.b do |b|
69
- name&.children&.each { |c2| parse(c2, b) }
70
- end
71
- end
61
+ def insert_tab(out, n)
62
+ tab = "&#x3000;"
63
+ [1..n].each { out << tab }
72
64
  end
73
65
 
74
66
  include BaseConvert
67
+ include Init
75
68
  end
76
69
  end
77
70
  end
@@ -0,0 +1,16 @@
1
+ module IsoDoc
2
+ module Gb
3
+ class I18n < IsoDoc::Iso::I18n
4
+ def load_yaml1(lang, script)
5
+ y = if lang == "en"
6
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
7
+ elsif lang == "zh" && script == "Hans"
8
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
9
+ else
10
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
11
+ end
12
+ super.merge(y)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require_relative "xref"
4
+ require_relative "i18n"
5
+
6
+ module IsoDoc
7
+ module Gb
8
+ module Init
9
+ def metadata_init(lang, script, labels)
10
+ unless ["en", "zh"].include? lang
11
+ lang = "zh"
12
+ script = "Hans"
13
+ end
14
+ @meta = Metadata.new(lang, script, labels)
15
+ @meta.set(:standardclassimg, @standardclassimg)
16
+ @common&.meta = @meta
17
+ end
18
+
19
+ def xref_init(lang, script, klass, labels, options)
20
+ @xrefs = Xref.new(lang, script, HtmlConvert.new(language: lang, script: script), labels, options)
21
+ end
22
+
23
+ def i18n_init(lang, script, i18nyaml = nil)
24
+ @i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -8,7 +8,7 @@ module IsoDoc
8
8
  # A {Converter} implementation that generates GB output, and a document
9
9
  # schema encapsulation of the document for validation
10
10
  class Metadata < IsoDoc::Iso::Metadata
11
- def initialize(lang, script, labels)
11
+ def initialize(lang, script, i18n)
12
12
  super
13
13
  set(:docmaintitlezh, "")
14
14
  set(:docsubtitlezh, "XXXX")
@@ -1,9 +1,25 @@
1
- require_relative "base_convert"
1
+ require_relative "init"
2
2
  require "isodoc"
3
3
 
4
4
  module IsoDoc
5
5
  module Gb
6
6
  class PresentationXMLConvert < IsoDoc::Iso::PresentationXMLConvert
7
+ def example1(f)
8
+ n = @xrefs.get[f["id"]]
9
+ lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example :
10
+ l10n("#{@i18n.example} #{n[:label]}")
11
+ prefix_name(f, "&nbsp;&mdash; ", l10n(lbl + ":"), "name")
12
+ end
13
+
14
+ def annex1(f)
15
+ lbl = @xrefs.anchor(f['id'], :label)
16
+ if t = f.at(ns("./title"))
17
+ t.children = "#{t.children.to_xml}"
18
+ end
19
+ prefix_name(f, "<br/><br/>", lbl, "title")
20
+ end
21
+
22
+ include Init
7
23
  end
8
24
  end
9
25
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "base_convert"
2
+ require_relative "init"
2
3
  require "isodoc"
3
4
 
4
5
  module IsoDoc
@@ -71,17 +72,17 @@ module IsoDoc
71
72
  out.table **attr_code(id: node["id"], class: "example") do |t|
72
73
  t.tr do |tr|
73
74
  tr.td **EXAMPLE_TBL_ATTR do |td|
74
- td << l10n(example_label(node) + ":")
75
+ node.at(ns("./name")).children.each { |n| parse(n, td) }
75
76
  end
76
77
  tr.td **{ valign: "top", class: "example" } do |td|
77
- node.children.each { |n| parse(n, td) }
78
+ node.children.each { |n| parse(n, td) unless n.name == "name" }
78
79
  end
79
80
  end
80
81
  end
81
82
  end
82
83
 
83
84
  def populate_template(docxml, format)
84
- meta = @meta.get.merge(@labels).merge(@meta.fonts_options || {})
85
+ meta = @meta.get.merge(@i18n.get).merge(@meta.fonts_options || {})
85
86
  logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format, @localdir)
86
87
  logofile = @meta.standard_logo(meta[:gbprefix])
87
88
  meta[:standard_agency_formatted] =
@@ -92,13 +93,6 @@ module IsoDoc
92
93
  gsub('&lt;', '&#x3c;').gsub('&gt;', '&#x3e;').gsub('&amp;', '&#x26;')
93
94
  end
94
95
 
95
- def annex_name(annex, name, div)
96
- div.h1 **{ class: "Annex" } do |t|
97
- t << "#{@xrefs.anchor(annex['id'], :label)}<br/><br/>"
98
- name&.children&.each { |c2| parse(c2, t) }
99
- end
100
- end
101
-
102
96
  def make_body(xml, docxml)
103
97
  body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
104
98
  xml.body **body_attr do |body|
@@ -126,6 +120,7 @@ module IsoDoc
126
120
  end
127
121
 
128
122
  include BaseConvert
123
+ include Init
129
124
  end
130
125
  end
131
126
  end
@@ -0,0 +1,6 @@
1
+ module IsoDoc
2
+ module Gb
3
+ class Xref < IsoDoc::Xref
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Gb
3
- VERSION = "1.4.3"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
31
31
 
32
- spec.add_dependency "metanorma-iso", "~> 1.4.0"
33
- spec.add_dependency "isodoc", "~> 1.1.0"
32
+ spec.add_dependency "metanorma-iso", "~> 1.5.0"
33
+ spec.add_dependency "isodoc", "~> 1.2.0"
34
34
  spec.add_dependency "twitter_cldr", "~> 4.4.4"
35
35
  spec.add_dependency "gb-agencies", "~> 0.0.4"
36
36
  spec.add_dependency "htmlentities", "~> 4.3.4"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-gb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
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-07-26 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-iso
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.0
19
+ version: 1.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.0
26
+ version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: isodoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.0
33
+ version: 1.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.0
40
+ version: 1.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: twitter_cldr
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +267,7 @@ files:
267
267
  - lib/asciidoctor/gb/basicdoc.rng
268
268
  - lib/asciidoctor/gb/biblio.rng
269
269
  - lib/asciidoctor/gb/boilerplate.xml
270
+ - lib/asciidoctor/gb/cleanup.rb
270
271
  - lib/asciidoctor/gb/converter.rb
271
272
  - lib/asciidoctor/gb/front.rb
272
273
  - lib/asciidoctor/gb/front_id.rb
@@ -324,10 +325,13 @@ files:
324
325
  - lib/isodoc/gb/html_convert.rb
325
326
  - lib/isodoc/gb/i18n-en.yaml
326
327
  - lib/isodoc/gb/i18n-zh-Hans.yaml
328
+ - lib/isodoc/gb/i18n.rb
329
+ - lib/isodoc/gb/init.rb
327
330
  - lib/isodoc/gb/metadata.rb
328
331
  - lib/isodoc/gb/pdf_convert.rb
329
332
  - lib/isodoc/gb/presentation_xml_convert.rb
330
333
  - lib/isodoc/gb/word_convert.rb
334
+ - lib/isodoc/gb/xref.rb
331
335
  - lib/metanorma-gb.rb
332
336
  - lib/metanorma/gb.rb
333
337
  - lib/metanorma/gb/processor.rb