metanorma-gb 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,6 +25,11 @@
25
25
  <ref name="ObligationType"/>
26
26
  </attribute>
27
27
  </optional>
28
+ <optional>
29
+ <attribute name="unnumbered">
30
+ <data type="boolean"/>
31
+ </attribute>
32
+ </optional>
28
33
  <attribute name="id">
29
34
  <data type="ID"/>
30
35
  </attribute>
@@ -1,4 +1,4 @@
1
- require "gbbib"
1
+ require "relaton_gb"
2
2
 
3
3
  module Asciidoctor
4
4
  module Gb
@@ -13,9 +13,27 @@ module Asciidoctor
13
13
  bilingual_terms_validate(doc.root)
14
14
  issuer_validate(doc.root)
15
15
  prefix_validate(doc.root)
16
+ bibdata_validate(doc.root)
16
17
  @agencyclass.gbtype_validate(doc.root.at("//gbscope")&.text, doc.root.at("//gbprefix")&.text)
17
18
  end
18
19
 
20
+ def bibdata_validate(doc)
21
+ doctype_validate(doc)
22
+ script_validate(doc)
23
+ end
24
+
25
+ def doctype_validate(xmldoc)
26
+ doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
27
+ %w(standard recommendation).include? doctype or
28
+ warn "Document Attributes: #{doctype} is not a recognised document type"
29
+ end
30
+
31
+ def script_validate(xmldoc)
32
+ script = xmldoc&.at("//bibdata/script")&.text
33
+ %(Hans Latn).include?(script) or
34
+ warn "Document Attributes: #{script} is not a recognised script"
35
+ end
36
+
19
37
  def prefix_validate(root)
20
38
  prefix = root&.at("//gbprefix")&.text
21
39
  scope = root&.at("//gbscope")&.text
@@ -69,8 +87,8 @@ module Asciidoctor
69
87
  end
70
88
 
71
89
  def title_intro_validate(root)
72
- title_intro_en = root.at("//title-intro[@language='en']")
73
- title_intro_zh = root.at("//title-intro[@language='zh']")
90
+ title_intro_en = root.at("//title[@type='title-intro' and @language='en']")
91
+ title_intro_zh = root.at("//title[@type='title-intro' and @language='zh']")
74
92
  if title_intro_en.nil? && !title_intro_zh.nil?
75
93
  warn "No English Title Intro!"
76
94
  end
@@ -80,8 +98,8 @@ module Asciidoctor
80
98
  end
81
99
 
82
100
  def title_main_validate(root)
83
- title_main_en = root.at("//title-main[@language='en']")
84
- title_main_zh = root.at("//title-main[@language='zh']")
101
+ title_main_en = root.at("//title[@type='title-main' and @language='en']")
102
+ title_main_zh = root.at("//title[@type='title-main' and @language='zh']")
85
103
  if title_main_en.nil? && !title_main_zh.nil?
86
104
  warn "No English Title!"
87
105
  end
@@ -91,8 +109,8 @@ module Asciidoctor
91
109
  end
92
110
 
93
111
  def title_part_validate(root)
94
- title_part_en = root.at("//title-part[@language='en']")
95
- title_part_zh = root.at("//title-part[@language='zh']")
112
+ title_part_en = root.at("//title[@type='title-part' and @language='en']")
113
+ title_part_zh = root.at("//title[@type='title-part' and @language='zh']")
96
114
  if title_part_en.nil? && !title_part_zh.nil?
97
115
  warn "No English Title Part!"
98
116
  end
@@ -1,14 +1,68 @@
1
+ require_relative "gbconvert"
2
+ require "gb_agencies"
3
+ require_relative "gbcleanup"
4
+ require_relative "metadata"
5
+ require "fileutils"
6
+
1
7
  module IsoDoc
2
8
  module Gb
