Class: Asciidoctor::Gb::Converter
- Inherits:
-
ISO::Converter
- Object
- ISO::Converter
- Asciidoctor::Gb::Converter
- Defined in:
- lib/asciidoctor/gb/converter.rb,
lib/asciidoctor/gb/front.rb,
lib/asciidoctor/gb/validate.rb,
lib/asciidoctor/gb/section_input.rb
Overview
A Converter implementation that generates GB output, and a document schema encapsulation of the document for validation
Constant Summary collapse
- ROMAN_TEXT =
/\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
- HAN_TEXT =
/\s*[\u4e00-\u9fff]+/
- LOCALISED_ELEMS =
"//admitted | //deprecates | //preferred | //prefix | "\ "//initial | //addition | //surname | //forename | //name | "\ "//abbreviation | //role/description | //affiliation/description | "\ "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\ "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\ "//bibdata/abstract | //bibitem/note ".freeze
- MUST_LOCALISE_ELEMS =
%w{admitted deprecates preferred}.freeze
- GBCODE =
"((AQ|BB|CB|CH|CJ|CY|DA|DB|DL|DZ|EJ|FZ|GA|GH|GM|GY|HB|HG|"\ "HJ|HS|HY|JB|JC|JG|JR|JT|JY|LB|LD|LS|LY|MH|MT|MZ|NY|QB|QC|QJ|"\ "QZ|SB|SC|SH|SJ|SN|SY|TB|TD|TJ|TY|WB|WH|WJ|WM|WS|WW|XB|YB|YC|"\ "YD|YS|YY|YZ|ZY|GB|GBZ|GJB|GBn|GHZB|GWKB|GWPB|JJF|JJG|Q|T)(/Z|/T)?)"
- ISO_REF =
%r{^<ref\sid="(?<anchor>[^"]+)"> \[(?<code>(ISO|IEC|#{GBCODE})[^0-9]*\s[0-9-]+?) ([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s (?<text>.*)$}xm
- ISO_REF_NO_YEAR =
%r{^<ref\sid="(?<anchor>[^"]+)"> \[(?<code>(ISO|IEC|#{GBCODE})[^0-9]*\s[0-9-]+):--\]</ref>,?\s? <fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?(?<text>.*)$}xm
- ISO_REF_ALL_PARTS =
%r{^<ref\sid="(?<anchor>[^"]+)"> \[(?<code>(ISO|IEC|#{GBCODE})[^0-9]*\s[0-9]+)\s \(all\sparts\)\]</ref>(<p>)?,?\s? (?<text>.*)(</p>)?$}xm
Instance Method Summary collapse
- #add_id_parts(dn, part, subpart) ⇒ Object
- #agency_value(issuer, scope, prefix, mandate) ⇒ Object
- #bilingual_terms_validate(root) ⇒ Object
- #check_bilingual(t, element) ⇒ Object
- #cleanup(xmldoc) ⇒ Object
- #committee_cleanup(xmldoc) ⇒ Object
- #content_validate(doc) ⇒ Object
- #contributor_cleanup(xmldoc) ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #docidentifier_cleanup(xmldoc) ⇒ Object
- #document(node) ⇒ Object
- #duplicate_localisedstrings(zh) ⇒ Object
-
#extract_localisedstrings(elem) ⇒ Object
element consists solely of localised strings, with no attributes.
- #fetch_ref(xml, code, year, **opts) ⇒ Object
- #front(node, xml) ⇒ Object
- #gb_attributes(node) ⇒ Object
- #get_mandate(node) ⇒ Object
- #get_prefix(node) ⇒ Object
- #get_scope(node) ⇒ Object
- #get_topic(node) ⇒ Object
- #html_compliant_converter(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_attributes(node) ⇒ Object
- #id_stage_prefix(dn, node) ⇒ Object
- #inline_quoted(node) ⇒ Object
- #iso_id(node, xml) ⇒ Object
- #issuer_validate(root) ⇒ Object
- #localisedstr(xmldoc) ⇒ Object
- #makexml(node) ⇒ Object
- #metadata(node, xml) ⇒ Object
- #metadata_author(node, xml) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #metadata_contributor1(node, xml, type, role) ⇒ Object
- #metadata_contributors(node, xml) ⇒ Object
- #metadata_copyright(node, xml) ⇒ Object
- #metadata_equivalence(node, xml) ⇒ Object
- #metadata_gblibraryids(node, xml) ⇒ Object
- #metadata_gbtype(node, xml) ⇒ Object
- #metadata_obsoletes(node, xml) ⇒ Object
- #norm_bibitem_style(root) ⇒ Object
- #prefix_validate(root) ⇒ Object
- #reference1_matches(item) ⇒ Object
- #section(node) ⇒ Object
- #standard_type(node) ⇒ Object
-
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
subclause contains subclauses.
- #termdef_boilerplate_cleanup(xmldoc) ⇒ Object
- #termdef_cleanup(xmldoc) ⇒ Object
- #title(node, xml) ⇒ Object
- #title_intro(node, lang, t, at) ⇒ Object
- #title_intro_validate(root) ⇒ Object
- #title_main(node, lang, t, at) ⇒ Object
- #title_main_validate(root) ⇒ Object
- #title_part(node, lang, t, at) ⇒ Object
- #title_part_validate(root) ⇒ Object
- #validate(doc) ⇒ Object
Instance Method Details
#add_id_parts(dn, part, subpart) ⇒ Object
187 188 189 190 191 |
# File 'lib/asciidoctor/gb/front.rb', line 187 def add_id_parts(dn, part, subpart) dn += ".#{part}" if part dn += ".#{subpart}" if subpart dn end |
#agency_value(issuer, scope, prefix, mandate) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/asciidoctor/gb/converter.rb', line 220 def agency_value(issuer, scope, prefix, mandate) agency = issuer.content agency == "GB" and agency = @agencyclass.standard_agency1(scope, prefix, mandate) agency = "GB" if agency.nil? || agency.empty? agency end |
#bilingual_terms_validate(root) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/asciidoctor/gb/validate.rb', line 63 def bilingual_terms_validate(root) root.xpath("//term").each do |t| check_bilingual(t, "preferred") check_bilingual(t, "admitted") check_bilingual(t, "deprecates") end end |
#check_bilingual(t, element) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/asciidoctor/gb/validate.rb', line 54 def check_bilingual(t, element) zh = t.at(".//#{element}[@language = 'zh']") en = t.at(".//#{element}[@language = 'en']") (en.nil? || en.text.empty?) && !(zh.nil? || zh.text.empty?) && warn("GB: #{element} term #{zh.text} has no English counterpart") !(en.nil? || en.text.empty?) && (zh.nil? || zh.text.empty?) && warn("GB: #{element} term #{en.text} has no Chinese counterpart") end |
#cleanup(xmldoc) ⇒ Object
191 192 193 194 195 196 197 |
# File 'lib/asciidoctor/gb/converter.rb', line 191 def cleanup(xmldoc) lang = xmldoc.at("//language")&.text @agencyclass = GbAgencies::Agencies.new(lang, {}, "") super contributor_cleanup(xmldoc) xmldoc end |
#committee_cleanup(xmldoc) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/asciidoctor/gb/converter.rb', line 212 def committee_cleanup(xmldoc) xmldoc.xpath("//gbcommittee").each do |c| xmldoc.at("//bibdata/contributor").next = "<contributor><role type='technical-committee'/><organization>"\ "<name>#{c.text}</name></organization></contributor>" end end |
#content_validate(doc) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/asciidoctor/gb/validate.rb', line 11 def content_validate(doc) super bilingual_terms_validate(doc.root) issuer_validate(doc.root) prefix_validate(doc.root) @agencyclass.gbtype_validate(doc.root.at("//gbscope")&.text, doc.root.at("//gbprefix")&.text) end |
#contributor_cleanup(xmldoc) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/asciidoctor/gb/converter.rb', line 228 def contributor_cleanup(xmldoc) issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\ "organization/name") scope = xmldoc.at("//gbscope")&.text prefix = xmldoc.at("//gbprefix")&.text mandate = xmldoc.at("//gbmandate")&.text || "mandatory" agency = agency_value(issuer, scope, prefix, mandate) owner = xmldoc.at("//copyright/owner/organization/name") owner.content = agency issuer.content = agency committee_cleanup(xmldoc) end |
#doc_converter(node) ⇒ Object
64 65 66 67 |
# File 'lib/asciidoctor/gb/converter.rb', line 64 def doc_converter(node) node.nil? ? IsoDoc::Gb::WordConvert.new({}) : IsoDoc::Gb::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
49 50 51 |
# File 'lib/asciidoctor/gb/converter.rb', line 49 def doc_extract_attributes(node) super.merge(gb_attributes(node)) end |
#docidentifier_cleanup(xmldoc) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/asciidoctor/gb/converter.rb', line 199 def docidentifier_cleanup(xmldoc) id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return scope = xmldoc.at("//gbscope")&.text prefix = xmldoc.at("//gbprefix")&.text mand = xmldoc.at("//gbmandate")&.text || "mandatory" idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text) id.content = idtext&.gsub(/\ /, " ") id = xmldoc.at("//bibdata/docidentifier[@type = 'gb-structured']/"\ "project-number") or return idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text) id.content = idtext&.gsub(/\ /, " ") end |
#document(node) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/asciidoctor/gb/converter.rb', line 69 def document(node) init(node) ret = makexml(node).to_xml(indent: 2) unless node.attr("nodoc") || !node.attr("docfile") filename = node.attr("docfile").gsub(/\.adoc$/, "").gsub(%r{^.*/}, "") File.open(filename + ".xml", "w:utf-8") { |f| f.write(ret) } html_compliant_converter(node).convert(filename + ".xml") FileUtils.mv "#{filename}.html", "#{filename}_compliant.html" html_converter(node).convert(filename + ".xml") doc_converter(node).convert(filename + ".xml") end @files_to_delete.each { |f| FileUtils.rm f } ret end |
#duplicate_localisedstrings(zh) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/asciidoctor/gb/converter.rb', line 119 def duplicate_localisedstrings(zh) en = zh.dup.remove zh.after(en).after(" ") zh["language"] = "zh" en["language"] = "en" en.traverse do |c| c.text? && c.content = c.text.gsub(HAN_TEXT, "").gsub(/^\s*/, "") end zh.traverse do |c| c.text? && c.content = c.text.gsub(ROMAN_TEXT, "").gsub(/^\s*/, "") end end |
#extract_localisedstrings(elem) ⇒ Object
element consists solely of localised strings, with no attributes
112 113 114 115 116 117 |
# File 'lib/asciidoctor/gb/converter.rb', line 112 def extract_localisedstrings(elem) elem.xpath("./string").each do |s| s.name = elem.name end elem.replace(elem.children) end |
#fetch_ref(xml, code, year, **opts) ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/asciidoctor/gb/converter.rb', line 180 def fetch_ref(xml, code, year, **opts) code = "CN(#{code})" if !/^CN\(/.match(code) && /^#{GBCODE}[^A-Za-z]/.match(code) hit = @bibdb&.fetch(code, year, opts) return nil if hit.nil? xml.parent.add_child(Asciidoctor::Standoc::Utils::smart_render_xml(hit)) xml rescue Algolia::AlgoliaProtocolError nil # Render reference without an Internet connection. end |
#front(node, xml) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/asciidoctor/gb/front.rb', line 12 def front(node, xml) xml.bibdata **attr_code(type: standard_type(node)) do |b| node, b end (node, xml) end |
#gb_attributes(node) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/asciidoctor/gb/converter.rb', line 36 def gb_attributes(node) { standardlogoimg: node.attr("standard-logo-img"), standardclassimg: node.attr("standard-class-img"), standardissuerimg: node.attr("standard-issuer-img"), titlefont: node.attr("title-font"), } end |
#get_mandate(node) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/asciidoctor/gb/front.rb', line 124 def get_mandate(node) node.attr("mandate") and return node.attr("mandate") p = node.attr("prefix") mandate = %r{/T}.match(p) ? "recommended" : %r{/Z}.match(p) ? "guidelines" : nil if mandate.nil? mandate = "mandatory" warn "GB: no mandate supplied, defaulting to mandatory" end mandate end |
#get_prefix(node) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/asciidoctor/gb/front.rb', line 110 def get_prefix(node) scope = get_scope(node) if prefix = node.attr("prefix") prefix.gsub!(%r{/[TZ]$}, "") prefix.gsub!(%r{^[TQ]/([TZ]/)?}, "") prefix.gsub!(/^DB/, "") if scope == "local" else prefix = "GB" scope = "national" warn "GB: no prefix supplied, defaulting to GB" end [scope, prefix] end |
#get_scope(node) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/asciidoctor/gb/front.rb', line 98 def get_scope(node) node.attr("scope") and return node.attr("scope") scope = if %r{^[TQ]/}.match node.attr("prefix") m = node.attr("prefix").split(%{/}) mandate = m[0] == "T" ? "social-group" : m[0] == "Q" ? "enterprise" : nil end return scope unless scope.nil? warn "GB: no scope supplied, defaulting to National" "national" end |
#get_topic(node) ⇒ Object
136 137 138 139 140 |
# File 'lib/asciidoctor/gb/front.rb', line 136 def get_topic(node) node.attr("topic") and return node.attr("topic") warn "GB: no topic supplied, defaulting to basic" "basic" end |
#html_compliant_converter(node) ⇒ Object
58 59 60 61 62 |
# File 'lib/asciidoctor/gb/converter.rb', line 58 def html_compliant_converter(node) node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) : IsoDoc::Gb::HtmlConvert.new(html_extract_attributes(node). merge(compliant: true)) end |
#html_converter(node) ⇒ Object
53 54 55 56 |
# File 'lib/asciidoctor/gb/converter.rb', line 53 def html_converter(node) node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) : IsoDoc::Gb::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
45 46 47 |
# File 'lib/asciidoctor/gb/converter.rb', line 45 def html_extract_attributes(node) super.merge(gb_attributes(node)) end |
#id_stage_prefix(dn, node) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/asciidoctor/gb/front.rb', line 193 def id_stage_prefix(dn, node) if node.attr("docstage") && node.attr("docstage").to_i < 60 abbr = IsoDoc::Gb::Metadata.new("en", "Latn", {}). stage_abbrev(node.attr("docstage"), node.attr("iteration"), node.attr("draft")) dn = "/#{abbr} #{dn}" # prefixes added in cleanup else dn += "-#{node.attr("copyright-year")}" if node.attr("copyright-year") end dn end |
#inline_quoted(node) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/asciidoctor/gb/converter.rb', line 132 def inline_quoted(node) ret = noko do |xml| case node.role when "en" then xml.string node.text, **{ language: "en" } when "zh" then xml.string node.text, **{ language: "zh" } when "zh-Hans" xml.string node.text, **{ language: "zh", script: "Hans" } when "zh-Hant" xml.string node.text, **{ language: "zh", script: "Hant" } else nil end end.join return ret unless ret.nil? or ret.empty? super end |
#iso_id(node, xml) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/asciidoctor/gb/front.rb', line 175 def iso_id(node, xml) return unless node.attr("docnumber") part = node.attr("partnumber") dn = add_id_parts(node.attr("docnumber"), part, nil) dn = id_stage_prefix(dn, node) xml.docidentifier dn, **attr_code(type: "gb") xml.docidentifier **attr_code(type: "gb-structured") do |i| i.project_number node.attr("docnumber"), **attr_code(part: part) end end |
#issuer_validate(root) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/asciidoctor/gb/validate.rb', line 45 def issuer_validate(root) issuer = root&.at("//bibdata/contributor[role/@type = 'issuer']/"\ "organization/name")&.text scope = root&.at("//gbscope")&.text if %w(enterprise social).include?(scope) && issuer == "GB" warn "No issuer provided for #{scope} standard" end end |
#localisedstr(xmldoc) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/asciidoctor/gb/converter.rb', line 101 def localisedstr(xmldoc) xmldoc.xpath(LOCALISED_ELEMS).each do |zh| if zh.at("./string") extract_localisedstrings(zh) elsif MUST_LOCALISE_ELEMS.include? zh.name duplicate_localisedstrings(zh) end end end |
#makexml(node) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/asciidoctor/gb/converter.rb', line 22 def makexml(node) result = ["<?xml version='1.0' encoding='UTF-8'?>\n<gb-standard>"] @draft = node.attributes.has_key?("draft") @keepboilerplate = node.attributes.has_key?("keep-boilerplate") result << noko { |ixml| front node, ixml } result << noko { |ixml| middle node, ixml } result << "</gb-standard>" result = textcleanup(result.flatten * "\n") ret1 = cleanup(Nokogiri::XML(result)) validate(ret1) ret1.root.add_namespace(nil, GB_NAMESPACE) ret1 end |
#metadata(node, xml) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/asciidoctor/gb/front.rb', line 205 def (node, xml) title node, xml (node, xml) (node, xml) (node, xml) (node, xml) xml.language (node.attr("language") || "zh") xml.script (node.attr("script") || "Hans") (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) end |
#metadata_author(node, xml) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/asciidoctor/gb/front.rb', line 19 def (node, xml) = node.attr("author") || return .split(/, ?/).each do || xml.contributor do |c| c.role **{ type: "author" } c.person do |p| p.name do |n| n.surname end end end end end |
#metadata_committee(node, xml) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/asciidoctor/gb/front.rb', line 57 def (node, xml) attrs = { type: node.attr("technical-committee-type") } xml.gbcommittee **attr_code(attrs) do |a| a << node.attr("technical-committee") end i = 2 while node.attr("technical-committee_#{i}") do attrs = { type: node.attr("technical-committee-type_#{i}") } xml.gbcommittee **attr_code(attrs) do |a| a << node.attr("technical-committee_#{i}") end i += 1 end end |
#metadata_contributor1(node, xml, type, role) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/asciidoctor/gb/front.rb', line 33 def (node, xml, type, role) contrib = node.attr(type) || "GB" contrib.split(/, ?/).each do |c| xml.contributor do |x| x.role **{ type: role } x.organization do |a| a.name { |n| n << c } end end end end |
#metadata_contributors(node, xml) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/asciidoctor/gb/front.rb', line 161 def (node, xml) (node, xml) (node, xml, "author-committee", "author") i = 2 while node.attr("author-committee_#{i}") do (node, xml, "author-committee_#{i}", "author") i += 1 end (node, xml, "publisher", "publisher") (node, xml, "authority", "authority") (node, xml, "proposer", "proposer") (node, xml, "issuer", "issuer") end |
#metadata_copyright(node, xml) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/asciidoctor/gb/front.rb', line 45 def (node, xml) from = node.attr("copyright-year") || Date.today.year xml.copyright do |c| c.from from c.owner do |owner| owner.organization do |o| o.name "GB" end end end end |
#metadata_equivalence(node, xml) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/asciidoctor/gb/front.rb', line 72 def (node, xml) isostd = node.attr("iso-standard") || return type = node.attr("equivalence") || "equivalent" m = /^(?<code>[^,]+),?(?<title>.*)$/.match isostd title = m[:title].empty? ? "[not supplied]" : m[:title] xml.relation **{ type: type } do |r| r.bibitem do |b| b.title { |t| t << title } b.docidentifier m[:code] end end end |
#metadata_gblibraryids(node, xml) ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/asciidoctor/gb/front.rb', line 152 def (node, xml) ccs = node.attr("library-ccs") ccs and ccs.split(/, ?/).each do |l| xml.ccs { |c| c << l } end l = node.attr("library-plan") l && xml.plannumber { |plan| plan << l } end |
#metadata_gbtype(node, xml) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/asciidoctor/gb/front.rb', line 142 def (node, xml) xml.gbtype do |t| scope, prefix = get_prefix(node) t.gbscope { |s| s << scope } t.gbprefix { |p| p << prefix } t.gbmandate { |m| m << get_mandate(node) } t.gbtopic { |t| t << get_topic(node) } end end |
#metadata_obsoletes(node, xml) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/asciidoctor/gb/front.rb', line 85 def (node, xml) std = node.attr("obsoletes") || return m = /^(?<code>[^,]+),?(?<title>.*)$/.match std title = m[:title].empty? ? "[not supplied]" : m[:title] xml.relation **{ type: "obsoletes" } do |r| r.bibitem do |b| b.title { |t| t << title } b.docidentifier m[:code] end r.bpart node.attr("obsoletes-parts") if node.attr("obsoletes-parts") end end |
#norm_bibitem_style(root) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/asciidoctor/gb/validate.rb', line 104 def norm_bibitem_style(root) root.xpath(NORM_BIBITEMS).each do |b| if b.at(Asciidoctor::Standoc::Converter::ISO_PUBLISHER_XPATH).nil? unless /^#{GBCODE}(?![A-Z])/.match(b.at("./docidentifier").text) Asciidoctor::Standoc::Utils::warning(b, NORM_ISO_WARN, b.text) end end end end |
#prefix_validate(root) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/asciidoctor/gb/validate.rb', line 19 def prefix_validate(root) prefix = root&.at("//gbprefix")&.text scope = root&.at("//gbscope")&.text case scope when "social-group" /^[A-Za-z]{3,6}$/.match(prefix) or warn("#{prefix} is improperly formatted for social standards") when "enterprise" /^[A-Z0-9]{3,}$/.match(prefix) or warn("#{prefix} is improperly formatted for enterprise standards") when "sector" %w(AQ BB CB CH CJ CY DA DB DL DZ EJ FZ GA GH GM GY HB HG HJ HS HY JB JC JG JR JT JY LB LD LS LY MH MT MZ NY QB QC QJ QX SB SC SH SJ SL SN SY TB TD TJ TY WB WH WJ WM WS WW XB YB YC YD YS YY YZ ZY).include? prefix or warn("#{prefix} is not a legal sector standard prefix") when "local" %w(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 end).include? prefix or warn("#{prefix} is not a legal local standard prefix") when "national" %w(GB GBZ GJB GBn GHZB GWPB JJF JJG).include? prefix or warn("#{prefix} is not a legal national standard prefix") end end |
#reference1_matches(item) ⇒ Object
173 174 175 176 177 178 |
# File 'lib/asciidoctor/gb/converter.rb', line 173 def reference1_matches(item) matched = ISO_REF.match item matched2 = ISO_REF_NO_YEAR.match item matched3 = ISO_REF_ALL_PARTS.match item [matched, matched2, matched3] end |
#section(node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/asciidoctor/gb/section_input.rb', line 24 def section(node) a = { id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node) } noko do |xml| case sectiontype(node) when "引言", "introduction" then introduction_parse(a, xml, node) when "patent notice" then patent_notice_parse(xml, node) when "范围", "scope" then scope_parse(a, xml, node) when "规范性引用文件", "normative references" norm_ref_parse(a, xml, node) when "术语和定义", "terms and definitions", "术语、定义、符号、代号和缩略语", "terms, definitions, symbols and abbreviated terms", "terms, definitions, symbols and abbreviations", "terms, definitions and symbols", "terms, definitions and abbreviations", "terms, definitions and abbreviated terms" @term_def = true term_def_parse(a, xml, node, true) @term_def = false when "符号、代号和缩略语", "symbols and abbreviated terms", "abbreviated terms", "abbreviations", "symbols" symbols_parse(a, xml, node) when "参考文献", "bibliography" bibliography_parse(a, xml, node) else if @term_def then term_def_subclause_parse(a, xml, node) elsif @biblio then bibliography_parse(a, xml, node) elsif node.attr("style") == "bibliography" && node.level == 1 bibliography_parse(a, xml, node) elsif node.attr("style") == "appendix" && node.level == 1 annex_parse(a, xml, node) else clause_parse(a, xml, node) end end end.join("\n") end |
#standard_type(node) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/asciidoctor/gb/front.rb', line 5 def standard_type(node) type = node.attr("mandate") || "mandatory" type = "standard" if type == "mandatory" type = "recommendation" if type == "recommended" type end |
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
subclause contains subclauses
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/asciidoctor/gb/section_input.rb', line 11 def term_def_subclause_parse(attrs, xml, node) return clause_parse(attrs, xml, node) if node.role == "nonterm" sub = node.find_by(context: :section) {|s| s.level == node.level + 1 } sub.empty? || (return term_def_parse(attrs, xml, node, false)) (node.title.downcase == "symbols and abbreviated terms" || node.title == "符号、代号和缩略语") && (return symbols_parse(attrs, xml, node)) xml.term **attr_code(attrs) do |xml_section| xml_section.preferred { |name| name << node.title } xml_section << node.content end end |
#termdef_boilerplate_cleanup(xmldoc) ⇒ Object
149 150 151 152 |
# File 'lib/asciidoctor/gb/converter.rb', line 149 def termdef_boilerplate_cleanup(xmldoc) return if @keepboilerplate super end |
#termdef_cleanup(xmldoc) ⇒ Object
84 85 86 87 |
# File 'lib/asciidoctor/gb/converter.rb', line 84 def termdef_cleanup(xmldoc) super localisedstr(xmldoc) end |
#title(node, xml) ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/asciidoctor/gb/front.rb', line 243 def title(node, xml) ["en", "zh"].each do |lang| xml.title do |t| at = { language: lang, format: "plain" } title_intro(node, lang, t, at) title_main(node, lang, t, at) title_part(node, lang, t, at) end end end |
#title_intro(node, lang, t, at) ⇒ Object
223 224 225 226 227 228 |
# File 'lib/asciidoctor/gb/front.rb', line 223 def title_intro(node, lang, t, at) node.attr("title-intro-#{lang}") and t.title_intro **attr_code(at) do |t1| t1 << asciidoc_sub(node.attr("title-intro-#{lang}")) end end |
#title_intro_validate(root) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/asciidoctor/gb/validate.rb', line 71 def title_intro_validate(root) title_intro_en = root.at("//title-intro[@language='en']") title_intro_zh = root.at("//title-intro[@language='zh']") if title_intro_en.nil? && !title_intro_zh.nil? warn "No English Title Intro!" end if !title_intro_en.nil? && title_intro_zh.nil? warn "No Chinese Title Intro!" end end |
#title_main(node, lang, t, at) ⇒ Object
230 231 232 233 234 |
# File 'lib/asciidoctor/gb/front.rb', line 230 def title_main(node, lang, t, at) t.title_main **attr_code(at) do |t1| t1 << asciidoc_sub(node.attr("title-main-#{lang}")) end end |
#title_main_validate(root) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/asciidoctor/gb/validate.rb', line 82 def title_main_validate(root) title_main_en = root.at("//title-main[@language='en']") title_main_zh = root.at("//title-main[@language='zh']") if title_main_en.nil? && !title_main_zh.nil? warn "No English Title!" end if !title_main_en.nil? && title_main_zh.nil? warn "No Chinese Title!" end end |
#title_part(node, lang, t, at) ⇒ Object
236 237 238 239 240 241 |
# File 'lib/asciidoctor/gb/front.rb', line 236 def title_part(node, lang, t, at) node.attr("title-part-#{lang}") and t.title_part **attr_code(at) do |t1| t1 << asciidoc_sub(node.attr("title-part-#{lang}")) end end |
#title_part_validate(root) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/asciidoctor/gb/validate.rb', line 93 def title_part_validate(root) title_part_en = root.at("//title-part[@language='en']") title_part_zh = root.at("//title-part[@language='zh']") if title_part_en.nil? && !title_part_zh.nil? warn "No English Title Part!" end if !title_part_en.nil? && title_part_zh.nil? warn "No Chinese Title Part!" end end |
#validate(doc) ⇒ Object
5 6 7 8 9 |
# File 'lib/asciidoctor/gb/validate.rb', line 5 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "gbstandard.rng")) end |