metanorma-gb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.hound.yml +3 -0
  4. data/.oss-guides.rubocop.yml +1077 -0
  5. data/.rubocop.ribose.yml +65 -0
  6. data/.rubocop.tb.yml +650 -0
  7. data/.rubocop.yml +15 -0
  8. data/.travis.yml +15 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE +25 -0
  12. data/README.adoc +369 -0
  13. data/Rakefile +6 -0
  14. data/asciidoctor-gb.gemspec.old +47 -0
  15. data/bin/console +14 -0
  16. data/bin/rspec +18 -0
  17. data/bin/setup +8 -0
  18. data/lib/asciidoctor-gb.rb +11 -0
  19. data/lib/asciidoctor/gb.rb +7 -0
  20. data/lib/asciidoctor/gb/biblio.rng +836 -0
  21. data/lib/asciidoctor/gb/converter.rb +224 -0
  22. data/lib/asciidoctor/gb/front.rb +228 -0
  23. data/lib/asciidoctor/gb/gbstandard.rng +409 -0
  24. data/lib/asciidoctor/gb/html/blank.png +0 -0
  25. data/lib/asciidoctor/gb/html/footer.png +0 -0
  26. data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.png +0 -0
  27. data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.svg +980 -0
  28. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.gif +0 -0
  29. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.png +0 -0
  30. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.svg +1 -0
  31. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.gif +0 -0
  32. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.png +0 -0
  33. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.svg +1 -0
  34. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
  35. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.png +0 -0
  36. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
  37. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.gif +0 -0
  38. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.png +0 -0
  39. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.svg +1 -0
  40. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
  41. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.png +0 -0
  42. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
  43. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.gif +0 -0
  44. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.png +0 -0
  45. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.svg +13 -0
  46. data/lib/asciidoctor/gb/html/gb.scss +556 -0
  47. data/lib/asciidoctor/gb/html/header.html +216 -0
  48. data/lib/asciidoctor/gb/html/html_gb_intro.html +9 -0
  49. data/lib/asciidoctor/gb/html/html_gb_titlepage.html +99 -0
  50. data/lib/asciidoctor/gb/html/htmlstyle.scss +269 -0
  51. data/lib/asciidoctor/gb/html/logo.png +0 -0
  52. data/lib/asciidoctor/gb/html/word_gb_intro.html +3 -0
  53. data/lib/asciidoctor/gb/html/word_gb_titlepage.html +388 -0
  54. data/lib/asciidoctor/gb/html/wordstyle.scss +2543 -0
  55. data/lib/asciidoctor/gb/isodoc.rng +1059 -0
  56. data/lib/asciidoctor/gb/isostandard.rng +1001 -0
  57. data/lib/asciidoctor/gb/section_input.rb +150 -0
  58. data/lib/asciidoctor/gb/validate.rb +115 -0
  59. data/lib/asciidoctor/gb/version.rb +5 -0
  60. data/lib/isodoc/gb/gbcleanup.rb +90 -0
  61. data/lib/isodoc/gb/gbconvert.rb +66 -0
  62. data/lib/isodoc/gb/gbhtmlconvert.rb +84 -0
  63. data/lib/isodoc/gb/gbhtmlrender.rb +208 -0
  64. data/lib/isodoc/gb/gbwordconvert.rb +136 -0
  65. data/lib/isodoc/gb/gbwordrender.rb +206 -0
  66. data/lib/isodoc/gb/html/blank.png +0 -0
  67. data/lib/isodoc/gb/html/footer.png +0 -0
  68. data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.png +0 -0
  69. data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.svg +980 -0
  70. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.gif +0 -0
  71. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.png +0 -0
  72. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.svg +1 -0
  73. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.gif +0 -0
  74. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.png +0 -0
  75. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.svg +1 -0
  76. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
  77. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.png +0 -0
  78. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
  79. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.gif +0 -0
  80. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.png +0 -0
  81. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.svg +1 -0
  82. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
  83. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.png +0 -0
  84. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
  85. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.gif +0 -0
  86. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.png +0 -0
  87. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.svg +13 -0
  88. data/lib/isodoc/gb/html/gb.scss +556 -0
  89. data/lib/isodoc/gb/html/header.html +216 -0
  90. data/lib/isodoc/gb/html/html_compliant_gb_titlepage.html +116 -0
  91. data/lib/isodoc/gb/html/html_gb_intro.html +6 -0
  92. data/lib/isodoc/gb/html/html_gb_titlepage.html +94 -0
  93. data/lib/isodoc/gb/html/htmlcompliantstyle.scss +1220 -0
  94. data/lib/isodoc/gb/html/htmlstyle.scss +1007 -0
  95. data/lib/isodoc/gb/html/logo.png +0 -0
  96. data/lib/isodoc/gb/html/scripts.html +71 -0
  97. data/lib/isodoc/gb/html/word_gb_intro.html +3 -0
  98. data/lib/isodoc/gb/html/word_gb_titlepage.html +388 -0
  99. data/lib/isodoc/gb/html/wordstyle.scss +2543 -0
  100. data/lib/isodoc/gb/i18n-en.yaml +12 -0
  101. data/lib/isodoc/gb/i18n-zh-Hans.yaml +12 -0
  102. data/lib/isodoc/gb/metadata.rb +232 -0
  103. data/lib/metanorma/gb.rb +7 -0
  104. data/lib/metanorma/gb/processor.rb +43 -0
  105. data/metanorma-gb.gemspec +48 -0
  106. metadata +380 -0