3
- # A {Converter} implementation that generates GB output, and a document
4
- # schema encapsulation of the document for validation
5
- class HtmlConvert < IsoDoc::HtmlConvert
9
+ module BaseConvert
10
+ def extract_fonts(options)
11
+ b = options[:bodyfont] || "Arial"
12
+ h = options[:headerfont] || "Arial"
13
+ m = options[:monospacefont] || "Courier"
14
+ t = options[:titlefont] || "Arial"
15
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n"
16
+ end
17
+
18
+ def metadata_init(lang, script, labels)
19
+ unless ["en", "zh"].include? lang
20
+ lang = "zh"
21
+ script = "Hans"
22
+ end
23
+ @meta = Metadata.new(lang, script, labels)
24
+ @meta.set(:standardclassimg, @standardclassimg)
25
+ @common.meta = @meta
26
+ end
27
+
28
+ def cleanup(docxml)
29
+ @cleanup = Cleanup.new(@script, @deprecated_lbl)
30
+ super
31
+ @cleanup.cleanup(docxml)
32
+ docxml
33
+ end
34
+
35
+ def example_cleanup(docxml)
36
+ super
37
+ @cleanup.example_cleanup(docxml)
38
+ end
39
+
40
+ def i18n_init(lang, script)
41
+ super
42
+ y = if lang == "en"
43
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
44
+ elsif lang == "zh" && script == "Hans"
45
+ YAML.load_file(File.join(File.dirname(__FILE__),
46
+ "i18n-zh-Hans.yaml"))
47
+ else
48
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
49
+ end
50
+ @labels = @labels.merge(y)
51
+ end
52
+
53
+ def omit_docid_prefix(prefix)
54
+ super || prefix == "Chinese Standard"
55
+ end
56
+
6
57
  def formula_parse(node, out)
7
58
  out.div **attr_code(id: node["id"], class: "formula") do |div|
8
59
  insert_tab(div, 1)
9
60
  parse(node.at(ns("./stem")), out)
10
- insert_tab(div, 1)
11
- div << "(#{get_anchors[node['id']][:label]})"
61
+ lbl = anchor(node['id'], :label, false)
62
+ unless lbl.nil?
63
+ insert_tab(div, 1)
64
+ div << "(#{lbl})"
65
+ end
12
66
  end
13
67
  formula_where(node.at(ns("./dl")), out)
14
68
  end
@@ -63,7 +117,7 @@ module IsoDoc
63
117
  out.table **attr_code(id: node["id"], class: "Note") do |t|
64
118
  t.tr do |tr|
65
119
  tr.td **EXAMPLE_TBL_ATTR do |td|
66
- td << l10n("#{get_anchors[node['id']][:label]}:")
120
+ td << l10n("#{anchor(node['id'], :label)}:")
67
121
  end
68
122
  tr.td **{ valign: "top", class: "Note" } do |td|
69
123
  node.children.each { |n| parse(n, td) }
@@ -123,18 +177,6 @@ module IsoDoc
123
177
  end.join
124
178
  end
125
179
 
126
- def populate_template(docxml, format)
127
- meta = @meta.get.merge(@labels)
128
- logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format, @localdir)
129
- logofile = @meta.standard_logo(meta[:gbprefix])
130
- docxml = termref_resolve(docxml)
131
- meta[:standard_agency_formatted] =
132
- @common.format_agency(meta[:standard_agency], format, @localdir)
133
- meta[:standard_logo] = logo
134
- template = Liquid::Template.parse(docxml)
135
- template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
136
- end
137
-
138
180
  def foreword(isoxml, out)
139
181
  f = isoxml.at(ns("//foreword")) || return
140
182
  page_break(out)
@@ -163,42 +205,15 @@ module IsoDoc
163
205
  if node["inline-header"] == "true"
164
206
  inline_header_title(out, node, c1)
165
207
  else
166
- div.send "h#{get_anchors[node['id']][:level]}" do |h|
167
- h << "#{get_anchors[node['id']][:label]}.&#x3000;" if !@suppressheadingnumbers
208
+ div.send "h#{anchor(node['id'], :level) || '1'}" do |h|
209
+ lbl = anchor(node['id'], :label, false)
210
+ h << "#{lbl}.&#x3000;" if !@suppressheadingnumbers
168
211
  c1 and c1.children.each { |c2| parse(c2, h) }
169
212
  end
170
213
  end
171
214
  end
172
215
 
