class Asciidoctor::Gb::Converter

A {Converter} implementation that generates GB output, and a document schema encapsulation of the document for validation

A {Converter} implementation that generates GB output, and a document schema encapsulation of the document for validation

Constants

GBCODE
HAN_TEXT
ISO_REF
ISO_REF_ALL_PARTS
ISO_REF_NO_YEAR
LOCALISED_ELEMS
MUST_LOCALISE_ELEMS
ROMAN_TEXT
STAGE_ABBRS_CN
XML_NAMESPACE
XML_ROOT_TAG

Public Instance Methods

add_id_parts(dn, part, subpart) click to toggle source
# File lib/asciidoctor/gb/front_id.rb, line 38
def add_id_parts(dn, part, subpart)
  dn += ".#{part}" if part
  dn += ".#{subpart}" if subpart
  dn
end
agency_value(issuer, scope, prefix, mandate) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 91
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
appendix_parse(attrs, xml, node) click to toggle source
# File lib/asciidoctor/gb/section_input.rb, line 35
def appendix_parse(attrs, xml, node)
  # UNSAFE, there is no unset_option() in asciidoctor
  node.remove_attr("appendix-option")
  clause_parse(attrs, xml, node)
end
bibdata_validate(doc) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 19
def bibdata_validate(doc)
  doctype_validate(doc)
  script_validate(doc)
end
bilingual_terms_validate(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 80
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
boilerplate_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 116
def boilerplate_cleanup(xmldoc)
  isodoc = boilerplate_isodoc(xmldoc)
  initial_boilerplate(xmldoc, isodoc)
  return if @keepboilerplate
  xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
    term_defs_boilerplate(f.at("./title"),
                          xmldoc.xpath(".//termdocsource"),
                          f.at(".//term"), f.at(".//p"), isodoc)
  end
  f = xmldoc.at(self.class::NORM_REF) and
    norm_ref_preface(f)
end
check_bilingual(t, element) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 71
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?) &&
    @log.add("Style", t, "GB: #{element} term #{zh.text} has no English counterpart")
  !(en.nil? || en.text.empty?) && (zh.nil? || zh.text.empty?) &&
    @log.add("Style", t, "GB: #{element} term #{en.text} has no Chinese counterpart")
end
cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/cleanup.rb, line 62
def cleanup(xmldoc)
  lang = xmldoc.at("//language")&.text
  @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
  super
  contributor_cleanup(xmldoc)
  xmldoc
end
committee_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 83
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) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/validate.rb, line 10
def content_validate(doc)
  super
  bilingual_terms_validate(doc.root)
  issuer_validate(doc.root)
  prefix_validate(doc.root)
  bibdata_validate(doc.root)
  @agencyclass.gbtype_validate(doc.root.at("//gbscope")&.text, doc.root.at("//gbprefix")&.text)
end
contributor_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 99
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) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 58
def doc_converter(node)
  node.nil? ? IsoDoc::Gb::WordConvert.new({}) :
    IsoDoc::Gb::WordConvert.new(doc_extract_attributes(node))
