asciidoctor-gb 0.1.5 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.tb.yml +20 -10
- data/LICENSE +25 -0
- data/README.adoc +262 -34
- data/asciidoctor-gb.gemspec +2 -1
- data/bin/rspec +18 -0
- data/lib/asciidoctor/gb/biblio.rng +602 -0
- data/lib/asciidoctor/gb/converter.rb +104 -70
- data/lib/asciidoctor/gb/front.rb +109 -61
- data/lib/asciidoctor/gb/gbstandard.rng +135 -31
- data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.gif +0 -0
- data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.png +0 -0
- data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.svg +980 -0
- data/lib/asciidoctor/gb/html/{gb.css → gb.scss} +133 -219
- data/lib/asciidoctor/gb/html/html_gb_intro.html +1 -37
- data/lib/asciidoctor/gb/html/html_gb_titlepage.html +6 -5
- data/lib/asciidoctor/gb/html/{htmlstyle.css → htmlstyle.scss} +85 -3
- data/lib/asciidoctor/gb/html/word_gb_intro.html +1 -1
- data/lib/asciidoctor/gb/html/word_gb_titlepage.html +320 -166
- data/lib/asciidoctor/gb/html/{wordstyle.css → wordstyle.scss} +605 -429
- data/lib/asciidoctor/gb/isodoc.rng +36 -564
- data/lib/asciidoctor/gb/isostandard.rng +198 -91
- data/lib/asciidoctor/gb/section_input.rb +21 -56
- data/lib/asciidoctor/gb/validate.rb +115 -0
- data/lib/asciidoctor/gb/version.rb +1 -1
- data/lib/asciidoctor-gb.rb +2 -1
- data/lib/isodoc/gb/agencies.rb +327 -0
- data/lib/isodoc/gb/block_output.rb +86 -0
- data/lib/isodoc/gb/gbcleanup.rb +87 -0
- data/lib/isodoc/gb/gbconvert.rb +153 -0
- data/lib/isodoc/gb/gbwordconvert.rb +89 -0
- data/lib/isodoc/gb/html/blank.png +0 -0
- data/lib/isodoc/gb/html/footer.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.svg +980 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-db.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-db.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-db.svg +1 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.svg +1 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.svg +1 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.gif +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.png +0 -0
- data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.svg +13 -0
- data/lib/isodoc/gb/html/gb.scss +556 -0
- data/lib/isodoc/gb/html/header.html +216 -0
- data/lib/isodoc/gb/html/html_gb_intro.html +9 -0
- data/lib/isodoc/gb/html/html_gb_titlepage.html +99 -0
- data/lib/isodoc/gb/html/htmlstyle.scss +269 -0
- data/lib/isodoc/gb/html/logo.png +0 -0
- data/lib/isodoc/gb/html/scripts.html +71 -0
- data/lib/isodoc/gb/html/word_gb_intro.html +3 -0
- data/lib/isodoc/gb/html/word_gb_titlepage.html +388 -0
- data/lib/isodoc/gb/html/wordstyle.scss +2543 -0
- data/lib/isodoc/gb/i18n-en.yaml +12 -0
- data/lib/isodoc/gb/i18n-zh-Hans.yaml +12 -0
- data/lib/isodoc/gb/i18n.rb +20 -0
- data/lib/isodoc/gb/metadata.rb +216 -0
- data/lib/{asciidoctor → isodoc}/gb/section_output.rb +22 -4
- data/lib/isodoc/gb/xref_gen.rb +17 -0
- metadata +75 -15
- data/lib/asciidoctor/gb/agencies.rb +0 -186
- data/lib/asciidoctor/gb/gbconvert.rb +0 -86
- data/lib/asciidoctor/gb/metadata.rb +0 -186
- data/lib/asciidoctor/gb/xref_gen.rb +0 -25
@@ -1,186 +0,0 @@
|
|
1
|
-
require "isodoc"
|
2
|
-
|
3
|
-
module Asciidoctor
|
4
|
-
module Gb
|
5
|
-
class GbConvert < IsoDoc::Convert
|
6
|
-
SECTOR = {
|
7
|
-
AQ: { industry: "安全生产", admin: "国家安全生产管理局" },
|
8
|
-
BB: { industry: "包装", admin: "国家发改委" },
|
9
|
-
CB: { industry: "船舶", admin: "国防科学工业委员会" },
|
10
|
-
CH: { industry: "测绘", admin: "国家测绘局" },
|
11
|
-
CJ: { industry: "城镇建设", admin: "建设部" },
|
12
|
-
CY: { industry: "新闻出版", admin: "国家新闻出版总署" },
|
13
|
-
DA: { industry: "档案", admin: "国家档案局" },
|
14
|
-
DB: { industry: "地震", admin: "中国地震局" },
|
15
|
-
DL: { industry: "电力", admin: "国家发改委" },
|
16
|
-
DZ: { industry: "地质矿产", admin: "国土资源部" },
|
17
|
-
EJ: { industry: "核工业", admin: "国防科学工业委员会" },
|
18
|
-
FZ: { industry: "纺织", admin: "国家发改委" },
|
19
|
-
GA: { industry: "公共安全", admin: "公安部" },
|
20
|
-
GH: { industry: "供销", admin: "中华全国供销合作总社" },
|
21
|
-
GM: { industry: "密码", admin: "国家密码管理局" },
|
22
|
-
GY: { industry: "广播电影电视", admin: "国家广播电影电视总局" },
|
23
|
-
HB: { industry: "航空", admin: "国防科学工业委员会" },
|
24
|
-
HG: { industry: "化工", admin: "国家发改委" },
|
25
|
-
HJ: { industry: "环境保护", admin: "国家环境保护总局" },
|
26
|
-
HS: { industry: "海关", admin: "海关总署" },
|
27
|
-
HY: { industry: "海洋", admin: "国家海洋局" },
|
28
|
-
JB: { industry: "机械", admin: "国家发改委" },
|
29
|
-
JC: { industry: "建材", admin: "国家发改委" },
|
30
|
-
JG: { industry: "建筑工业", admin: "建设部" },
|
31
|
-
JR: { industry: "金融", admin: "中国人民银行" },
|
32
|
-
JT: { industry: "交通", admin: "交通部" },
|
33
|
-
JY: { industry: "教育", admin: "教育部" },
|
34
|
-
LB: { industry: "旅游", admin: "国家旅游局" },
|
35
|
-
LD: { industry: "劳动和劳动安全", admin: "劳动和社会保障部" },
|
36
|
-
LS: { industry: "粮食", admin: "国家粮食局" },
|
37
|
-
LY: { industry: "林业", admin: "国家林业局" },
|
38
|
-
MH: { industry: "民用航空", admin: "中国民航管理总局" },
|
39
|
-
MT: { industry: "煤炭", admin: "国家发改委" },
|
40
|
-
MZ: { industry: "民政", admin: "民政部" },
|
41
|
-
NY: { industry: "农业", admin: "农业部" },
|
42
|
-
QB: { industry: "轻工", admin: "国家发改委" },
|
43
|
-
QC: { industry: "汽车", admin: "国家发改委" },
|
44
|
-
QJ: { industry: "航天", admin: "国防科学工业委员会" },
|
45
|
-
QX: { industry: "气象", admin: "中国气象局" },
|
46
|
-
SB: { industry: "国内贸易", admin: "商务部" },
|
47
|
-
SC: { industry: "水产", admin: "农业部" },
|
48
|
-
SH: { industry: "石油化工", admin: "国家发改委" },
|
49
|
-
SJ: { industry: "电子", admin: "信息产业部" },
|
50
|
-
SL: { industry: "水利", admin: "水利部" },
|
51
|
-
SN: { industry: "商检", admin: "国家质量监督检验检疫总局" },
|
52
|
-
SY: { industry: "石油天然气", admin: "国家发改委" },
|
53
|
-
TB: { industry: "铁道", admin: "铁道部" },
|
54
|
-
TD: { industry: "土地管理", admin: "国土资源部" },
|
55
|
-
TJ: { industry: "铁道交通", admin: "铁道部标准所" },
|
56
|
-
TY: { industry: "体育", admin: "国家体育总局" },
|
57
|
-
WB: { industry: "物资管理", admin: "国家发改委" },
|
58
|
-
WH: { industry: "文化", admin: "文化部" },
|
59
|
-
WJ: { industry: "兵工民品", admin: "国防科学工业委员会" },
|
60
|
-
WM: { industry: "外经贸", admin: "外经贸部科技司" },
|
61
|
-
WS: { industry: "卫生", admin: "卫生部" },
|
62
|
-
WW: { industry: "文物保护", admin: "国家文物局" },
|
63
|
-
XB: { industry: "稀土", admin: "国家发改委稀土办公室" },
|
64
|
-
YB: { industry: "黑色冶金", admin: "国家发改委" },
|
65
|
-
YC: { industry: "烟草", admin: "国家烟草专卖局" },
|
66
|
-
YD: { industry: "通信", admin: "信息产业部" },
|
67
|
-
YS: { industry: "有色冶金", admin: "国家发改委" },
|
68
|
-
YY: { industry: "医药", admin: "国家食品药品监督管理局" },
|
69
|
-
YZ: { industry: "邮政", admin: "国家邮政局" },
|
70
|
-
ZY: { industry: "中医药", admin: "国家中医药管理局" },
|
71
|
-
}.freeze
|
72
|
-
|
73
|
-
NATIONAL = {
|
74
|
-
GB: { name: "中华人民共和国国家标准",
|
75
|
-
admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] },
|
76
|
-
"GB/T": { name: "中华人民共和国国家标准",
|
77
|
-
admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] },
|
78
|
-
"GB/Z": { name: "中华人民共和国国家标准化指导性技术文件",
|
79
|
-
admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] },
|
80
|
-
GBZ: { name: "中华人民共和国国家职业卫生标准", admin: "中华人民共和国卫生部" },
|
81
|
-
GJB: { name: "中华人民共和国国家军用标准", admin: "中国人民解放军装备总部" },
|
82
|
-
GBn: { name: "中华人民共和国国家内部标准", admin: "" },
|
83
|
-
GHZB: { name: "中华人民共和国国家环境质量标准", admin: "" }, GWKB: { name: "中华人民共和国国家环境保护标准", admin: "环境保护部" },
|
84
|
-
GWPB: { name: "中华人民共和国国家污染物排放标准", admin: "" },
|
85
|
-
JJF: { name: "中华人民共和国国家计量技术规范", admin: "中华人民共和国国家质量监督检验检疫总局" },
|
86
|
-
JJG: { name: "中华人民共和国国家计量检定规程", admin: "中华人民共和国国家质量监督检验检疫总局" },
|
87
|
-
}.freeze
|
88
|
-
|
89
|
-
LOCAL = {
|
90
|
-
"11": "北京市",
|
91
|
-
"12": "天津市",
|
92
|
-
"13": "河北省",
|
93
|
-
"14": "山西省",
|
94
|
-
"15": "内蒙古自治区",
|
95
|
-
"21": "辽宁省",
|
96
|
-
"22": "吉林省",
|
97
|
-
"23": "黑龙江省",
|
98
|
-
"31": "上海市",
|
99
|
-
"32": "江苏省",
|
100
|
-
"33": "浙江省",
|
101
|
-
"34": "安徽省",
|
102
|
-
"35": "福建省",
|
103
|
-
"36": "江西省",
|
104
|
-
"37": "山东省",
|
105
|
-
"41": "河南省",
|
106
|
-
"42": "湖北省",
|
107
|
-
"43": "湖南省",
|
108
|
-
"44": "广东省",
|
109
|
-
"45": "广西壮族自治区",
|
110
|
-
"46": "海南省",
|
111
|
-
"50": "重庆市",
|
112
|
-
"51": "四川省",
|
113
|
-
"52": "贵州省",
|
114
|
-
"53": "云南省",
|
115
|
-
"54": "西藏自治区",
|
116
|
-
"61": "陕西省",
|
117
|
-
"62": "甘肃省",
|
118
|
-
"63": "青海省",
|
119
|
-
"64": "宁夏回族自治区",
|
120
|
-
"65": "新疆维吾尔自治区",
|
121
|
-
"71": "台湾省",
|
122
|
-
"81": "香港特别行政区",
|
123
|
-
"82": "澳门特别行政区",
|
124
|
-
}.freeze
|
125
|
-
|
126
|
-
def gb_mandate_suffix(prefix, mandate)
|
127
|
-
if prefix == "GB"
|
128
|
-
prefix += "/T" if mandate == "recommended"
|
129
|
-
prefix += "/Z" if mandate == "guide"
|
130
|
-
end
|
131
|
-
prefix
|
132
|
-
end
|
133
|
-
|
134
|
-
def mandate_suffix(prefix, mandate)
|
135
|
-
prefix += "/T" if mandate == "recommended"
|
136
|
-
prefix += "/Z" if mandate == "guide"
|
137
|
-
prefix
|
138
|
-
end
|
139
|
-
|
140
|
-
def standard_class(scope, prefix, mandate)
|
141
|
-
case scope
|
142
|
-
when "national"
|
143
|
-
NATIONAL&.dig(gb_mandate_suffix(prefix, mandate).to_sym,
|
144
|
-
:name) || "XXXX"
|
145
|
-
when "sector"
|
146
|
-
"中华人民共和国#{SECTOR&.dig(prefix.to_sym,
|
147
|
-
:industry) || 'XXXX'}行业标准"
|
148
|
-
when "local"
|
149
|
-
"#{LOCAL&.dig(prefix.to_sym) || 'XXXX'}地方标准"
|
150
|
-
when "enterprise" then "ENTERPRISE STANDARD" # TODO
|
151
|
-
when "professional" then "PROFESSIONAL STANDARD" # TODO
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def standard_agency(scope, prefix, mandate)
|
156
|
-
case scope
|
157
|
-
when "national"
|
158
|
-
NATIONAL&.dig(gb_mandate_suffix(prefix, mandate).to_sym,
|
159
|
-
:admin) || "XXXX"
|
160
|
-
when "sector"
|
161
|
-
SECTOR&.dig(prefix.to_sym, :admin) || "XXXX"
|
162
|
-
when "local"
|
163
|
-
"#{LOCAL&.dig(prefix.to_sym) || 'XXXX'}质量技术检测局"
|
164
|
-
when "enterprise" then "ENTERPRISE STANDARD" # TODO
|
165
|
-
when "professional" then "PROFESSIONAL STANDARD" # TODO
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def gbtype_validate(root)
|
170
|
-
scope = root.at("//gbscope")&.text
|
171
|
-
prefix = root.at("//gbprefix")&.text
|
172
|
-
case scope
|
173
|
-
when "national"
|
174
|
-
NATIONAL.has_key?(prefix.to_sym) ||
|
175
|
-
warn("GB: #{prefix} is not a recognised national prefix")
|
176
|
-
when "sector"
|
177
|
-
SECTOR.has_key?(prefix.to_sym) ||
|
178
|
-
warn("GB: #{prefix} is not a recognised sector prefix")
|
179
|
-
when "local"
|
180
|
-
LOCAL.has_key?(prefix.to_sym) ||
|
181
|
-
warn("GB: #{prefix} is not a recognised local prefix")
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require "isodoc"
|
2
|
-
require_relative "./xref_gen.rb"
|
3
|
-
require_relative "./metadata.rb"
|
4
|
-
require_relative "./agencies.rb"
|
5
|
-
require_relative "./section_output.rb"
|
6
|
-
|
7
|
-
module Asciidoctor
|
8
|
-
module Gb
|
9
|
-
# A {Converter} implementation that generates GB output, and a document
|
10
|
-
# schema encapsulation of the document for validation
|
11
|
-
class GbConvert < IsoDoc::Convert
|
12
|
-
def initialize(options)
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
def error_parse(node, out)
|
17
|
-
# catch elements not defined in ISO
|
18
|
-
case node.name
|
19
|
-
when "string" then string_parse(node, out)
|
20
|
-
else
|
21
|
-
super
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def string_parse(node, out)
|
26
|
-
if node["script"] == "Hant"
|
27
|
-
out.span **{ class: "Hant" } do |s|
|
28
|
-
node.children.each { |c| parse(c, s) }
|
29
|
-
end
|
30
|
-
else
|
31
|
-
node.children.each { |c| parse(c, out) }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def fileloc(loc)
|
36
|
-
File.join(File.dirname(__FILE__), loc)
|
37
|
-
end
|
38
|
-
|
39
|
-
def generate_header(filename, dir)
|
40
|
-
super
|
41
|
-
system "cp #{fileloc(File.join('html', 'blank.png'))} blank.png"
|
42
|
-
end
|
43
|
-
|
44
|
-
def cleanup(docxml)
|
45
|
-
super
|
46
|
-
# intro_cleanup(docxml)
|
47
|
-
terms_cleanup(docxml)
|
48
|
-
end
|
49
|
-
|
50
|
-
def term_merge(docxml, term_class)
|
51
|
-
docxml.xpath("//p[@class = '#{term_class}']").each do |t|
|
52
|
-
t1 = t.next_element || next
|
53
|
-
if t1.name == "p" && t1["class"] == term_class
|
54
|
-
t.add_child(" ")
|
55
|
-
t.add_child(t1.remove.children)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def terms_cleanup(docxml)
|
61
|
-
term_merge(docxml, "Terms")
|
62
|
-
term_merge(docxml, "AltTerms")
|
63
|
-
term_merge(docxml, "DeprecatedTerms")
|
64
|
-
docxml
|
65
|
-
end
|
66
|
-
|
67
|
-
def intro_cleanup(docxml)
|
68
|
-
# insert tab for purposes of ToC lining up
|
69
|
-
docxml.xpath("//h1[@class = 'IntroTitle']").each do |h1|
|
70
|
-
if h1.content == "引言"
|
71
|
-
h1.add_child('<span style="mso-tab-count:1">  </span>')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def toWord(result, filename, dir)
|
77
|
-
result = from_xhtml(word_cleanup(to_xhtml(result)))
|
78
|
-
result = populate_template(result, :word)
|
79
|
-
Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet,
|
80
|
-
header_file: "header.html", dir: dir,
|
81
|
-
asciimathdelims: [@openmathdelim, @closemathdelim],
|
82
|
-
liststyles: {ul: "l7", ol: "l10"})
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,186 +0,0 @@
|
|
1
|
-
require "isodoc"
|
2
|
-
|
3
|
-
module Asciidoctor
|
4
|
-
module Gb
|
5
|
-
# A {Converter} implementation that generates GB output, and a document
|
6
|
-
# schema encapsulation of the document for validation
|
7
|
-
class GbConvert < IsoDoc::Convert
|
8
|
-
def init_metadata
|
9
|
-
super
|
10
|
-
set_metadata(:docmaintitlezh, "")
|
11
|
-
set_metadata(:docsubtitlezh, "XXXX")
|
12
|
-
set_metadata(:docparttitlezh, "")
|
13
|
-
set_metadata(:docmaintitleen, "")
|
14
|
-
set_metadata(:docsubtitleen, "XXXX")
|
15
|
-
set_metadata(:docparttitleen, "")
|
16
|
-
set_metadata(:gbequivalence, "")
|
17
|
-
set_metadata(:isostandard, nil)
|
18
|
-
set_metadata(:isostandardtitle, "")
|
19
|
-
set_metadata(:doctitle, "XXXX")
|
20
|
-
set_metadata(:obsoletes, nil)
|
21
|
-
set_metadata(:obsoletes_part, nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
def title(isoxml, _out)
|
25
|
-
intro = isoxml.at(ns("//title-intro[@language='zh']"))
|
26
|
-
main = isoxml.at(ns("//title-main[@language='zh']"))
|
27
|
-
part = isoxml.at(ns("//title-part[@language='zh']"))
|
28
|
-
partnumber = isoxml.at(ns("//project-number/@part"))
|
29
|
-
intro.nil? || set_metadata(:docmaintitlezh, intro.text + "—")
|
30
|
-
main.nil? || set_metadata(:docsubtitlezh, main.text)
|
31
|
-
partnum = partnumber ? "#{part_label(partnumber, 'zh')}: " : ""
|
32
|
-
part.nil? || set_metadata(:docparttitlezh,
|
33
|
-
"—#{partnum} #{part.text}")
|
34
|
-
set_metadata(:doctitle, get_metadata[:docmaintitlezh] +
|
35
|
-
get_metadata[:docsubtitlezh] +
|
36
|
-
get_metadata[:docparttitlezh])
|
37
|
-
end
|
38
|
-
|
39
|
-
def subtitle(isoxml, _out)
|
40
|
-
intro = isoxml.at(ns("//title-intro[@language='en']"))
|
41
|
-
main = isoxml.at(ns("//title-main[@language='en']"))
|
42
|
-
part = isoxml.at(ns("//title-part[@language='en']"))
|
43
|
-
partnumber = isoxml.at(ns("//project-number/@part"))
|
44
|
-
intro.nil? || set_metadata(:docmaintitleen, intro.text + "—")
|
45
|
-
main.nil? || set_metadata(:docsubtitleen, main.text)
|
46
|
-
partnum = partnumber ? "#{part_label(partnumber, 'en')}: " : ""
|
47
|
-
part.nil? || set_metadata(:docparttitleen,
|
48
|
-
"—#{partnum} #{part.text}")
|
49
|
-
end
|
50
|
-
|
51
|
-
def author(isoxml, _out)
|
52
|
-
gbcommittee = isoxml.at(ns("//bibdata/gbcommittee"))
|
53
|
-
set_metadata(:committee, gbcommittee.text)
|
54
|
-
end
|
55
|
-
|
56
|
-
def id(isoxml, _out)
|
57
|
-
super
|
58
|
-
gb_identifier(isoxml)
|
59
|
-
gb_library_identifier(isoxml)
|
60
|
-
gb_equivalence(isoxml)
|
61
|
-
end
|
62
|
-
|
63
|
-
ISO_STD_XPATH = "//bibdata/relation[@type = 'equivalent' or "\
|
64
|
-
"@type = 'identical' or @type = 'nonequivalent']/bibitem".freeze
|
65
|
-
|
66
|
-
def gb_equivalence(isoxml)
|
67
|
-
isostdid = isoxml.at(ns("#{ISO_STD_XPATH}/docidentifier")) || return
|
68
|
-
set_metadata(:isostandard, isostdid.text)
|
69
|
-
isostdtitle = isoxml.at(ns("#{ISO_STD_XPATH}/title"))
|
70
|
-
set_metadata(:isostandardtitle, isostdtitle.text) if isostdtitle
|
71
|
-
eq = isoxml.at(ns("//bibdata/relation/@type"))
|
72
|
-
case eq.text
|
73
|
-
when "equivalent" then set_metadata(:gbequivalence, "MOD")
|
74
|
-
when "nonequivalent" then set_metadata(:gbequivalence, "NEQ")
|
75
|
-
when "identical" then set_metadata(:gbequivalence, "IDT")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def docidentifier(gbscope, gbprefix, gbmandate)
|
80
|
-
docnum = get_metadata[:docnumber]
|
81
|
-
dn = if gbscope == "local"
|
82
|
-
"DB#{mandate_suffix(gbprefix, gbmandate)}/#{docnum}".
|
83
|
-
gsub(%r{/([TZ])/}, "/\\1 ")
|
84
|
-
else
|
85
|
-
"#{mandate_suffix(gbprefix, gbmandate)} #{docnum}"
|
86
|
-
end
|
87
|
-
set_metadata(:docidentifier, dn)
|
88
|
-
end
|
89
|
-
|
90
|
-
def gb_identifier(isoxml)
|
91
|
-
scope = isoxml.at(ns("//gbscope"))&.text || "national"
|
92
|
-
mandate = isoxml.at(ns("//gbmandate"))&.text || "mandatory"
|
93
|
-
prefix = isoxml.at(ns("//gbprefix"))&.text || "XXX"
|
94
|
-
docidentifier(scope, prefix, mandate)
|
95
|
-
set_metadata(:standard_class, standard_class(scope, prefix, mandate))
|
96
|
-
set_metadata(:standard_agency, standard_agency(scope, prefix, mandate))
|
97
|
-
set_metadata(:gbprefix, scope == "local" ? "DB" : prefix)
|
98
|
-
end
|
99
|
-
|
100
|
-
def standard_logo(gbprefix)
|
101
|
-
case gbprefix.downcase
|
102
|
-
when "db" then "gb-standard-db"
|
103
|
-
when "gb" then "gb-standard-gb"
|
104
|
-
when "gjb" then "gb-standard-gjb"
|
105
|
-
when "gm" then "gb-standard-gm"
|
106
|
-
when "jjf" then "gb-standard-jjf"
|
107
|
-
when "zb" then "gb-standard-zb"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def gb_library_identifier(isoxml)
|
112
|
-
ics = isoxml.at(ns("//gblibraryids/ics"))
|
113
|
-
l = isoxml.at(ns("//gblibraryids/l"))
|
114
|
-
set_metadata(:libraryid_ics, ics ? ics.text : "XXX")
|
115
|
-
set_metadata(:libraryid_l, l ? l.text : "XXX")
|
116
|
-
end
|
117
|
-
|
118
|
-
def part_label(partnumber, lang)
|
119
|
-
case lang
|
120
|
-
when "en" then "Part #{partnumber}"
|
121
|
-
when "zh" then "第#{partnumber}部"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def format_logo(prefix, _format)
|
126
|
-
logo = standard_logo(prefix)
|
127
|
-
if logo.nil?
|
128
|
-
"<span style='font-size:36pt;font-weight:bold'>#{prefix}</span>"
|
129
|
-
else
|
130
|
-
logo += ".gif"
|
131
|
-
system "cp #{fileloc(File.join('html/gb-logos', logo))} #{logo}"
|
132
|
-
"<img width='113' height='56' src='#{logo}' alt='#{prefix}'>"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def format_agency(agency, format)
|
137
|
-
return agency unless agency.is_a?(Array)
|
138
|
-
ret = "<table><tr><td>#{agency[0]}</td>"\
|
139
|
-
"<td rowspan='#{agency.size}'>发布</td></tr>"
|
140
|
-
agency[1..-1].each { |a| ret += "<tr><td>#{a}</td></tr>" }
|
141
|
-
ret += "</table>"
|
142
|
-
ret.gsub!(/<table>/, "<table width='100%'>") if format == :word
|
143
|
-
ret
|
144
|
-
end
|
145
|
-
|
146
|
-
def termref_render(x)
|
147
|
-
parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m)
|
148
|
-
parts[1] = ",定义" if parts.size > 1 && parts[1] == ","
|
149
|
-
parts.map do |p|
|
150
|
-
/\s*\[MODIFICATION\]/.match?(p) ? ", 改写 — " : p
|
151
|
-
end.join.sub(/\A\s*/m, "【").sub(/\s*\z/m, "】")
|
152
|
-
end
|
153
|
-
|
154
|
-
def termref_resolve(docxml)
|
155
|
-
docxml.split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4).
|
156
|
-
map do |a|
|
157
|
-
a.size < 3 ? a[0] : a[0] + termref_render(a[2])
|
158
|
-
end.join
|
159
|
-
end
|
160
|
-
|
161
|
-
def populate_template(docxml, format)
|
162
|
-
meta = get_metadata
|
163
|
-
logo = format_logo(meta[:gbprefix], format)
|
164
|
-
docxml = termref_resolve(docxml)
|
165
|
-
docxml.gsub!(/\s*\[ISOSECTION\]/, ", ?~Z?~I")
|
166
|
-
meta[:standard_agency_formatted] =
|
167
|
-
format_agency(meta[:standard_agency], format)
|
168
|
-
meta[:standard_logo] = logo
|
169
|
-
template = Liquid::Template.parse(docxml)
|
170
|
-
template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
|
171
|
-
end
|
172
|
-
|
173
|
-
STAGE_ABBRS = {
|
174
|
-
"00": "PWI",
|
175
|
-
"10": "NWIP",
|
176
|
-
"20": "WD",
|
177
|
-
"30": "CD",
|
178
|
-
"40": "DIS",
|
179
|
-
"50": "FDIS",
|
180
|
-
"60": "IS",
|
181
|
-
"90": "(Review)",
|
182
|
-
"95": "(Withdrawal)",
|
183
|
-
}.freeze
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|