173
- def annex_name(annex, name, div)
174
- div.h1 **{ class: "Annex" } do |t|
175
- t << "#{get_anchors[annex['id']][:label]}<br/><br/>"
176
- t.b do |b|
177
- name&.children&.each { |c2| parse(c2, b) }
178
- end
179
- end
180
- end
181
-
182
- def term_defs_boilerplate(div, source, term, preface)
183
- unless preface
184
- (source.empty? && term.nil?) and div << @no_terms_boilerplate or
185
- div << term_defs_boilerplate_cont(source, term)
186
- end
187
- #div << @term_def_boilerplate unless preface
188
- end
189
-
190
- =begin
191
- def reference_names(ref)
192
- isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
193
- docid = ref.at(ns("./docidentifier"))
194
- date = ref.at(ns("./date[@type = 'published']"))
195
- allparts = ref.at(ns("./allparts"))
196
- reference = format_ref(docid.text, isopub, date, allparts)
197
- @anchors[ref["id"]] = { xref: reference }
198
- end
199
- =end
200
-
201
- def example_p_parse(node, div)
216
+ def example_p_parse(node, div)
202
217
  div.p do |p|
203
218
  p.span **{ class: "example_label" } do |s|
204
219
  s << example_label(node)
@@ -231,4 +246,3 @@ module IsoDoc
231
246
  end
232
247
  end
233
248
  end
234
-
@@ -1,8 +1,5 @@
1
- require_relative "gbconvert"
2
- require "gb_agencies"
3
- require_relative "gbcleanup"
4
- require_relative "metadata"
5
- require_relative "gbhtmlrender"
1
+ require_relative "gbbaseconvert"
2
+ require "isodoc"
6
3
 
7
4
  module IsoDoc
8
5
  module Gb
@@ -26,7 +23,7 @@ module IsoDoc
26
23
  headerfont: (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif'),
27
24
  monospacefont: '"Courier New",monospace',
28
25
  titlefont: (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) :
29
- (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
26
+ (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
30
27
  }
31
28
  end
32
29
 
@@ -39,52 +36,36 @@ module IsoDoc
39
36
  }
40
37
  end
41
38
 
42
- def extract_fonts(options)
43
- b = options[:bodyfont] || "Arial"
44
- h = options[:headerfont] || "Arial"
45
- m = options[:monospacefont] || "Courier"
46
- t = options[:titlefont] || "Arial"
47
- "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n"
39
+ def populate_template(docxml, format)
40
+ meta = @meta.get.merge(@labels)
41
+ logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format, @localdir)
42
+ logofile = @meta.standard_logo(meta[:gbprefix])
43
+ docxml = termref_resolve(docxml)
44
+ meta[:standard_agency_formatted] =
45
+ @common.format_agency(meta[:standard_agency], format, @localdir)
46
+ meta[:standard_logo] = logo
47
+ template = Liquid::Template.parse(docxml)
48
+ template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
48
49
  end
49
50
 
50
- def metadata_init(lang, script, labels)
51
- unless ["en", "zh"].include? lang
52
- lang = "zh"
53
- script = "Hans"
51
+ def annex_name(annex, name, div)
52
+ div.h1 **{ class: "Annex" } do |t|
53
+ t << "#{anchor(annex['id'], :label)}<br/><br/>"
54
+ t.b do |b|
55
+ name&.children&.each { |c2| parse(c2, b) }
56
+ end
54
57
  end
55
- @meta = Metadata.new(lang, script, labels)
56
- @meta.set(:standardclassimg, @standardclassimg)
57
- @common.meta = @meta
58
58
  end
59
59
 
60
- def cleanup(docxml)
61
- @cleanup = Cleanup.new(@script, @deprecated_lbl)
62
- super
63
- @cleanup.cleanup(docxml)
64
- docxml
65
- end
66
-
67
- def example_cleanup(docxml)
68
- super
69
- @cleanup.example_cleanup(docxml)
70
- end
71
-
72
- def i18n_init(lang, script)
73
- super
74
- y = if lang == "en"
75
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
76
- elsif lang == "zh" && script == "Hans"
77
- YAML.load_file(File.join(File.dirname(__FILE__),
78
- "i18n-zh-Hans.yaml"))
79
- else
80
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
81
- end
82
- @labels = @labels.merge(y)
60
+ def term_defs_boilerplate(div, source, term, preface)
61
+ unless preface
62
+ (source.empty? && term.nil?) and div << @no_terms_boilerplate or
63
+ div << term_defs_boilerplate_cont(source, term)
64
+ end
65
+ #div << @term_def_boilerplate unless preface
83
66
  end
84
67
 
85
- def omit_docid_prefix(prefix)
86
- super || prefix == "Chinese Standard"
87
- end
68
+ include BaseConvert
88
69
  end
89
70
  end
90
71
  end
