Class: IsoDoc::Gb::Convert
- Inherits:
-
Convert
- Object
- Convert
- IsoDoc::Gb::Convert
- Defined in:
- lib/isodoc/gb/metadata.rb,
lib/isodoc/gb/i18n.rb,
lib/isodoc/gb/agencies.rb,
lib/isodoc/gb/gbcleanup.rb,
lib/isodoc/gb/gbconvert.rb,
lib/isodoc/gb/section_output.rb
Overview
A Converter implementation that generates GB output, and a document schema encapsulation of the document for validation
Direct Known Subclasses
Constant Summary collapse
- SECTOR =
{ "zh" => { AQ: { industry: "安全生产", admin: "国家安全生产管理局" }, BB: { industry: "包装", admin: "国家发改委" }, CB: { industry: "船舶", admin: "国防科学工业委员会" }, CH: { industry: "测绘", admin: "国家测绘局" }, CJ: { industry: "城镇建设", admin: "建设部" }, CY: { industry: "新闻出版", admin: "国家新闻出版总署" }, DA: { industry: "档案", admin: "国家档案局" }, DB: { industry: "地震", admin: "中国地震局" }, DL: { industry: "电力", admin: "国家发改委" }, DZ: { industry: "地质矿产", admin: "国土资源部" }, EJ: { industry: "核工业", admin: "国防科学工业委员会" }, FZ: { industry: "纺织", admin: "国家发改委" }, GA: { industry: "公共安全", admin: "公安部" }, GH: { industry: "供销", admin: "中华全国供销合作总社" }, GM: { industry: "密码", admin: "国家密码管理局" }, GY: { industry: "广播电影电视", admin: "国家广播电影电视总局" }, HB: { industry: "航空", admin: "国防科学工业委员会" }, HG: { industry: "化工", admin: "国家发改委" }, HJ: { industry: "环境保护", admin: "国家环境保护总局" }, HS: { industry: "海关", admin: "海关总署" }, HY: { industry: "海洋", admin: "国家海洋局" }, JB: { industry: "机械", admin: "国家发改委" }, JC: { industry: "建材", admin: "国家发改委" }, JG: { industry: "建筑工业", admin: "建设部" }, JR: { industry: "金融", admin: "中国人民银行" }, JT: { industry: "交通", admin: "交通部" }, JY: { industry: "教育", admin: "教育部" }, LB: { industry: "旅游", admin: "国家旅游局" }, LD: { industry: "劳动和劳动安全", admin: "劳动和社会保障部" }, LS: { industry: "粮食", admin: "国家粮食局" }, LY: { industry: "林业", admin: "国家林业局" }, MH: { industry: "民用航空", admin: "中国民航管理总局" }, MT: { industry: "煤炭", admin: "国家发改委" }, MZ: { industry: "民政", admin: "民政部" }, NY: { industry: "农业", admin: "农业部" }, QB: { industry: "轻工", admin: "国家发改委" }, QC: { industry: "汽车", admin: "国家发改委" }, QJ: { industry: "航天", admin: "国防科学工业委员会" }, QX: { industry: "气象", admin: "中国气象局" }, SB: { industry: "国内贸易", admin: "商务部" }, SC: { industry: "水产", admin: "农业部" }, SH: { industry: "石油化工", admin: "国家发改委" }, SJ: { industry: "电子", admin: "信息产业部" }, SL: { industry: "水利", admin: "水利部" }, SN: { industry: "商检", admin: "国家质量监督检验检疫总局" }, SY: { industry: "石油天然气", admin: "国家发改委" }, TB: { industry: "铁道", admin: "铁道部" }, TD: { industry: "土地管理", admin: "国土资源部" }, TJ: { industry: "铁道交通", admin: "铁道部标准所" }, TY: { industry: "体育", admin: "国家体育总局" }, WB: { industry: "物资管理", admin: "国家发改委" }, WH: { industry: "文化", admin: "文化部" }, WJ: { industry: "兵工民品", admin: "国防科学工业委员会" }, WM: { industry: "外经贸", admin: "外经贸部科技司" }, WS: { industry: "卫生", admin: "卫生部" }, WW: { industry: "文物保护", admin: "国家文物局" }, XB: { industry: "稀土", admin: "国家发改委稀土办公室" }, YB: { industry: "黑色冶金", admin: "国家发改委" }, YC: { industry: "烟草", admin: "国家烟草专卖局" }, YD: { industry: "通信", admin: "信息产业部" }, YS: { industry: "有色冶金", admin: "国家发改委" }, YY: { industry: "医药", admin: "国家食品药品监督管理局" }, YZ: { industry: "邮政", admin: "国家邮政局" }, ZY: { industry: "中医药", admin: "国家中医药管理局" }, }, "en" => { AQ: { industry: "Production Safety", admin: "State Administration of Work Safety" }, BB: { industry: "Packaging", admin: "China National Packaging Industry Corporation" }, CB: { industry: "Ships", admin: "National Defense Commission" }, CH: { industry: "Surveying and Mapping", admin: "National Bureau of Surveying and Mapping" }, CJ: { industry: "Town Construction", admin: "Ministry of Construction" }, CY: { industry: "News Publishing", admin: "State Press and Publication Administration" }, DA: { industry: "Archiving", admin: "National Archival Bureau" }, DB: { industry: "Seismology", admin: "National Seismological Bureau" }, DL: { industry: "Electricity", admin: "State Economic and Trade Commission" }, DZ: { industry: "Geological and Mineral Products", admin: "Ministry of Land and Resources" }, EJ: { industry: "Nuclear Industry", admin: "National Defense Commission" }, FZ: { industry: "Textile", admin: "State Economic and Trade Commission" }, GA: { industry: "Public Safety", admin: "Ministry of Public Security" }, GH: { industry: "Supply and Marketing", admin: "China Federation of Supply and Marketing Cooperatives" }, GM: { industry: "Cryptography", admin: "State Administration Of Cryptography" }, GY: { industry: "Radio, Film and Television", admin: "State Administration of Radio, Film and Television" }, HB: { industry: "Aviation", admin: "National Defense Commission" }, HG: { industry: "Chemical Industry", admin: "State Economic and Trade Commission" }, HJ: { industry: "Environmental Protection", admin: "State Environmental Protection Administration" }, HS: { industry: "Customs", admin: "General Administration of Customs" }, HY: { industry: "Oceanography", admin: "State Oceanic Administration" }, JB: { industry: "Mechanical Engineering", admin: "State Economic and Trade Commission" }, JC: { industry: "Building Materials", admin: "State Economic and Trade Commission" }, JG: { industry: "Construction Industry", admin: "Ministry of Construction" }, JR: { industry: "Financial", admin: "People’s Bank of China" }, JT: { industry: "Traffic", admin: "Ministry of Communications" }, JY: { industry: "Education", admin: "Ministry of Education" }, LB: { industry: "Tourism", admin: "National Tourism Bureau" }, LD: { industry: "Labor and Work Safety", admin: "Ministry of Labor and Social Security" }, LS: { industry: "Food", admin: "National Food Administration" }, LY: { industry: "Forestry", admin: "State Forestry Administration" }, MH: { industry: "Civil Aviation", admin: "Civil Aviation Administration" }, MT: { industry: "Coal", admin: "State Economic and Trade Commission" }, MZ: { industry: "Civil Affairs", admin: "Ministry of Civil Affairs" }, NY: { industry: "Agriculture", admin: "Ministry of Agriculture" }, QB: { industry: "Light Industry", admin: "State Economic and Trade Commission" }, QC: { industry: "Automotive", admin: "State Economic and Trade Commission" }, QJ: { industry: "Aerospace", admin: "National Defense Commission" }, QX: { industry: "Meteorological", admin: "China Meteorological Administration" }, SB: { industry: "Domestic Business", admin: "Ministry of Commerce" }, SC: { industry: "Aquatic Products", admin: "Ministry of Agriculture" }, SH: { industry: "Petrochemical", admin: "State Economic and Trade Commission" }, SJ: { industry: "Electronics", admin: "Ministry of Information Industry" }, SL: { industry: "Water Resources", admin: "Ministry of Water Resources" }, SN: { industry: "Inspection", admin: "General Administration of Quality Supervision, Inspection and Quarantine" }, SY: { industry: "Natural Gas", admin: "State Economic and Trade Commission" }, TB: { industry: "Rail Transport", admin: "Ministry of Railways" }, TD: { industry: "Land Management", admin: "Ministry of Land and Resources" }, TJ: { industry: "Railway Traffic", admin: "Ministry of Railways Standards" }, TY: { industry: "Sports", admin: "National Department of Sport" }, WB: { industry: "Materials Management", admin: "State Economic and Trade Commission" }, WH: { industry: "Culture", admin: "Ministry of Culture" }, WJ: { industry: "Ordnance", admin: "National Defense Commission" }, WM: { industry: "Foreign Trade", admin: "Ministry of Foreign Trade and Economic Cooperation" }, WS: { industry: "Health", admin: "Ministry of Health" }, WW: { industry: "Cultural Relics Protection", admin: "National Heritage Board" }, XB: { industry: "Rare Earths", admin: "State Planning Commission Rare Earths Office" }, YB: { industry: "Ferrous Metallurgy", admin: "State Economic and Trade Commission" }, YC: { industry: "Tobacco", admin: "State Tobacco Monopoly Bureau" }, YD: { industry: "Communication", admin: "Ministry of Information Industry" }, YS: { industry: "Non-Ferrous Metallurgy", admin: "State Economic and Trade Commission" }, YY: { industry: "Medicine", admin: "State Food and Drug Administration" }, YZ: { industry: "Postal", admin: "State Post Office" }, ZY: { industry: "Chinese Medicine", admin: "State Administration of Traditional Chinese Medicine" }, } }.freeze
- NATIONAL =
{ "zh" => { GB: { name: "中华人民共和国国家标准", admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] }, "GB/T": { name: "中华人民共和国国家标准", admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] }, "GB/Z": { name: "中华人民共和国国家标准化指导性技术文件", admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] }, GBZ: { name: "中华人民共和国国家职业卫生标准", admin: "中华人民共和国卫生部" }, GJB: { name: "中华人民共和国国家军用标准", admin: "中国人民解放军装备总部" }, GBn: { name: "中华人民共和国国家内部标准", admin: "" }, GHZB: { name: "中华人民共和国国家环境质量标准", admin: "" }, GWKB: { name: "中华人民共和国国家环境保护标准", admin: "环境保护部" }, GWPB: { name: "中华人民共和国国家污染物排放标准", admin: "" }, JJF: { name: "中华人民共和国国家计量技术规范", admin: "中华人民共和国国家质量监督检验检疫总局" }, JJG: { name: "中华人民共和国国家计量检定规程", admin: "中华人民共和国国家质量监督检验检疫总局" }, }, "en" => { GB: { name: "National standard", admin: "General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China" }, "GB/T": { name: "National standard (Recommended)", admin: "General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China" }, "GB/Z": { name: "Standardized guidelines", admin: "General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China" }, GBZ: { name: "National occupational health standards", admin: "Ministry of Health" }, GJB: { name: "National military standards", admin: "Chinese People’s Liberation Army Equipment Headquarters" }, GBn: { name: "National internal standards", admin: "" }, GHZB: { name: "National environmental quality standards", admin: "" }, GWKB: { name: "National Environmental Protection Standards", admin: "Ministry of Environmental Protection" }, GWPB: { name: "National pollutant discharge standards", admin: "" }, JJF: { name: "National calibration specifications", admin: "General Administration of Quality Supervision, Inspection and Quarantine" }, JJG: { name: "National calibration verification regulations", admin: "General Administration of Quality Supervision, Inspection and Quarantine" }, } }.freeze
- LOCAL =
{ "zh" => { "11": "北京市", "12": "天津市", "13": "河北省", "14": "山西省", "15": "内蒙古自治区", "21": "辽宁省", "22": "吉林省", "23": "黑龙江省", "31": "上海市", "32": "江苏省", "33": "浙江省", "34": "安徽省", "35": "福建省", "36": "江西省", "37": "山东省", "41": "河南省", "42": "湖北省", "43": "湖南省", "44": "广东省", "45": "广西壮族自治区", "46": "海南省", "50": "重庆市", "51": "四川省", "52": "贵州省", "53": "云南省", "54": "西藏自治区", "61": "陕西省", "62": "甘肃省", "63": "青海省", "64": "宁夏回族自治区", "65": "新疆维吾尔自治区", "71": "台湾省", "81": "香港特别行政区", "82": "澳门特别行政区", }, "en" => { "11": "Beijing City", "12": "Tianjin", "13": "Hebei Province", "14": "Shanxi Province", "15": "Inner Mongolia Autonomous Region", "21": "Liaoning Province", "22": "Jilin Province", "23": "Heilongjiang Province", "31": "Shanghai", "32": "Jiangsu Province", "33": "Zhejiang Province", "34": "Anhui Province", "35": "Fujian Province", "36": "Jiangxi Province", "37": "Shandong Province", "41": "Henan Province", "42": "Hubei Province", "43": "Hunan Province", "44": "Guangdong Province", "45": "Guangxi Zhuang Autonomous Region", "46": "Hainan", "50": "Chongqing", "51": "Sichuan Province", "52": "Guizhou Province", "53": "Yunnan Province", "54": "Tibet Autonomous Region", "61": "Shaanxi Province", "62": "Gansu Province", "63": "Qinghai Province", "64": "Ningxia Hui Autonomous Region", "65": "Xinjiang Uygur Autonomous Region", "71": "Taiwan Province", "81": "Hong Kong Special Administrative Region", "82": "Macao Special Administrative Region", } }.freeze
- STAGE_ABBRS_CN =
{ "00": "新工作项目建议", "10": "新工作项目", "20": "标准草案工作组讨论稿", "30": "标准草案征求意见稿", "40": "标准草案送审稿", "50": "标准草案报批稿", "60": "国家标准", "90": "(Review)", "95": "(Withdrawal)", }.freeze
- ISO_STD_XPATH =
"//bibdata/relation[@type = 'equivalent' or "\ "@type = 'identical' or @type = 'nonequivalent']/bibitem".freeze
- SCOPEPFX =
{ local: "DB", social: "T", enterprise: "Q", }.freeze
Instance Method Summary collapse
- #annex_name(annex, name, div) ⇒ Object
- #author(isoxml, _out) ⇒ Object
- #bibdate(isoxml, _out) ⇒ Object
- #clause_name(num, title, div, header_class) ⇒ Object
- #clause_parse_title(node, div, c1, out) ⇒ Object
- #cleanup(docxml) ⇒ Object
- #default_fonts(options) ⇒ Object
- #deprecated_single_label(docxml) ⇒ Object
- #deprecated_term_parse(node, out) ⇒ Object
- #docid(isoxml, _out) ⇒ Object
- #docid1(isoxml, _out) ⇒ Object
- #docidentifier(scope, prefix, mandate, docyear) ⇒ Object
- #docstatus(isoxml, _out) ⇒ Object
- #end_line(_isoxml, out) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #example_cleanup(docxml) ⇒ Object
- #fileloc(loc) ⇒ Object
-
#foreword(isoxml, out) ⇒ Object
putting in tab so that ToC aligns.
- #format_agency(agency, format) ⇒ Object
- #format_agency1(agency, format) ⇒ Object
- #format_logo(prefix, scope, _format) ⇒ Object
- #format_logo1(logo, prefix, scope) ⇒ Object
- #formula_cleanup(docxml) ⇒ Object
- #gb_equivalence(isoxml) ⇒ Object
- #gb_identifier(isoxml) ⇒ Object
- #gb_library_identifier(isoxml) ⇒ Object
- #gb_mandate_suffix(prefix, mandate) ⇒ Object
- #gbtype_validate(root) ⇒ Object
- #html_doc_path(file) ⇒ Object
- #i18n_init(lang, script) ⇒ Object
- #init_metadata ⇒ Object
-
#initialize(options) ⇒ Convert
constructor
A new instance of Convert.
- #local_logo_suffix(scope) ⇒ Object
- #mandate_suffix(prefix, mandate) ⇒ Object
- #middle(isoxml, out) ⇒ Object
- #part_label(partnumber, lang) ⇒ Object
- #populate_template(docxml, format) ⇒ Object
- #set_doctitle ⇒ Object
- #spaerdruck(x, return_on_br) ⇒ Object
- #stage_abbrev_cn(stage, iter, draft) ⇒ Object
- #standard_agency(scope, prefix, mandate) ⇒ Object
- #standard_agency1(scope, prefix, mandate) ⇒ Object
- #standard_class(scope, prefix, mandate) ⇒ Object
- #standard_logo(gbprefix) ⇒ Object
- #string_parse(node, out) ⇒ Object
- #subtitle(isoxml, _out) ⇒ Object
- #term_defs_boilerplate(div, source, term) ⇒ Object
- #term_merge(docxml, term_class) ⇒ Object
- #termref_render(x) ⇒ Object
- #termref_resolve(docxml) ⇒ Object
- #terms_cleanup(docxml) ⇒ Object
- #title(isoxml, _out) ⇒ Object
- #title_cleanup(docxml) ⇒ Object
Constructor Details
#initialize(options) ⇒ Convert
Returns a new instance of Convert.
31 32 33 34 35 36 37 38 |
# File 'lib/isodoc/gb/gbconvert.rb', line 31 def initialize() super @htmlstylesheet = generate_css(html_doc_path("htmlstyle.scss"), true, default_fonts()) @standardstylesheet = generate_css(html_doc_path("gb.scss"), true, default_fonts()) @htmlcoverpage = html_doc_path("html_gb_titlepage.html") @htmlintropage = html_doc_path("html_gb_intro.html") @scripts = html_doc_path("scripts.html") end |
Instance Method Details
#annex_name(annex, name, div) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/isodoc/gb/section_output.rb', line 40 def annex_name(annex, name, div) div.h1 **{ class: "Annex" } do |t| t << "#{get_anchors[annex['id']][:label]}<br/><br/>" t << name.text end end |
#author(isoxml, _out) ⇒ Object
62 63 64 65 |
# File 'lib/isodoc/gb/metadata.rb', line 62 def (isoxml, _out) gbcommittee = isoxml.at(ns("//bibdata/gbcommittee")) (:committee, gbcommittee&.text) end |
#bibdate(isoxml, _out) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/isodoc/gb/metadata.rb', line 198 def bibdate(isoxml, _out) super m = if @lang == "zh" (:labelled_publisheddate, m[:publisheddate] + " " + @labels["publicationdate_lbl"]) (:labelled_implementeddate, m[:implementeddate] + " " + @labels["implementationdate_lbl"]) else (:labelled_publisheddate, @labels["publicationdate_lbl"] + ": " + m[:publisheddate]) (:labelled_implementeddate, @labels["implementationdate_lbl"] + ": " + m[:implementeddate]) end end |
#clause_name(num, title, div, header_class) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/isodoc/gb/section_output.rb', line 17 def clause_name(num, title, div, header_class) header_class = {} if header_class.nil? div.h1 **attr_code(header_class) do |h1| if num h1 << num h1 << " " end h1 << title end div.parent.at(".//h1") end |
#clause_parse_title(node, div, c1, out) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/isodoc/gb/section_output.rb', line 29 def clause_parse_title(node, div, c1, out) if node["inline-header"] == "true" inline_header_title(out, node, c1) else div.send "h#{get_anchors[node['id']][:level]}" do |h| h << "#{get_anchors[node['id']][:label]}. " c1.children.each { |c2| parse(c2, h) } end end end |
#cleanup(docxml) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 4 def cleanup(docxml) super terms_cleanup(docxml) formula_cleanup(docxml) title_cleanup(docxml) docxml end |
#default_fonts(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/isodoc/gb/gbconvert.rb', line 15 def default_fonts() script = [:script] || "Hans" b = [:bodyfont] || (script == "Hans" ? '"SimSun",serif' : script == "Latn" ? '"Cambria",serif' : '"SimSun",serif' ) h = [:headerfont] || (script == "Hans" ? '"SimHei",sans-serif' : script == "Latn" ? '"Calibri",sans-serif' : '"SimHei",sans-serif' ) m = [:monospacefont] || '"Courier New",monospace' scope = [:scope] || "national" t = [:titlefont] || (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) : (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' )) "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n" end |
#deprecated_single_label(docxml) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 58 def deprecated_single_label(docxml) docxml.xpath("//p[@class = 'DeprecatedTerms']").each do |d| t1 = d.previous_element next unless t1 && t1.name == "p" && t1["class"] == "DeprecatedTerms" d.children.first.content = d.children.first.content.sub(/^#{@deprecated_lbl}:\s*/, "") end end |
#deprecated_term_parse(node, out) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/isodoc/gb/gbconvert.rb', line 76 def deprecated_term_parse(node, out) out.p **{ class: "DeprecatedTerms" } do |p| p << l10n("#{@deprecated_lbl}: ") node.children.each { |c| parse(c, p) } end end |
#docid(isoxml, _out) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/isodoc/gb/metadata.rb', line 108 def docid(isoxml, _out) docid1(isoxml, _out) gb_identifier(isoxml) gb_library_identifier(isoxml) gb_equivalence(isoxml) end |
#docid1(isoxml, _out) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/isodoc/gb/metadata.rb', line 97 def docid1(isoxml, _out) dn = docnumber(isoxml) docstatus = [:stage] if docstatus abbr = stage_abbrev(docstatus.to_s, isoxml.at(ns("//status/iteration")), isoxml.at(ns("//version/draft"))) (docstatus.to_i < 60) && dn = abbr + " " + dn end (:docnumber, dn) end |
#docidentifier(scope, prefix, mandate, docyear) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/isodoc/gb/metadata.rb', line 137 def docidentifier(scope, prefix, mandate, docyear) docnum = [:docnumber] dn = case scope when "local" "#{SCOPEPFX[scope.to_sym]}#{mandate_suffix(prefix, mandate)}/"\ "#{docnum}".gsub(%r{/([TZ])/}, "/\\1 ") when "social", "enterprise" "#{mandate_suffix(SCOPEPFX[scope.to_sym], mandate)}/"\ "#{prefix} #{docnum}" else "#{mandate_suffix(prefix, mandate)} #{docnum}" end dn += "—#{docyear}" if docyear (:docidentifier, dn) end |
#docstatus(isoxml, _out) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/isodoc/gb/metadata.rb', line 87 def docstatus(isoxml, _out) docstatus = isoxml.at(ns("//status/stage")) if docstatus (:stage, docstatus.text.to_i) abbr = stage_abbrev_cn(docstatus.text, isoxml.at(ns("//status/iteration")), isoxml.at(ns("//version/draft"))) (:stageabbr, abbr) end end |
#end_line(_isoxml, out) ⇒ Object
49 50 51 |
# File 'lib/isodoc/gb/gbconvert.rb', line 49 def end_line(_isoxml, out) out.hr **{ width: "25%" } end |
#error_parse(node, out) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/gb/gbconvert.rb', line 53 def error_parse(node, out) # catch elements not defined in ISO case node.name when "string" then string_parse(node, out) else super end end |
#example_cleanup(docxml) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 19 def example_cleanup(docxml) super docxml.xpath("//table[@class = 'Note']//p[not(@class)]").each do |p| p["class"] = "Note" end docxml end |
#fileloc(loc) ⇒ Object
72 73 74 |
# File 'lib/isodoc/gb/gbconvert.rb', line 72 def fileloc(loc) File.join(File.dirname(__FILE__), loc) end |
#foreword(isoxml, out) ⇒ Object
putting in tab so that ToC aligns
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/isodoc/gb/section_output.rb', line 5 def foreword(isoxml, out) f = isoxml.at(ns("//foreword")) || return page_break(out) out.div do |s| s.h1 **{ class: "ForewordTitle" } do |h1| h1 << "#{@foreword_lbl} " # insert_tab(h1, 1) end f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#format_agency(agency, format) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/isodoc/gb/gbconvert.rb', line 108 def format_agency(agency, format) return agency unless agency.is_a?(Array) if agency == ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] logo = "gb-issuer-default.gif" system "cp #{fileloc(File.join('html/gb-logos', logo))} #{logo}" return "<img src='#{logo}' alt='#{agency.join(",")}'></img>" end format_agency1(agency, format) end |
#format_agency1(agency, format) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/isodoc/gb/gbconvert.rb', line 118 def format_agency1(agency, format) ret = "<table>" agency.each { |a| ret += "<tr><td>#{a}</td></tr>" } ret += "</table>" ret.gsub!(/<table>/, "<table width='100%'>") if format == :word ret end |
#format_logo(prefix, scope, _format) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/isodoc/gb/gbconvert.rb', line 89 def format_logo(prefix, scope, _format) return "" if %w(enterprise social).include? scope logo = standard_logo(prefix) if logo.nil? "<span style='font-size:36pt;font-weight:bold'>#{prefix}</span>" else format_logo1(logo, prefix, scope) end end |
#format_logo1(logo, prefix, scope) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/isodoc/gb/gbconvert.rb', line 99 def format_logo1(logo, prefix, scope) logo += ".gif" system "cp #{fileloc(File.join('html/gb-logos', logo))} #{logo}" local = local_logo_suffix(scope) @files_to_delete << logo "<img width='113' height='56' src='#{logo}' alt='#{prefix}'></img>"\ "#{local}" end |
#formula_cleanup(docxml) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 12 def formula_cleanup(docxml) docxml.xpath("//table[@class = 'dl']//p[not(@class)]").each do |p| p["class"] = "dl" end docxml end |
#gb_equivalence(isoxml) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/isodoc/gb/metadata.rb', line 118 def gb_equivalence(isoxml) isostdid = isoxml.at(ns("#{ISO_STD_XPATH}/docidentifier")) || return (:isostandard, isostdid.text) isostdtitle = isoxml.at(ns("#{ISO_STD_XPATH}/title")) (:isostandardtitle, isostdtitle.text) if isostdtitle eq = isoxml.at(ns("//bibdata/relation/@type")) case eq.text when "equivalent" then (:gbequivalence, "MOD") when "nonequivalent" then (:gbequivalence, "NEQ") when "identical" then (:gbequivalence, "IDT") end end |
#gb_identifier(isoxml) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/isodoc/gb/metadata.rb', line 153 def gb_identifier(isoxml) scope = isoxml.at(ns("//gbscope"))&.text || "national" mandate = isoxml.at(ns("//gbmandate"))&.text || "mandatory" prefix = isoxml.at(ns("//gbprefix"))&.text || "XXX" docyear = isoxml&.at(ns("//copyright/from"))&.text docidentifier(scope, prefix, mandate, docyear) issuer = isoxml&.at(ns("//bibdata/contributor[role/@type = 'issuer']/"\ "organization/name"))&.text || "GB" (:issuer, issuer) (:standard_class, standard_class(scope, prefix, mandate)) (:standard_agency, standard_agency(scope, prefix, mandate)) (:gbprefix, scope == "local" ? "DB" : prefix) (:gbscope, scope) end |
#gb_library_identifier(isoxml) ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/isodoc/gb/metadata.rb', line 180 def gb_library_identifier(isoxml) ics = [] ccs = [] isoxml.xpath(ns("//bibdata/ics")).each { |i| ics << i.text } isoxml.xpath(ns("//bibdata/ccs")).each { |i| ccs << i.text } p = isoxml.at(ns("//bibdata/plannumber")) (:libraryid_ics, ics.empty? ? "XXX" : ics.join(", ")) (:libraryid_ccs, ccs.empty? ? "XXX" : ccs.join(", ")) (:libraryid_plan, p ? p.text : "XXX") end |
#gb_mandate_suffix(prefix, mandate) ⇒ Object
248 249 250 251 252 253 254 |
# File 'lib/isodoc/gb/agencies.rb', line 248 def gb_mandate_suffix(prefix, mandate) if prefix == "GB" prefix += "/T" if mandate == "recommended" prefix += "/Z" if mandate == "guide" end prefix end |
#gbtype_validate(root) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/isodoc/gb/agencies.rb', line 310 def gbtype_validate(root) scope = root.at("//gbscope")&.text prefix = root.at("//gbprefix")&.text case scope when "national" NATIONAL.dig(@lang, prefix.to_sym) || warn("GB: #{prefix} is not a recognised national prefix") when "sector" SECTOR.dig(@lang, prefix.to_sym) || warn("GB: #{prefix} is not a recognised sector prefix") when "local" LOCAL.dig(@lang, prefix.to_sym) || warn("GB: #{prefix} is not a recognised local prefix") end end |
#html_doc_path(file) ⇒ Object
40 41 42 |
# File 'lib/isodoc/gb/gbconvert.rb', line 40 def html_doc_path(file) File.join(File.dirname(__FILE__), File.join("html", file)) end |
#i18n_init(lang, script) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/isodoc/gb/i18n.rb', line 6 def i18n_init(lang, script) super y = if lang == "en" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) elsif lang == "zh" && script == "Hans" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) else YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) end @labels = @labels.merge(y) end |
#init_metadata ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/isodoc/gb/metadata.rb', line 9 def super (:docmaintitlezh, "") (:docsubtitlezh, "XXXX") (:docparttitlezh, "") (:docmaintitleen, "") (:docsubtitleen, "XXXX") (:docparttitleen, "") (:gbequivalence, "") (:isostandard, nil) (:isostandardtitle, "") (:doctitle, "XXXX") (:obsoletes, nil) (:obsoletes_part, nil) end |
#local_logo_suffix(scope) ⇒ Object
83 84 85 86 87 |
# File 'lib/isodoc/gb/gbconvert.rb', line 83 def local_logo_suffix(scope) return "" if scope != "local" local = [:docidentifier][2,2] "<span style='font-weight:bold'>#{local}</span>" end |
#mandate_suffix(prefix, mandate) ⇒ Object
256 257 258 259 260 |
# File 'lib/isodoc/gb/agencies.rb', line 256 def mandate_suffix(prefix, mandate) prefix += "/T" if mandate == "recommended" prefix += "/Z" if mandate == "guide" prefix end |
#middle(isoxml, out) ⇒ Object
44 45 46 47 |
# File 'lib/isodoc/gb/gbconvert.rb', line 44 def middle(isoxml, out) super end_line(isoxml, out) end |
#part_label(partnumber, lang) ⇒ Object
191 192 193 194 195 196 |
# File 'lib/isodoc/gb/metadata.rb', line 191 def part_label(partnumber, lang) case lang when "en" then "Part #{partnumber}" when "zh" then "第#{partnumber}部分" end end |
#populate_template(docxml, format) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/isodoc/gb/gbconvert.rb', line 141 def populate_template(docxml, format) = .merge(@labels) logo = format_logo([:gbprefix], [:gbscope], format) docxml = termref_resolve(docxml) [:standard_agency_formatted] = format_agency([:standard_agency], format) [:standard_logo] = logo template = Liquid::Template.parse(docxml) template.render(.map { |k, v| [k.to_s, v] }.to_h) end |
#set_doctitle ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/isodoc/gb/metadata.rb', line 37 def set_doctitle if @lang == "zh" (:doctitle, [:docmaintitlezh] + [:docsubtitlezh] + [:docparttitlezh]) else (:doctitle, [:docmaintitleen] + [:docsubtitleen] + [:docparttitleen]) end end |
#spaerdruck(x, return_on_br) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 27 def spaerdruck(x, return_on_br) x.traverse do |n| n.text? and n.content = n.text.gsub(/(.)/, "\\1\u00a0\u00a0"). gsub(/\u00a0+$/, "") return_on_br and n.element? and n.name == "br" and return end end |
#stage_abbrev_cn(stage, iter, draft) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/isodoc/gb/metadata.rb', line 79 def stage_abbrev_cn(stage, iter, draft) return stage_abbrev(stage, iter, draft) if @lang != "zh" stage = STAGE_ABBRS_CN[stage.to_sym] || "??" stage = "#{iter.text.to_i.localize(:zh).spellout}次#{stage}" if iter stage = "Pre" + stage if draft&.text =~ /^0\./ stage end |
#standard_agency(scope, prefix, mandate) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/isodoc/gb/agencies.rb', line 295 def standard_agency(scope, prefix, mandate) case scope when "national" NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym, :admin) || nil when "sector" SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil when "local" "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{@labels["local_issuer"]}" when "enterprise", "social" [:issuer] when "professional" then "PROFESSIONAL STANDARD" # TODO end end |
#standard_agency1(scope, prefix, mandate) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/isodoc/gb/agencies.rb', line 280 def standard_agency1(scope, prefix, mandate) case scope when "national" NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym, :admin) || nil when "sector" SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil when "local" LOCAL&.dig(@lang, prefix.to_sym) || nil when "enterprise", "social" [:issuer] || nil when "professional" then "PROFESSIONAL STANDARD" # TODO end end |
#standard_class(scope, prefix, mandate) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/isodoc/gb/agencies.rb', line 262 def standard_class(scope, prefix, mandate) case scope when "national" NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym, :name) || "XXXX" when "sector" "#{@labels["PRC"]}#{SECTOR&.dig(@lang, prefix.to_sym, :industry) || 'XXXX'}#{@labels["industry_standard"]}" when "local" "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{@labels["local_standard"]}" when "enterprise" issuer = [:issuer] "#{issuer}#{@labels["enterprise_standard"]}" when "social" then @labels["social_standard"] when "professional" then "PROFESSIONAL STANDARD" # TODO end end |
#standard_logo(gbprefix) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/isodoc/gb/metadata.rb', line 168 def standard_logo(gbprefix) return nil unless gbprefix case gbprefix.downcase when "db" then "gb-standard-db" when "gb" then "gb-standard-gb" when "gjb" then "gb-standard-gjb" when "gm" then "gb-standard-gm" when "jjf" then "gb-standard-jjf" when "zb" then "gb-standard-zb" end end |
#string_parse(node, out) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/isodoc/gb/gbconvert.rb', line 62 def string_parse(node, out) if node["script"] == "Hant" out.span **{ class: "Hant" } do |s| node.children.each { |c| parse(c, s) } end else node.children.each { |c| parse(c, out) } end end |
#subtitle(isoxml, _out) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/gb/metadata.rb', line 49 def subtitle(isoxml, _out) intro = isoxml.at(ns("//title-intro[@language='en']")) main = isoxml.at(ns("//title-main[@language='en']")) part = isoxml.at(ns("//title-part[@language='en']")) partnumber = isoxml.at(ns("//project-number/@part")) intro.nil? || (:docmaintitleen, intro.text + "—") main.nil? || (:docsubtitleen, main.text) partnum = partnumber ? "#{part_label(partnumber, 'en')}: " : "" part.nil? || (:docparttitleen, "—#{partnum} #{part.text}") set_doctitle end |
#term_defs_boilerplate(div, source, term) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/isodoc/gb/section_output.rb', line 47 def term_defs_boilerplate(div, source, term) if source.empty? && term.nil? div << @no_terms_boilerplate else div << term_defs_boilerplate_cont(source, term) end end |
#term_merge(docxml, term_class) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 48 def term_merge(docxml, term_class) docxml.xpath("//p[@class = '#{term_class}']").each do |t| t1 = t.next_element || next if t1.name == "p" && t1["class"] == term_class t.add_child(" ") t.add_child(t1.remove.children) end end end |
#termref_render(x) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/isodoc/gb/gbconvert.rb', line 126 def termref_render(x) parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m) parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 && parts[1] == "," parts.map do |p| /\s*\[MODIFICATION\]/.match?(p) ? l10n(", #{@modified_lbl} — ") : p end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]")) end |
#termref_resolve(docxml) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/isodoc/gb/gbconvert.rb', line 134 def termref_resolve(docxml) docxml.split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4). map do |a| a.size < 3 ? a[0] : a[0] + termref_render(a[2]) end.join end |
#terms_cleanup(docxml) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 67 def terms_cleanup(docxml) term_merge(docxml, "Terms") term_merge(docxml, "AltTerms") deprecated_single_label(docxml) term_merge(docxml, "DeprecatedTerms") docxml end |
#title(isoxml, _out) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/isodoc/gb/metadata.rb', line 25 def title(isoxml, _out) intro = isoxml.at(ns("//title-intro[@language='zh']")) main = isoxml.at(ns("//title-main[@language='zh']")) part = isoxml.at(ns("//title-part[@language='zh']")) partnumber = isoxml.at(ns("//project-number/@part")) intro.nil? || (:docmaintitlezh, intro.text + " ") main.nil? || (:docsubtitlezh, main.text) partnum = partnumber ? "#{part_label(partnumber, 'zh')}:" : "" part.nil? || (:docparttitlezh, " #{partnum}#{part.text}") end |
#title_cleanup(docxml) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/isodoc/gb/gbcleanup.rb', line 35 def title_cleanup(docxml) @script == "Hans" or return docxml.xpath("//*[@class = 'zzContents' or @class = 'ForewordTitle' or "\ "@class = 'IntroTitle'] | "\ "//h1[@class = 'Sections3']").each do |x| spaerdruck(x, false) end docxml.xpath("//h1[@class = 'Annex']").each do |x| spaerdruck(x, true) end docxml end |