class Asciidoctor::ITU::Converter

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

Constants

ITULANG
PUBLISHER
XML_NAMESPACE
XML_ROOT_TAG

Public Instance Methods

add_id() click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 37
def add_id
  %(id="_#{UUIDTools::UUID.random_create}")
end
approval_validate(xmldoc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 84
def approval_validate(xmldoc)
  s = xmldoc.at("//bibdata/ext/recommendationstatus/approvalstage") or
    return
  process = s["process"]
  if process == "aap" and %w(determined in-force).include? s.text
    @log.add("Document Attributes", nil, 
             "Recommendation Status #{s.text} inconsistent with AAP")
  end
  if process == "tap" and !%w(determined in-force).include? s.text
    @log.add("Document Attributes", nil, 
             "Recommendation Status #{s.text} inconsistent with TAP")
  end
end
bibdata_validate(doc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 4
def bibdata_validate(doc)
  doctype_validate(doc)
  stage_validate(doc)
end
biblio_reorder(xmldoc) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 212
def biblio_reorder(xmldoc)
  xmldoc.xpath("//references").each do |r|
    biblio_reorder1(r)
  end
end
clause_parse(attrs, xml, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 116
def clause_parse(attrs, xml, node)
  node.option?("unnumbered") and attrs[:unnumbered] = true
  case sectiontype1(node)
  when "conventions" then attrs = attrs.merge(type: "conventions")
  when "history"
    attrs[:preface] and attrs = attrs.merge(type: "history")
  when "source"
    attrs[:preface] and attrs = attrs.merge(type: "source")
  end
  super
end
cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/cleanup.rb, line 105
def cleanup(xmldoc)
  symbols_cleanup(xmldoc)
  super
  obligations_cleanup(xmldoc)
  xmldoc
end
content_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/validate.rb, line 26
def content_validate(doc)
  super
  approval_validate(doc)
  itu_identifier_validate(doc)
  bibdata_validate(doc.root)
  termdef_style(doc.root)
  title_validate1(doc.root)
  requirement_validate(doc.root)
  numbers_validate(doc.root)
end
default_publisher() click to toggle source
# File lib/asciidoctor/itu/front.rb, line 72
def default_publisher
  "International Telecommunication Union"
end
doc_converter(node) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 150
def doc_converter(node)
  IsoDoc::ITU::WordConvert.new(doc_extract_attributes(node))
end
doc_extract_attributes(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 133
def doc_extract_attributes(node)
  super.merge(hierarchical_assets:
              node.attr("hierarchical-object-numbering"))
end
doctype(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 36
def doctype(node)
  ret = super || "recommendation"
  ret = "recommendation" if ret == "article"
  ret
end
doctype_validate(xmldoc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 9
def doctype_validate(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  %w(recommendation recommendation-supplement recommendation-amendment 
  recommendation-corrigendum recommendation-errata recommendation-annex 
  focus-group implementers-guide technical-paper technical-report 
  joint-itu-iso-iec service-publication).include? doctype or
  @log.add("Document Attributes", nil, "#{doctype} is not a recognised document type")
end
extract_text(node) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 47
def extract_text(node)
  return "" if node.nil?
  node1 = Nokogiri::XML.fragment(node.to_s)
  node1.xpath("//link | //locality | //localityStack").each(&:remove)
  ret = ""
  node1.traverse { |x| ret += x.text if x.text? }
  ret
end
html_converter(node) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 142
def html_converter(node)
  IsoDoc::ITU::HtmlConvert.new(html_extract_attributes(node))
end
html_extract_attributes(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 128
def html_extract_attributes(node)
  super.merge(hierarchical_assets:
              node.attr("hierarchical-object-numbering"))
end
init(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 24
def init(node)
  super
  @smartquotes = node.attr("smartquotes") == "true"
  @no_insert_missing_sections = doctype(node) != "recommendation" ||
    node.attr("legacy-do-not-insert-missing-sections")
end
insert_conventions(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 80
def insert_conventions(xml)
  ins =  xml.at("//sections//definitions") ||
    xml.at("//sections/clause[descendant::definitions]")
  unless xml.at("//sections/clause[@type = 'conventions']")
    ins.next = "<clause #{add_id} type='conventions'>"\
               "<title>#{@i18n.conventions}</title><p>"\
               "#{@i18n.clause_empty}</p></clause>"
  end
end
insert_empty_clauses(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 90
def insert_empty_clauses(xml)
  xml.xpath("//terms[not(./term)][not(.//terms)]").each do |c|
    insert_empty_clauses1(c, @i18n.clause_empty)
  end
  xml.xpath("//definitions[not(./dl)]").each do |c|
    insert_empty_clauses1(c, @i18n.clause_empty)
  end
end
insert_empty_clauses1(clause, text) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 99
def insert_empty_clauses1(clause, text)
  clause.at("./p") and return
  ins = clause.at("./title") or return
  ins.next = "<p>#{text}</p>"
end
insert_missing_sections(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 29
def insert_missing_sections(xml)
  insert_scope(xml)
  insert_norm_ref(xml)
  insert_terms(xml)
  insert_symbols(xml)
  insert_conventions(xml)
end
insert_norm_ref(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 54
def insert_norm_ref(xml)
  xml.at("//bibliography") or
    xml.at("./*/annex[last()] | ./*/sections").next =
      "<bibliography><sentinel/></bibliography>"
  ins = xml.at("//bibliography").elements.first
  xml.at("//bibliography/references[@normative = 'true']") or
    ins.previous = "<references #{add_id} normative='true'>"\
                   "<title>#{@i18n.normref}</title></references>"
  xml&.at("//sentinel")&.remove
end
insert_scope(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 41
def insert_scope(xml)
  xml.at("./*/sections") or
    xml.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
      "<sections><sentinel/></sections>"
  xml.at("./*/sections/*") or xml.at("./*/sections") << "<sentinel/>"
  ins = xml.at("//sections").elements.first
  xml.at("//sections/clause[@type = 'scope']") or
    ins.previous =
      "<clause type='scope' #{add_id}><title>#{@i18n.scope}</title><p>"\
      "#{@i18n.clause_empty}</p></clause>"
  xml&.at("//sentinel")&.remove
end
insert_symbols(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 71
def insert_symbols(xml)
  ins =  xml.at("//sections/terms") ||
    xml.at("//sections/clause[descendant::terms]")
  unless xml.at("//sections//definitions")
    ins.next = "<definitions #{add_id}>"\
               "<title>#{@i18n.symbolsabbrev}</title></definitions>"
  end
end
insert_terms(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 65
def insert_terms(xml)
  ins = xml.at("//sections/clause[@type = 'scope']")
  xml.at("//sections//terms") or
    ins.next = "<terms #{add_id}><title>#{@i18n.termsdef}</title></terms>"
end
itu_id(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 139
def itu_id(node, xml)
  return unless node.attr("docnumber")

  xml.docidentifier **{ type: "ITU" } do |i|
    i << itu_id1(node, false)
  end
  xml.docidentifier **{ type: "ITU-lang" } do |i|
    i << itu_id1(node, true)
  end
  xml.docnumber { |i| i << node.attr("docnumber") }
end
itu_id1(node, lang) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 129
def itu_id1(node, lang)
  bureau = node.attr("bureau") || "T"
  id = if doctype(node) == "service-publication"
         @i18n.annex_to_itu_ob_abbrev.sub(/%/, node.attr("docnumber"))
       else
         "ITU-#{bureau} #{node.attr('docnumber')}"
       end
  id + (lang ? "-#{ITULANG[@lang]}" : "")
end
itu_identifier_validate(xmldoc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 98
def itu_identifier_validate(xmldoc)
  s = xmldoc.xpath("//bibdata/docidentifier[@type = 'ITU']").each do |x|
    /^ITU-[RTD] [AD-VX-Z]\.[0-9]+$/.match(x.text) or
      @log.add("Style", nil, "#{x.text} does not match ITU document "\
               "identifier conventions")
  end
end
makexml(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 31
def makexml(node)
  @draft = node.attributes.has_key?("draft")
  super
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 76
def metadata_committee(node, xml)
  metadata_committee1(node, xml, "")
  suffix = 2
  while node.attr("bureau_#{suffix}")
    metadata_committee1(node, xml, "_#{suffix}")
    suffix += 1
  end
end
metadata_committee1(node, xml, suffix) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 85
def metadata_committee1(node, xml, suffix)
  xml.editorialgroup do |a|
    a.bureau ( node.attr("bureau#{suffix}") || "T")
    ["", "sub", "work"].each do |p|
      next unless node.attr("#{p}group#{suffix}")

      type = node.attr("#{p}grouptype#{suffix}")
      a.send "#{p}group", **attr_code(type: type) do |g|
        metadata_committee2(node, g, suffix, p)
      end
    end
  end
end
metadata_committee2(node, group, suffix, prefix) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 99
def metadata_committee2(node, group, suffix, prefix)
  group.name node.attr("#{prefix}group#{suffix}")
  node.attr("#{prefix}groupacronym#{suffix}") and
    group.acronym node.attr("#{prefix}groupacronym#{suffix}")
  if node.attr("#{prefix}groupyearstart#{suffix}")
    group.period do |p|
      p.start node.attr("#{prefix}groupyearstart#{suffix}")
      node.attr("#{prefix}groupacronym#{suffix}") and
        p.end node.attr("#{prefix}groupyearend#{suffix}")
    end
  end
end
metadata_ext(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 241
def metadata_ext(node, xml)
  metadata_doctype(node, xml)
  metadata_subdoctype(node, xml)
  metadata_committee(node, xml)
  metadata_ics(node, xml)
  metadata_recommendationstatus(node, xml)
  metadata_ip_notice(node, xml)
  metadata_techreport(node, xml)
  structured_id(node, xml)
end
metadata_id(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 112
def metadata_id(node, xml)
  provisional_id(node, xml)
  itu_id(node, xml)
  recommendation_id(node, xml)
end
metadata_ip_notice(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 190
def metadata_ip_notice(node, xml)
  xml.ip_notice_received (node.attr("ip-notice-received") || "false")
end
metadata_keywords(node, xml) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 107
def metadata_keywords(node, xml)
  return unless node.attr("keywords")

  node.attr("keywords").split(/, */).sort.each_with_index do |kw, i|
    kw_out = i.zero? ? Metanorma::Utils.strict_capitalize_first(kw) : kw
    xml.keyword kw_out
  end
end
metadata_meeting(mtg, acronym, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 215
def metadata_meeting(mtg, acronym, xml)
  xml.meeting **attr_code(acronym: acronym) do |m|
    m << mtg
  end
end
metadata_meeting_date(val, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 221
def metadata_meeting_date(val, xml)
  xml.meeting_date do |m|
    d = val.split("/")
    if d.size > 1
      m.from d[0]
      m.to d[1]
    else
      m.on d[0]
    end
  end
end
metadata_recommendationstatus(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 176
def metadata_recommendationstatus(node, xml)
  return unless node.attr("recommendation-from")

  xml.recommendationstatus do |s|
    s.from node.attr("recommendation-from")
    s.to node.attr("recommendation-to") if node.attr("recommendation-to")
    if node.attr("approval-process")
      s.approvalstage **{ process: node.attr("approval-process") } do |a|
        a << node.attr("approval-status")
      end
    end
  end
end
metadata_series(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 161
def metadata_series(node, xml)
  node.attr("series") and
    xml.series **{ type: "main" } do |s|
      s.title node.attr("series")
    end
  node.attr("series1") and
    xml.series **{ type: "secondary" } do |s|
      s.title node.attr("series1")
    end
  node.attr("series2") and
    xml.series **{ type: "tertiary" } do |s|
      s.title node.attr("series2")
    end
end
metadata_status(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 8
def metadata_status(node, xml)
  stage = (node.attr("status") || node.attr("docstage") || "published")
  stage = "draft" if node.attributes.has_key?("draft")
  xml.status do |s|
    s.stage stage
  end
end
metadata_techreport(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 206
def metadata_techreport(node, xml)
  a = node.attr("meeting") and
    metadata_meeting(a, node.attr("meeting-acronym"), xml)
  a = node.attr("meeting-place") and xml.meeting_place a
  a = node.attr("meeting-date") and metadata_meeting_date(a, xml)
  a = node.attr("intended-type") and xml.intended_type a
  a = node.attr("source") and xml.source a
end
numbers_validate(xmldoc) click to toggle source

Editing Guidelines 9.4.3 Supplanted by rendering

# File lib/asciidoctor/itu/validate.rb, line 69
def numbers_validate(xmldoc)
end
olist(node) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 42
def olist(node)
  id = Metanorma::Utils::anchor_or_uuid(node)
  noko do |xml|
    xml.ol **attr_code(id: id, class: node.attr("class")) do |xml_ol|
      node.items.each { |item| li(xml_ol, item) }
    end
  end.join("\n")
end
other_title_defaultlang(node, xml, type) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 53
def other_title_defaultlang(node, xml, type)
  a = node.attr(type) || node.attr("#{type}-#{@lang}")
  xml.title **attr_code(title_attr(type.sub(/-title/, ""), @lang)) do |t|
    t << Metanorma::Utils::asciidoc_sub(a)
  end
end
other_title_otherlangs(node, xml, type) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 60
def other_title_otherlangs(node, xml, type)
  node.attributes.each do |k, v|
    next unless m = /^#{type}-(?<lang>.+)$/.match(k)
    next if m[:lang] == @lang

    xml.title **attr_code(title_attr(type.sub(/-title/, ""),
                                     m[:lang])) do |t|
      t << Metanorma::Utils::asciidoc_sub(v)
    end
  end
end
outputs(node, ret) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 51
def outputs(node, ret)
  File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
  presentation_xml_converter(node).convert("#{@filename}.xml")
  html_converter(node).convert("#{@filename}.presentation.xml",
                               nil, false, "#{@filename}.html")
  doc_converter(node).convert("#{@filename}.presentation.xml",
                              nil, false, "#{@filename}.doc")
  node.attr("no-pdf") or
    pdf_converter(node)&.convert("#{@filename}.presentation.xml",
                                 nil, false, "#{@filename}.pdf")
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 146
def pdf_converter(node)
  IsoDoc::ITU::PdfConvert.new(html_extract_attributes(node))
end
personal_role(node, contrib, suffix) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/front.rb, line 233
def personal_role(node, contrib, suffix)
  if node.attr("role#{suffix}")&.downcase == "rapporteur"
    contrib.role "raporteur", **{ type: "editor" }
  else
    super
  end
end
presentation_xml_converter(node) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 138
def presentation_xml_converter(node)
  IsoDoc::ITU::PresentationXMLConvert.new(html_extract_attributes(node))
end
provisional_id(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 118
def provisional_id(node, xml)
  return unless node.attr("provisional-name")

  xml.docidentifier **{ type: "ITU-provisional" } do |i|
    i << node.attr("provisional-name")
  end
end
pub_class(bib) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 173
def pub_class(bib)
  return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ITU']")
  return 1 if bib.at("#{PUBLISHER}[name = 'International "\
                     "Telecommunication Union']")
  return 2 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
  return 2 if bib.at("#{PUBLISHER}[name = 'International Organization "\
                     "for Standardization']")
  return 3 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
  return 3 if bib.at("#{PUBLISHER}[name = 'International "\
                     "Electrotechnical Commission']")
  return 4 if bib.at("./docidentifier[@type][not(@type = 'DOI' or "\
                     "@type = 'metanorma' or @type = 'ISSN' or @type = "\
                     "'ISBN')]")

  5
end
recommendation_id(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 151
def recommendation_id(node, xml)
  return unless node.attr("recommendationnumber")

  node.attr("recommendationnumber").split("/").each do |s|
    xml.docidentifier **{ type: "ITU-Recommendation" } do |i|
      i << s
    end
  end
end
requirement_validate(xmldoc) click to toggle source

Editing Guidelines 7

# File lib/asciidoctor/itu/validate.rb, line 57
def requirement_validate(xmldoc)
  xmldoc.xpath("//preface/*").each do |c|
    extract_text(c).split(/\.\s+/).each do |t|
      /\b(shall|must)\b/i.match(t) and
        @log.add("Style", c, 
                 "Requirement possibly in preface: #{t.strip}")
    end
  end
end
resolution_inline_header(xml) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 11
def resolution_inline_header(xml)
  return unless xml&.at("//bibdata/ext/doctype")&.text == "resolution"

  xml.xpath("//clause//clause").each do |c|
    next if (title = c.at("./title")) && !title&.text&.empty?

    c["inline-header"] = true
  end
end
section_check(xmldoc) click to toggle source

Editing Guidelines 7.2, 7.3

# File lib/asciidoctor/itu/validate.rb, line 122
def section_check(xmldoc)
  xmldoc.at("//bibdata/abstract") or
    @log.add("Style", nil, "No Summary has been provided")
  xmldoc.at("//bibdata/keywords") or
    @log.add("Style", nil, "No Keywords have been provided")
end
section_names_terms_cleanup(xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/cleanup.rb, line 149
def section_names_terms_cleanup(xml)
  super
  replace_title(
    xml, "//terms[@type = 'internal'] | "\
         "//clause[./terms[@type = 'internal']]"\
         "[not(./terms[@type = 'external'])]",
    @i18n&.internal_termsdef
  )
  replace_title(
    xml, "//terms[@type = 'external'] | "\
         "//clause[./terms[@type = 'external']]"\
         "[not(./terms[@type = 'internal'])]",
    @i18n&.external_termsdef
  )
end
section_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/validate.rb, line 106
def section_validate(doc)
  super
  section_check(doc.root)
  unnumbered_check(doc.root)
end
sections_cleanup(xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/cleanup.rb, line 4
def sections_cleanup(xml)
  super
  insert_missing_sections(xml) unless @no_insert_missing_sections
  insert_empty_clauses(xml)
  resolution_inline_header(xml)
end
sectiontype(node, level = true) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 85
def sectiontype(node, level = true)
  ret = super
  hdr = sectiontype_streamline(node&.attr("heading")&.downcase)
  return nil if ret == "terms and definitions" &&
    hdr != "terms and definitions" && node.level > 1
  return nil if ret == "symbols and abbreviated terms" &&
    hdr != "symbols and abbreviated terms" && node.level > 1

  ret
end
sectiontype_streamline(ret) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 73
def sectiontype_streamline(ret)
  case ret
  when "definitions" then "terms and definitions"
  when "abbreviations and acronyms" then "symbols and abbreviated terms"
  when "references" then "normative references"
  when "terms defined elsewhere" then "terms and definitions"
  when "terms defined in this recommendation" then "terms and definitions"
  else
    super
  end
end
smartquotes_cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/cleanup.rb, line 112
def smartquotes_cleanup(xmldoc)
  return super if @smartquotes

  xmldoc.traverse do |n|
    next unless n.text?

    n.replace(HTMLEntities.new.encode(
                n.text.gsub(/\u2019|\u2018|\u201a|\u201b/, "'")
                .gsub(/\u201c|\u201d|\u201e|\u201f/, '"'), :basic
              ))
  end
  xmldoc
end
sort_biblio(bib) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 190
def sort_biblio(bib)
  bib.sort do |a, b|
    sort_biblio_key(a) <=> sort_biblio_key(b)
  end
end
sort_biblio_key(bib) click to toggle source

sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other then standard class (docid class other than DOI &c) then alphanumeric doc id (not DOI &c) then title

# File lib/asciidoctor/itu/cleanup.rb, line 200
def sort_biblio_key(bib)
  pubclass = pub_class(bib)
  id = bib&.at("./docidentifier[not(@type = 'DOI' or @type = "\
               "'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")
  metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
  abbrid = metaid unless /^\[\d+\]$/.match?(metaid)
  type = id["type"] if id
  title = bib&.at("./title[@type = 'main']")&.text ||
    bib&.at("./title")&.text || bib&.at("./formattedref")&.text
  "#{pubclass} :: #{type} :: #{id&.text || metaid} :: #{title}"
end
stage_validate(xmldoc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 18
def stage_validate(xmldoc)
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  %w(in-force superseded in-force-prepublished withdrawn 
  draft).include? stage or
    @log.add("Document Attributes", nil, 
             "#{stage} is not a recognised status")
end
structured_id(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 194
def structured_id(node, xml)
  return unless node.attr("docnumber")

  xml.structuredidentifier do |i|
    i.bureau node.attr("bureau") || "T"
    i.docnumber node.attr("docnumber")
    a = node.attr("annexid") and i.annexid a
    a = node.attr("amendment-number") and i.amendment a
    a = node.attr("corrigendum-number") and i.corrigendum a
  end
end
style(_node, _text) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 69
def style(_node, _text)
  nil
end
style_two_regex_not_prev(n, text, re, re_prev, warning) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 72
def style_two_regex_not_prev(n, text, re, re_prev, warning)
  return if text.nil?
  arr = text.split(/\W+/)
  arr.each_index do |i|
    m = re.match arr[i]
    m_prev = i.zero? ? nil : re_prev.match(arr[i - 1])
    if !m.nil? && m_prev.nil?
      @log.add("Style", n, "#{warning}: #{m[:num]}")
    end
  end
end
symbols_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 165
def symbols_cleanup(xmldoc)
  sym = xmldoc.at("//definitions/title")
  sym and sym&.next_element&.name == "dl" and
    sym.next = "<p>#{@i18n.symbols_boilerplate}</p>"
end
table_cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/cleanup.rb, line 21
def table_cleanup(xmldoc)
  super
  xmldoc.xpath("//thead/tr[1]/th | //thead/tr[1]/td").each do |t|
    text = t.at("./descendant::text()") or next
    text.replace(text.text.capitalize)
  end
end
term_def_subclause_parse(attrs, xml, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/itu/converter.rb, line 96
def term_def_subclause_parse(attrs, xml, node)
  case sectiontype1(node)
  when "terms defined in this recommendation"
    term_def_parse(attrs.merge(type: "internal"), xml, node, false)
  when "terms defined elsewhere"
    term_def_parse(attrs.merge(type: "external"), xml, node, false)
  else
    super
  end
end
term_defs_boilerplate(div, _source, _term, _preface, _isodoc) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 134
def term_defs_boilerplate(div, _source, _term, _preface, _isodoc)
  internal, external = terms_extract(div.parent)
  internal&.next_element&.name == "term" and
    internal.next = "<p>#{@i18n.internal_terms_boilerplate}</p>"
  internal and internal&.next_element == nil and
    internal.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
  external&.next_element&.name == "term" and
    external.next = "<p>#{@i18n.external_terms_boilerplate}</p>"
  external and external&.next_element == nil and
    external.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
  !internal and !external and
    %w(term terms).include? div&.next_element&.name and
    div.next = "<p>#{@i18n.term_def_boilerplate}</p>"
end
termdef_boilerplate_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 126
def termdef_boilerplate_cleanup(xmldoc); end
termdef_style(xmldoc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 129
def termdef_style(xmldoc)
  xmldoc.xpath("//term").each do |t|
    para = t.at("./definition") || return
    term = t.at("./preferred").text
    termdef_warn(term, /^[A-Z][a-z]+/, t, term, "term is not lowercase")
    termdef_warn(para.text, /^[a-z]/, t, term, 
                 "term definition does not start with capital")
    termdef_warn(para.text, /[^.]$/, t, term, 
                 "term definition does not end with period")
  end
end
termdef_warn(text, re, t, term, msg) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 141
def termdef_warn(text, re, t, term, msg)
  re.match(text) && @log.add("Style", t, "#{term}: #{msg}")
end
terms_extract(div) click to toggle source
# File lib/asciidoctor/itu/cleanup.rb, line 128
def terms_extract(div)
  internal = div.at("./terms[@type = 'internal']/title")
  external = div.at("./terms[@type = 'external']/title")
  [internal, external]
end
title(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 44
def title(node, xml)
  title_defaultlang(node, xml)
  title_otherlangs(node, xml)
  %w(subtitle amendment-title corrigendum-title).each do |t|
    other_title_defaultlang(node, xml, t)
    other_title_otherlangs(node, xml, t)
  end
end
title_attr(type, lang = "en") click to toggle source
# File lib/asciidoctor/itu/front.rb, line 16
def title_attr(type, lang = "en")
  { language: lang, format: "text/plain", type: type }
end
title_defaultlang(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 20
def title_defaultlang(node, xml)
  a = node.attr("title") || node.attr("title-#{@lang}")
  xml.title **attr_code(title_attr("main", @lang)) do |t|
    t << (Metanorma::Utils::asciidoc_sub(a) || node.title)
  end
  if a = node.attr("annextitle") || node.attr("annextitle-#{@lang}")
    xml.title **attr_code(title_attr("annex", @lang)) do |t|
      t << Metanorma::Utils::asciidoc_sub(a)
    end
  end
end
title_otherlangs(node, xml) click to toggle source
# File lib/asciidoctor/itu/front.rb, line 32
def title_otherlangs(node, xml)
  node.attributes.each do |k, v|
    next unless /^(annex)?title-(?<lang>.+)$/ =~ k
    next if lang == @lang

    type = /^annex/.match?(k) ? "annex" : "main"
    xml.title **attr_code(title_attr(type, lang)) do |t|
      t << Metanorma::Utils::asciidoc_sub(v)
    end
  end
end
title_validate(_root) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 20
def title_validate(_root)
  nil
end
title_validate1(xmldoc) click to toggle source

Editing Guidelines 6.3

# File lib/asciidoctor/itu/validate.rb, line 38
def title_validate1(xmldoc)
  t = xmldoc.at("//bibdata/title")&.text
  xmldoc.xpath("//bibdata/series/title").each do |s|
    series = s.text.sub(/^[A-Z]: /, "")
    t.downcase.include?(series.downcase) and
      @log.add("Document Attributes", nil, "Title includes series name #{series}")
  end
end
unnumbered_check(xmldoc) click to toggle source
# File lib/asciidoctor/itu/validate.rb, line 112
def unnumbered_check(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  xmldoc.xpath("//clause[@unnumbered = 'true']").each do |c|
    next if doctype == "resolution" and c.parent.name == "sections" and
      !c.at("./preceding-sibling::clause")
    @log.add("Style", c, "Unnumbered clause out of place")
  end
end
validate(doc) click to toggle source
# File lib/asciidoctor/itu/converter.rb, line 63
def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "itu.rng"))
end