@@ -1,10 +1,5 @@
1
+ require_relative "gbbaseconvert"
1
2
  require "isodoc"
2
- require_relative "gbconvert"
3
- require_relative "gbcleanup"
4
- require "gb_agencies"
5
- require_relative "metadata"
6
- require_relative "gbwordrender"
7
- require "fileutils"
8
3
 
9
4
  module IsoDoc
10
5
  module Gb
@@ -44,49 +39,6 @@ module IsoDoc
44
39
  }
45
40
  end
46
41
 
47
- def extract_fonts(options)
48
- b = options[:bodyfont] || "Arial"
49
- h = options[:headerfont] || "Arial"
50
- m = options[:monospacefont] || "Courier"
51
- t = options[:titlefont] || "Arial"
52
- "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n"
53
- end
54
-
55
- def metadata_init(lang, script, labels)
56
- unless ["en", "zh"].include? lang
57
- lang = "zh"
58
- script = "Hans"
59
- end
60
- @meta = Metadata.new(lang, script, labels)
61
- @meta.set(:standardclassimg, @standardclassimg)
62
- @common.meta = @meta
63
- end
64
-
65
- def cleanup(docxml)
66
- @cleanup = Cleanup.new(@script, @deprecated_lbl)
67
- super
68
- @cleanup.cleanup(docxml)
69
- docxml
70
- end
71
-
72
- def example_cleanup(docxml)
73
- super
74
- @cleanup.example_cleanup(docxml)
75
- end
76
-
77
- def i18n_init(lang, script)
78
- super
79
- y = if lang == "en"
80
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
81
- elsif lang == "zh" && script == "Hans"
82
- YAML.load_file(File.join(File.dirname(__FILE__),
83
- "i18n-zh-Hans.yaml"))
84
- else
85
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
86
- end
87
- @labels = @labels.merge(y)
88
- end
89
-
90
42
  ENDLINE = <<~END.freeze
91
43
  <v:line id="_x0000_s1026"
92
44
  alt="" style='position:absolute;left:0;text-align:left;z-index:251662848;
@@ -107,9 +59,46 @@ module IsoDoc
107
59
  docxml
108
60
  end
109
61
 
110
- def omit_docid_prefix(prefix)
111
- super || prefix == "Chinese Standard"
62
+ def example_table_parse(node, out)
63
+ out.table **attr_code(id: node["id"], class: "example") do |t|
64
+ t.tr do |tr|
65
+ tr.td **EXAMPLE_TBL_ATTR do |td|
66
+ td << l10n(example_label(node) + ":")
67
+ end
68
+ tr.td **{ valign: "top", class: "example" } do |td|
69
+ node.children.each { |n| parse(n, td) }
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def populate_template(docxml, format)
76
+ meta = @meta.get.merge(@labels)
77
+ logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format, @localdir)
78
+ logofile = @meta.standard_logo(meta[:gbprefix])
79
+ @files_to_delete << logofile + ".gif" unless logofile.nil?
80
+ docxml = termref_resolve(docxml)
81
+ meta[:standard_agency_formatted] =
82
+ @common.format_agency(meta[:standard_agency], format, @localdir)
83
+ meta[:standard_logo] = logo
84
+ template = Liquid::Template.parse(docxml)
85
+ template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
112
86
  end
87
+
88
+ def annex_name(annex, name, div)
89
+ div.h1 **{ class: "Annex" } do |t|
90
+ t << "#{anchor(annex['id'], :label)}<br/><br/>"
91
+ name&.children&.each { |c2| parse(c2, t) }
92
+ end
93
+ end
94
+
95
+ def term_defs_boilerplate(div, source, term, preface)
96
+ (source.empty? && term.nil?) and div << @no_terms_boilerplate or
97
+ div << term_defs_boilerplate_cont(source, term)
98
+ #div << @term_def_boilerplate unless preface
99
+ end
100
+
101
+ include BaseConvert
113
102
  end
114
103
  end
115
104
  end
@@ -24,10 +24,10 @@ module IsoDoc
24
24
  end
25
25
 
26
26
  def title(isoxml, _out)