@@ -0,0 +1,224 @@
1
+ require "asciidoctor"
2
+ require "asciidoctor/iso/converter"
3
+ require "asciidoctor/gb/version"
4
+ require "isodoc/gb/gbconvert"
5
+ require "isodoc/gb/gbwordconvert"
6
+ require "gb_agencies"
7
+ require_relative "./section_input.rb"
8
+ require_relative "./front.rb"
9
+ require_relative "./validate.rb"
10
+
11
+ module Asciidoctor
12
+ module Gb
13
+ GB_NAMESPACE = "http://riboseinc.com/gbstandard"
14
+
15
+ # A {Converter} implementation that generates GB output, and a document
16
+ # schema encapsulation of the document for validation
17
+ class Converter < ISO::Converter
18
+
19
+ register_for "gb"
20
+
21
+ def makexml(node)
22
+ result = ["<?xml version='1.0' encoding='UTF-8'?>\n<gb-standard>"]
23
+ @draft = node.attributes.has_key?("draft")
24
+ @keepboilerplate = node.attributes.has_key?("keep-boilerplate")
25
+ result << noko { |ixml| front node, ixml }
26
+ result << noko { |ixml| middle node, ixml }
27
+ result << "</gb-standard>"
28
+ result = textcleanup(result.flatten * "\n")
29
+ ret1 = cleanup(Nokogiri::XML(result))
30
+ validate(ret1)
31
+ ret1.root.add_namespace(nil, GB_NAMESPACE)
32
+ ret1
33
+ end
34
+
35
+ def html_converter(node)
36
+ node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) :
37
+ IsoDoc::Gb::HtmlConvert.new(
38
+ html_extract_attributes(node).merge(titlefont:
39
+ node.attr("title-font")))
40
+ end
41
+
42
+ def html_compliant_converter(node)
43
+ node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) :
44
+ IsoDoc::Gb::HtmlConvert.new(html_extract_attributes(node).
45
+ merge(compliant: true,
46
+ titlefont: node.attr("title-font")))
47
+ end
48
+
49
+ def doc_converter(node)
50
+ node.nil? ? IsoDoc::Gb::WordConvert.new({}) :
51
+ IsoDoc::Gb::WordConvert.new(doc_extract_attributes(node).
52
+ merge(titlefont: node.attr("title-font")))
53
+ end
54
+
55
+ def document(node)
56
+ init(node)
57
+ ret = makexml(node).to_xml(indent: 2)
58
+ unless node.attr("nodoc") || !node.attr("docfile")
59
+ filename = node.attr("docfile").gsub(/\.adoc$/, "").gsub(%r{^.*/}, "")
60
+ File.open(filename + ".xml", "w") { |f| f.write(ret) }
61
+ html_compliant_converter(node).convert(filename + ".xml")
62
+ system "mv #{filename}.html #{filename}_compliant.html"
63
+ html_converter(node).convert(filename + ".xml")
64
+ doc_converter(node).convert(filename + ".xml")
65
+ end
66
+ @files_to_delete.each { |f| system "rm #{f}" }
67
+ ret
68
+ end
69
+
70
+ def termdef_cleanup(xmldoc)
71
+ super
72
+ localisedstr(xmldoc)
73
+ end
74
+
75
+ ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
76
+ HAN_TEXT = /\s*[\u4e00-\u9fff]+/
77
+
78
+ LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
79
+ "//initial | //addition | //surname | //forename | //name | "\
80
+ "//abbreviation | //role/description | //affiliation/description | "\
81
+ "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
82
+ "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
83
+ "//bibdata/abstract | //bibitem/note ".freeze
84
+
85
+ MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
86
+
87
+ def localisedstr(xmldoc)
88
+ xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
89
+ if zh.at("./string")
90
+ extract_localisedstrings(zh)
91
+ elsif MUST_LOCALISE_ELEMS.include? zh.name
92
+ duplicate_localisedstrings(zh)
93
+ end
94
+ end
95
+ end
96
+
97
+ # element consists solely of localised strings, with no attributes
98
+ def extract_localisedstrings(elem)
99
+ elem.xpath("./string").each do |s|
100
+ s.name = elem.name
101
+ end
102
+ elem.replace(elem.children)
103
+ end
104
+
105
+ def duplicate_localisedstrings(zh)
106
+ en = zh.dup.remove
107
+ zh.after(en).after(" ")
108
+ zh["language"] = "zh"
109
+ en["language"] = "en"
110
+ en.traverse do |c|
111
+ c.text? && c.content = c.text.gsub(HAN_TEXT, "").gsub(/^\s*/, "")
112
+ end
113
+ zh.traverse do |c|
114
+ c.text? && c.content = c.text.gsub(ROMAN_TEXT, "").gsub(/^\s*/, "")
115
+ end
116
+ end
117
+
118
+ def inline_quoted(node)
119
+ ret = noko do |xml|
120
+ case node.role
121
+ when "en" then xml.string node.text, **{ language: "en" }
122
+ when "zh" then xml.string node.text, **{ language: "zh" }
123
+ when "zh-Hans"
124
+ xml.string node.text, **{ language: "zh", script: "Hans" }
125
+ when "zh-Hant"
126
+ xml.string node.text, **{ language: "zh", script: "Hant" }
127
+ else
128
+ nil
129
+ end
130
+ end.join
131
+ return ret unless ret.nil? or ret.empty?
132
+ super
133
+ end
134
+
135
+ def termdef_boilerplate_cleanup(xmldoc)
136
+ return if @keepboilerplate
137
+ super
138
+ end
139
+
140
+ GBCODE = "((AQ|BB|CB|CH|CJ|CY|DA|DB|DL|DZ|EJ|FZ|GA|GH|GM|GY|HB|HG|"\
141
+ "HJ|HS|HY|JB|JC|JG|JR|JT|JY|LB|LD|LS|LY|MH|MT|MZ|NY|QB|QC|QJ|"\
142
+ "QZ|SB|SC|SH|SJ|SN|SY|TB|TD|TJ|TY|WB|WH|WJ|WM|WS|WW|XB|YB|YC|"\
143
+ "YD|YS|YY|YZ|ZY|GB|GBZ|GJB|GBn|GHZB|GWKB|GWPB|JJF|JJG|Q|T)(/Z|/T)?)"
144
+
145
+ ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
146
+ \[(?<code>(ISO|IEC|#{GBCODE})[^0-9]*\s[0-9-]+?)
147
+ ([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s
148
+ (?<text>.*)$}xm
149
+
150
+ ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
151
+ \[(?<code>(ISO|IEC|#{GBCODE})[^0-9]*\s[0-9-]+):--\]</ref>,?\s?
152
+ <fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?(?<text>.*)$}xm
153
+
154
+ ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
155
+ \[(?<code>(ISO|IEC|#{GBCODE})[^0-9]*\s[0-9]+)\s
156
+ \(all\sparts\)\]</ref>(<p>)?,?\s?
157
+ (?<text>.*)(</p>)?$}xm
158
+
159
+ def reference1_matches(item)
160
+ matched = ISO_REF.match item
161
+ matched2 = ISO_REF_NO_YEAR.match item
162
+ matched3 = ISO_REF_ALL_PARTS.match item
163
+ [matched, matched2, matched3]
164
+ end
165
+
166
+ def fetch_ref(xml, code, year, **opts)
167
+ code = "GB Standard " + code if /^#{GBCODE}[^A-Za-z]/.match? code
168
+ hit = @bibdb&.fetch(code, year, opts)
169
+ return nil if hit.nil?
170
+ xml.parent.add_child(hit.to_xml)
171
+ xml
172
+ rescue Algolia::AlgoliaProtocolError
173
+ nil # Render reference without an Internet connection.
174
+ end
175
+
176
+ def cleanup(xmldoc)
177
+ lang = xmldoc.at("//language")&.text
178
+ @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
179
+ super
180
+ contributor_cleanup(xmldoc)
181
+ xmldoc
182
+ end
183
+
184
+ def docidentifier_cleanup(xmldoc)
185
+ id = xmldoc.at("//bibdata/docidentifier/project-number") or return
186
+ scope = xmldoc.at("//gbscope")&.text
187
+ prefix = xmldoc.at("//gbprefix")&.text
188
+ mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
189
+ idtext = @agencyclass.docidentifier(scope, prefix, mandate,
190
+ nil, id.text) || return
191
+ id.content = idtext.gsub(/\&#x2002;/, " ")
192
+ end
193
+
194
+ def committee_cleanup(xmldoc)
195
+ xmldoc.xpath("//gbcommittee").each do |c|
196
+ xmldoc.at("//bibdata/contributor").next =
197
+ "<contributor><role type='technical-committee'/><organization>"\
198
+ "<name>#{c.text}</name></organization></contributor>"
199
+ end
200
+ end
201
+
202
+ def agency_value(issuer, scope, prefix, mandate)
203
+ agency = issuer.content
204
+ agency == "GB" and
205
+ agency = @agencyclass.standard_agency1(scope, prefix, mandate)
206
+ agency = "GB" if agency.nil? || agency.empty?
207
+ agency
208
+ end
209
+
210
+ def contributor_cleanup(xmldoc)
211
+ issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
212
+ "organization/name")
213
+ scope = xmldoc.at("//gbscope")&.text
214
+ prefix = xmldoc.at("//gbprefix")&.text
215
+ mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
216
+ agency = agency_value(issuer, scope, prefix, mandate)
217
+ owner = xmldoc.at("//copyright/owner/organization/name")
218
+ owner.content = agency
219
+ issuer.content = agency
220
+ committee_cleanup(xmldoc)
221
+ end
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,228 @@
1
+
2
+ module Asciidoctor
3
+ module Gb
4
+ class Converter < ISO::Converter
5
+ def standard_type(node)
6
+ type = node.attr("mandate") || "mandatory"
7
+ type = "standard" if type == "mandatory"
8
+ type = "recommendation" if type == "recommended"
9
+ type
10
+ end
11
+
12
+ def front(node, xml)
13
+ xml.bibdata **attr_code(type: standard_type(node)) do |b|
14
+ metadata node, b
15
+ end
16
+ metadata_version(node, xml)
17
+ end
18
+
19
+ def metadata_author(node, xml)
20
+ author = node.attr("author") || return
21
+ author.split(/, ?/).each do |author|
22
+ xml.contributor do |c|
23
+ c.role **{ type: "author" }
24
+ c.person do |p|
25
+ p.name do |n|
26
+ n.surname author
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def metadata_contributor1(node, xml, type, role)
34
+ contrib = node.attr(type) || "GB"
35
+ contrib.split(/, ?/).each do |c|
36
+ xml.contributor do |x|
37
+ x.role **{ type: role }
38
+ x.organization do |a|
39
+ a.name { |n| n << c }
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def metadata_copyright(node, xml)
46
+ from = node.attr("copyright-year") || Date.today.year
47
+ xml.copyright do |c|
48
+ c.from from
49
+ c.owner do |owner|
50
+ owner.organization do |o|
51
+ o.name "GB"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def metadata_committee(node, xml)
58
+ attrs = { type: node.attr("technical-committee-type") }
59
+ xml.gbcommittee **attr_code(attrs) do |a|
60
+ a << node.attr("technical-committee")
61
+ end
62
+ end
63
+
64
+ def metadata_equivalence(node, xml)
65
+ isostd = node.attr("iso-standard") || return
66
+ type = node.attr("equivalence") || "equivalent"
67
+ m = /^(?<code>[^,]+),?(?<title>.*)$/.match isostd
68
+ title = m[:title].empty? ? "[not supplied]" : m[:title]
69
+ xml.relation **{ type: type } do |r|
70
+ r.bibitem do |b|
71
+ b.title { |t| t << title }
72
+ b.docidentifier m[:code]
73
+ end
74
+ end
75
+ end
76
+
77
+ def metadata_obsoletes(node, xml)
78
+ std = node.attr("obsoletes") || return
79
+ m = /^(?<code>[^,]+),?(?<title>.*)$/.match std
80
+ title = m[:title].empty? ? "[not supplied]" : m[:title]
81
+ xml.relation **{ type: "obsoletes" } do |r|
82
+ r.bibitem do |b|
83
+ b.title { |t| t << title }
84
+ b.docidentifier m[:code]
85
+ end
86
+ r.bpart node.attr("obsoletes-parts") if node.attr("obsoletes-parts")
87
+ end
88
+ end
89
+
90
+ def get_scope(node)
91
+ node.attr("scope") and return node.attr("scope")
92
+ scope = if %r{^[TQ]/}.match? node.attr("prefix")
93
+ m = node.attr("prefix").split(%{/})
94
+ mandate = m[0] == "T" ? "social-group" :
95
+ m[0] == "Q" ? "enterprise" : nil
96
+ end
97
+ return scope unless scope.nil?
98
+ warn "GB: no scope supplied, defaulting to National"
99
+ "national"
100
+ end
101
+
102
+ def get_prefix(node)
103
+ scope = get_scope(node)
104
+ if prefix = node.attr("prefix")
105
+ prefix.gsub!(%r{/[TZ]$}, "")
106
+ prefix.gsub!(%r{^[TQ]/([TZ]/)?}, "")
107
+ prefix.gsub!(/^DB/, "") if scope == "local"
108
+ else
109
+ prefix = "GB"
110
+ scope = "national"
111
+ warn "GB: no prefix supplied, defaulting to GB"
112
+ end
113
+ [scope, prefix]
114
+ end
115
+
116
+ def get_mandate(node)
117
+ node.attr("mandate") and return node.attr("mandate")
118
+ p = node.attr("prefix")
119
+ mandate = %r{/T}.match?(p) ? "recommended" :
120
+ %r{/Z}.match?(p) ? "guidelines" : nil
121
+ if mandate.nil?
122
+ mandate = "mandatory"
123
+ warn "GB: no mandate supplied, defaulting to mandatory"
124
+ end
125
+ mandate
126
+ end
127
+
128
+ def get_topic(node)
129
+ node.attr("topic") and return node.attr("topic")
130
+ warn "GB: no topic supplied, defaulting to basic"
131
+ "basic"
132
+ end
133
+
134
+ def metadata_gbtype(node, xml)
135
+ xml.gbtype do |t|
136
+ scope, prefix = get_prefix(node)
137
+ t.gbscope { |s| s << scope }
138
+ t.gbprefix { |p| p << prefix }
139
+ t.gbmandate { |m| m << get_mandate(node) }
140
+ t.gbtopic { |t| t << get_topic(node) }
141
+ end
142
+ end
143
+
144
+ def metadata_date1(node, xml, type)
145
+ date = node.attr("#{type}-date")
146
+ date and xml.date **{ type: type } do |d|
147
+ d.on date
148
+ end
149
+ end
150
+
151
+ DATETYPES = %w{ published accessed created implemented obsoleted
152
+ confirmed updated issued
153
+ }.freeze
154
+
155
+ def metadata_date(node, xml)
156
+ DATETYPES.each do |t|
157
+ metadata_date1(node, xml, t)
158
+ end
159
+ end
160
+
161
+ def metadata_gblibraryids(node, xml)
162
+ ccs = node.attr("library-ccs")
163
+ ccs and ccs.split(/, ?/).each do |l|
164
+ xml.ccs { |c| c << l }
165
+ end
166
+ l = node.attr("library-plan")
167
+ l && xml.plannumber { |plan| plan << l }
168
+ end
169
+
170
+ def metadata_contributors(node, xml)
171
+ metadata_author(node, xml)
172
+ metadata_contributor1(node, xml, "author-committee", "author")
173
+ metadata_contributor1(node, xml, "publisher", "publisher")
174
+ metadata_contributor1(node, xml, "authority", "authority")
175
+ metadata_contributor1(node, xml, "proposer", "proposer")
176
+ metadata_contributor1(node, xml, "issuer", "issuer")
177
+ end
178
+
179
+ def metadata(node, xml)
180
+ title node, xml
181
+ metadata_id(node, xml)
182
+ metadata_date(node, xml)
183
+ metadata_contributors(node, xml)
184
+ xml.language (node.attr("language") || "zh")
185
+ xml.script (node.attr("script") || "Hans")
186
+ metadata_status(node, xml)
187
+ metadata_copyright(node, xml)
188
+ metadata_equivalence(node, xml)
189
+ metadata_obsoletes(node, xml)
190
+ metadata_ics(node, xml)
191
+ metadata_committee(node, xml)
192
+ metadata_gbtype(node, xml)
193
+ metadata_gblibraryids(node, xml)
194
+ end
195
+
196
+ def title_intro(node, lang, t, at)
197
+ node.attr("title-intro-#{lang}") and
198
+ t.title_intro **attr_code(at) do |t1|
199
+ t1 << asciidoc_sub(node.attr("title-intro-#{lang}"))
200
+ end
201
+ end
202
+
203
+ def title_main(node, lang, t, at)
204
+ t.title_main **attr_code(at) do |t1|
205
+ t1 << asciidoc_sub(node.attr("title-main-#{lang}"))
206
+ end
207
+ end
208
+
209
+ def title_part(node, lang, t, at)
210
+ node.attr("title-part-#{lang}") and
211
+ t.title_part **attr_code(at) do |t1|
212
+ t1 << asciidoc_sub(node.attr("title-part-#{lang}"))
213
+ end
214
+ end
215
+
216
+ def title(node, xml)
217
+ ["en", "zh"].each do |lang|
218
+ xml.title do |t|
219
+ at = { language: lang, format: "plain" }
220
+ title_intro(node, lang, t, at)
221
+ title_main(node, lang, t, at)
222
+ title_part(node, lang, t, at)
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end