end
doc_extract_attributes(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/converter.rb, line 43
def doc_extract_attributes(node)
  super.merge(gb_attributes(node))
end
docidentifier_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 70
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(/\&#x2002;/, " ")
  id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
                 "project-number") or return
  idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
  id.content = idtext&.gsub(/\&#x2002;/, " ")
end
doctype(node) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 6
def doctype(node)
  type = node.attr("mandate") || "mandatory"
  type = "standard" if type == "mandatory"
  type = "recommendation" if type == "recommended"
  type
end
doctype_validate(xmldoc) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 24
def doctype_validate(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  %w(standard recommendation).include? doctype or
    @log.add("Document Attributes", nil, "#{doctype} is not a recognised document type")
end
duplicate_localisedstrings(zh) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 44
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 = text_clean(c.text.gsub(HAN_TEXT, ""))
  end
  zh.traverse do |c|
    c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
  end
end
extract_localisedstrings(elem) click to toggle source

element consists solely of localised strings, with no attributes

# File lib/asciidoctor/gb/cleanup.rb, line 33
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) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/converter.rb, line 131
def fetch_ref(xml, code, year, **opts)
  code = "CN(#{code})" if !/^CN\(/.match(code) &&
    /^#{GBCODE}[^A-Za-z]/.match(code)
    super
end
gb_attributes(node) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 30
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) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 125
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"
    @log.add("Document Attributes", nil, "GB: no mandate supplied, defaulting to mandatory")
  end
  mandate
end
get_prefix(node) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 111
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"
    @log.add("Document Attributes", nil, "GB: no prefix supplied, defaulting to GB")
  end
  [scope, prefix]
end
get_scope(node) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 99
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?
  @log.add("Document Attributes", nil, "GB: no scope supplied, defaulting to National")
  "national"
end
get_topic(node) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 137
def get_topic(node)
  node.attr("topic") and return node.attr("topic")
  @log.add("Document Attributes", nil, "GB: no topic supplied, defaulting to basic")
  "basic"
end
html_compliant_converter(node) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 52
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) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 47
def html_converter(node)
  node.nil? ? IsoDoc::Gb::HtmlConvert.new({}) :
    IsoDoc::Gb::HtmlConvert.new(html_extract_attributes(node))
end
html_extract_attributes(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/converter.rb, line 39
def html_extract_attributes(node)
  super.merge(gb_attributes(node))
end
id_stage_prefix(dn, node) click to toggle source
# File lib/asciidoctor/gb/front_id.rb, line 44
def id_stage_prefix(dn, node)
  if node.attr("docstage") && node.attr("docstage").to_i < 60
    abbr = IsoDoc::Gb::Metadata.new("en", "Latn", @i18n).
      status_abbrev(node.attr("docstage"), nil, node.attr("iteration"),
                    node.attr("draft"), doctype(node))
    dn = "/#{abbr} #{dn}" # prefixes added in cleanup
  else
    dn += "-#{node.attr("copyright-year")}" if node.attr("copyright-year")
  end
  dn
end
init(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/converter.rb, line 137
def init(node)
  node.attr("language") or node.set_attr("language", "zh")
  node.attr("script") or
    node.set_attr("script", node.attr("language") == "zh" ?
                  "Hans" : "Latn")
  super
end
inline_quoted(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/converter.rb, line 88
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) click to toggle source
# File lib/asciidoctor/gb/front_id.rb, line 22
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")
end
issuer_validate(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 62
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"
    @log.add("Document Attributes", nil, "No issuer provided for #{scope} standard")
  end
end
localisedstr(xmldoc) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 22
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) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/converter.rb, line 24
def makexml(node)
  @draft = node.attributes.has_key?("draft")
  @keepboilerplate = node.attributes.has_key?("keep-boilerplate")
  super
end
metadata_author(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 162
def metadata_author(node, xml)
  metadata_author_personal(node, xml)
  metadata_contributor1(node, xml, "author-committee", "author")
  i = 2
  while node.attr("author-committee_#{i}") do
    metadata_contributor1(node, xml, "author-committee_#{i}", "author")
    i += 1
  end
end
metadata_author_personal(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 13
def metadata_author_personal(node, xml)
  author = node.attr("author") || return
  author.split(/, ?/).each do |author|
    xml.contributor do |c|
      c.role **{ type: "author" }
      c.person do |p|
        p.name do |n|
          n.surname author
        end
      end
    end
  end
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 51
def metadata_committee(node, xml)
  return unless node.attr("technical-committee")
  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) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 27
def metadata_contributor1(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_equivalence(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 67
def metadata_equivalence(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: "adoptedFrom" } do |r|
    r.description type
    r.bibitem do |b|
      b.title { |t| t << title }
      b.docidentifier m[:code]
    end
  end
end
metadata_ext(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 187
def metadata_ext(node, xml)
  metadata_doctype(node, xml)
  metadata_committee(node, xml)
  metadata_ics(node, xml)
  structured_id(node, xml)
  xml.stagename stage_name(get_stage(node), get_substage(node))
  metadata_gbtype(node, xml)
  metadata_gblibraryids(node, xml)
end
metadata_gblibraryids(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 153
def metadata_gblibraryids(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) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 143
def metadata_gbtype(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_language(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 179
def metadata_language(node, xml)
  xml.language (node.attr("language") || "zh")
end
metadata_obsoletes(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 86
def metadata_obsoletes(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
metadata_publisher(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 172
def metadata_publisher(node, xml)
  metadata_contributor1(node, xml, "publisher", "publisher")
  metadata_contributor1(node, xml, "authority", "authority")
  metadata_contributor1(node, xml, "proposer", "proposer")
  metadata_contributor1(node, xml, "issuer", "issuer")
end
metadata_relations(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 81
def metadata_relations(node, xml)
  metadata_equivalence(node, xml)
  metadata_obsoletes(node, xml)
end
metadata_script(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 183
def metadata_script(node, xml)
  xml.script (node.attr("script") || "Hans")
end
norm_bibitem_style(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 121
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)
        @log.add("Bibliography", b, "#{NORM_ISO_WARN}: #{b.text}")
      end
    end
  end
end
omit_docid_prefix(prefix) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 112
def omit_docid_prefix(prefix)
  IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
end
outputs(node, ret) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 74
def outputs(node, ret)
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
  presentation_xml_converter(node).convert(@filename + ".xml")
  html_compliant_converter(node).
    convert(@filename + ".presentation.xml", 
            nil, false, "#{@filename}_compliant.html")
  html_converter(node).convert(@filename + ".presentation.xml", 
                               nil, false, "#{@filename}.html")
  doc_converter(node).convert(@filename + ".presentation.xml", 
                              nil, false, "#{@filename}.doc")
  pdf_converter(node)&.convert(@filename + ".presentation.xml", 
                               nil, false, "#{@filename}.pdf")
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 63
def pdf_converter(node)
  return nil if node.attr("no-pdf")
  node.nil? ? IsoDoc::Gb::PdfConvert.new({}) :
    IsoDoc::Gb::PdfConvert.new(doc_extract_attributes(node))
end
prefix_validate(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 36
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
      @log.add("Document Attributes", nil, "#{prefix} is improperly formatted for social standards")
  when "enterprise"
    /^[A-Z0-9]{3,}$/.match(prefix) or
      @log.add("Document Attributes", nil, "#{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
       @log.add("Document Attributes", nil, "#{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
       @log.add("Document Attributes", nil, "#{prefix} is not a legal local standard prefix")
  when "national"
    %w(GB GBZ GJB GBn GHZB GWPB JJF JJG).include? prefix or
      @log.add("Document Attributes", nil, "#{prefix} is not a legal national standard prefix")
  end
end
presentation_xml_converter(node) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 69
def presentation_xml_converter(node)
  node.nil? ? IsoDoc::Gb::PresentationXMLConvert.new({}) :
    IsoDoc::Gb::PresentationXMLConvert.new(html_extract_attributes(node))
end
reference1_matches(item) click to toggle source
# File lib/asciidoctor/gb/converter.rb, line 124
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
script_validate(xmldoc) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 30
def script_validate(xmldoc)
  script = xmldoc&.at("//bibdata/script")&.text
  %(Hans Latn).include?(script) or
    @log.add("Document Attributes", nil, "#{script} is not a recognised script")
end
sectiontype_streamline(ret) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/section_input.rb, line 9
def sectiontype_streamline(ret)
  case ret
  when "前言" then "foreword"
  when "致謝" then "acknowledgements"
  when "引言" then "introduction"
  when "范围" then "scope"
  when "规范性引用文件" then "normative references"
  when "术语和定义", "术语、定义、符号、代号和缩略语"
    "terms and definitions"
  when "符号、代号和缩略语" then "symbols and abbreviated terms"
  when "参考文献" then "bibliography"
  when "致谢" then "acknowledgements"
  else
    super
  end
end
stage_name(stage, substage) click to toggle source
# File lib/asciidoctor/gb/front_id.rb, line 16
def stage_name(stage, substage)
  return "Proof" if stage == "60" && substage == "00"
  @lang == "en" ?
    STAGE_NAMES[stage.to_sym] : STAGE_ABBRS_CN[stage.to_sym]
end
structured_id(node, xml) click to toggle source
# File lib/asciidoctor/gb/front_id.rb, line 30
def structured_id(node, xml)
  part = node.attr("partnumber")
  xml.structuredidentifier do |i|
    i.project_number node.attr("docnumber"),
      **attr_code(part: part)
  end
end
symbols_attrs(node, a) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/section_input.rb, line 26
def symbols_attrs(node, a)
  case sectiontype1(node)
  when "符号" then a.merge(type: "symbols")
  when "代号和缩略语" then a.merge(type: "abbreviated_terms")
  else
    super
  end
end
termdef_boilerplate_cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/cleanup.rb, line 57
def termdef_boilerplate_cleanup(xmldoc)
  return if @keepboilerplate
  super
end
termdef_cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/gb/cleanup.rb, line 4
def termdef_cleanup(xmldoc)
  super
  # TODO this should become variant tag
  localisedstr(xmldoc)
end
text_clean(text) click to toggle source
# File lib/asciidoctor/gb/cleanup.rb, line 40
def text_clean(text)
  text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
end
title(node, xml) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 231
def title(node, xml)
  ["en", "zh"].each do |lang|
    at = { language: lang, format: "plain" }
    title_full(node, lang, xml, at)
    title_intro(node, lang, xml, at)
    title_main(node, lang, xml, at)
    title_part(node, lang, xml, at)
  end
end
title_full(node, lang, t, at) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 197
def title_full(node, lang, t, at)
  title = node.attr("title-main-#{lang}")
  intro = node.attr("title-intro-#{lang}")
  part = node.attr("title-part-#{lang}")
  title = "#{intro} -- #{title}" if intro
  title = "#{title} -- #{part}" if part
  t.title **attr_code(at.merge(type: "main")) do |t1|
    t1 << Asciidoctor::Standoc::Utils::asciidoc_sub(title)
  end
end
title_intro(node, lang, t, at) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 208
def title_intro(node, lang, t, at)
  node.attr("title-intro-#{lang}") and
    t.title **attr_code(at.merge(type: "title-intro")) do |t1|
    t1 << Asciidoctor::Standoc::Utils::asciidoc_sub(
      node.attr("title-intro-#{lang}"))
  end
end
title_intro_validate(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 88
def title_intro_validate(root)
  title_intro_en = root.at("//title[@type='title-intro' and @language='en']")
  title_intro_zh = root.at("//title[@type='title-intro' and @language='zh']")
  if title_intro_en.nil? && !title_intro_zh.nil?
    @log.add("Style", title_intro_zh, "No English Title Intro!")
  end
  if !title_intro_en.nil? && title_intro_zh.nil?
    @log.add("Style", title_intro_en, "No Chinese Title Intro!")
  end
end
title_main(node, lang, t, at) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 216
def title_main(node, lang, t, at)
  t.title **attr_code(at.merge(type: "title-main")) do |t1|
    t1 << Asciidoctor::Standoc::Utils::asciidoc_sub(
      node.attr("title-main-#{lang}"))
  end
end
title_main_validate(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 99
def title_main_validate(root)
  title_main_en = root.at("//title[@type='title-main' and @language='en']")
  title_main_zh = root.at("//title[@type='title-main' and @language='zh']")
  if title_main_en.nil? && !title_main_zh.nil?
    @log.add("Style", title_main_zh,  "No English Title!")
  end
  if !title_main_en.nil? && title_main_zh.nil?
    @log.add("Style", title_main_en,  "No Chinese Title!")
  end
end
title_part(node, lang, t, at) click to toggle source
# File lib/asciidoctor/gb/front.rb, line 223
def title_part(node, lang, t, at)
  node.attr("title-part-#{lang}") and
    t.title **attr_code(at.merge(type: "title-part")) do |t1|
    t1 << Asciidoctor::Standoc::Utils::asciidoc_sub(
      node.attr("title-part-#{lang}"))
  end
end
title_part_validate(root) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 110
def title_part_validate(root)
  title_part_en = root.at("//title[@type='title-part' and @language='en']")
  title_part_zh = root.at("//title[@type='title-part' and @language='zh']")
  if title_part_en.nil? && !title_part_zh.nil?
    @log.add("Style", title_part_en,  "No English Title Part!")
  end
  if !title_part_en.nil? && title_part_zh.nil?
    @log.add("Style", title_part_zh,  "No Chinese Title Part!")
  end
end
validate(doc) click to toggle source
# File lib/asciidoctor/gb/validate.rb, line 4
def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "gbstandard.rng"))
end