27
- intro = isoxml.at(ns("//bibdata//title-intro[@language='zh']"))
28
- main = isoxml.at(ns("//bibdata//title-main[@language='zh']"))
29
- part = isoxml.at(ns("//bibdata//title-part[@language='zh']"))
30
- partnumber = isoxml.at(ns("//bibdata/docidentifier/project-number/@part"))
27
+ intro = isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='zh']"))
28
+ main = isoxml.at(ns("//bibdata//title[@type='title-main' and @language='zh']"))
29
+ part = isoxml.at(ns("//bibdata//title[@type='title-part' and @language='zh']"))
30
+ partnumber = isoxml.at(ns("//bibdata/ext/structuredidentifier/project-number/@part"))
31
31
  intro.nil? || set(:docmaintitlezh, intro.text + "&nbsp;")
32
32
  main.nil? || set(:docsubtitlezh, main.text)
33
33
  partnum = partnumber ? "#{part_label(partnumber, 'zh')}:" : ""
@@ -46,10 +46,10 @@ module IsoDoc
46
46
  end
47
47
 
48
48
  def subtitle(isoxml, _out)
49
- intro = isoxml.at(ns("//bibdata//title-intro[@language='en']"))
50
- main = isoxml.at(ns("//bibdata//title-main[@language='en']"))
51
- part = isoxml.at(ns("//bibdata//title-part[@language='en']"))
52
- partnumber = isoxml.at(ns("//bibdata/docidentifier/project-number/@part"))
49
+ intro = isoxml.at(ns("//bibdata//title[@type='title-intro' and @language='en']"))
50
+ main = isoxml.at(ns("//bibdata//title[@type='title-main' and @language='en']"))
51
+ part = isoxml.at(ns("//bibdata//title[@type='title-part' and @language='en']"))
52
+ partnumber = isoxml.at(ns("//bibdata/ext/structuredidentifier/project-number/@part"))
53
53
  intro.nil? || set(:docmaintitleen, intro.text + "&mdash;")
54
54
  main.nil? || set(:docsubtitleen, main.text)
55
55
  partnum = partnumber ? "#{part_label(partnumber, 'en')}: " : ""
@@ -59,7 +59,7 @@ module IsoDoc
59
59
  end
60
60
 
61
61
  def author(isoxml, _out)
62
- gbcommittee = isoxml.at(ns("//bibdata/gbcommittee"))
62
+ gbcommittee = isoxml.at(ns("//bibdata/ext/gbcommittee"))
63
63
  set(:committee, gbcommittee&.text)
64
64
  end
65
65
 
@@ -164,9 +164,9 @@ module IsoDoc
164
164
  end
165
165
 
166
166
  def gb_identifier(isoxml)
167
- scope = isoxml.at(ns("//bibdata/gbtype/gbscope"))&.text || "national"
168
- mandate = isoxml.at(ns("//bibdata/gbtype/gbmandate"))&.text || "mandatory"
169
- prefix = isoxml.at(ns("//bibdata/gbtype/gbprefix"))&.text || "XXX"
167
+ scope = isoxml.at(ns("//bibdata/ext/gbtype/gbscope"))&.text || "national"
168
+ mandate = isoxml.at(ns("//bibdata/ext/gbtype/gbmandate"))&.text || "mandatory"
169
+ prefix = isoxml.at(ns("//bibdata/ext/gbtype/gbprefix"))&.text || "XXX"
170
170
  docyear = isoxml&.at(ns("//bibdata/copyright/from"))&.text
171
171
  issuer = isoxml&.at(ns("//bibdata/contributor[role/@type = 'issuer']/"\
172
172
  "organization/name"))&.text || "GB"
@@ -199,9 +199,9 @@ module IsoDoc
199
199
  def gb_library_identifier(isoxml)
200
200
  ics = []
201
201
  ccs = []
202
- isoxml.xpath(ns("//bibdata/ics/code")).each { |i| ics << i.text }
203
- isoxml.xpath(ns("//bibdata/ccs")).each { |i| ccs << i.text }
204
- p = isoxml.at(ns("//bibdata/plannumber"))
202
+ isoxml.xpath(ns("//bibdata/ext/ics/code")).each { |i| ics << i.text }
203
+ isoxml.xpath(ns("//bibdata/ext/ccs")).each { |i| ccs << i.text }
204
+ p = isoxml.at(ns("//bibdata/ext/plannumber"))
205
205
  set(:libraryid_ics, ics.empty? ? "XXX" : ics.join(", "))
206
206
  set(:libraryid_ccs, ccs.empty? ? "XXX" : ccs.join(", "))
207
207
  set(:libraryid_plan, p ? p.text : "XXX")