class Asciidoctor::Unece::Converter

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

Constants

XML_NAMESPACE
XML_ROOT_TAG

Public Instance Methods

admonition_attrs(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/converter.rb, line 198
def admonition_attrs(node)
  attr_code(super.merge(
    "unnumbered": node.option?("unnumbered"),
    "subsequence": node.attr("subsequence"),
  ))
end
bibdata_validate(doc) click to toggle source
# File lib/asciidoctor/unece/validate.rb, line 9
def bibdata_validate(doc)
  stage_validate(doc)
end
content_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/validate.rb, line 4
def content_validate(doc)
  super
  bibdata_validate(doc.root)
end
doc_extract_attributes(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/converter.rb, line 167
def doc_extract_attributes(node)
  super.merge(toc: node.attributes.has_key?("toc"))
end
doctype(node) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 127
def doctype(node)
  d = node.attr("doctype")
  unless %w{plenary recommendation addendum communication corrigendum reissue
    agenda budgetary sec-gen-notes expert-report resolution}.include? d
    warn "#{d} is not a legal document type: reverting to 'recommendation'"
    d = "recommendation"
  end
  d
end
document(node) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 137
def document(node)
  init(node)
  ret1 = makexml(node)
  ret = ret1.to_xml(indent: 2)
  unless node.attr("nodoc") || !node.attr("docfile")
    filename = node.attr("docfile").gsub(/\.adoc/, ".xml").
      gsub(%r{^.*/}, "")
    File.open(filename, "w") { |f| f.write(ret) }
    html_converter(node).convert filename unless node.attr("nodoc")
    word_converter(node).convert filename unless node.attr("nodoc")
    pdf_converter(node).convert filename unless node.attr("nodoc")
  end
  @files_to_delete.each { |f| FileUtils.rm f }
  ret
end
html_converter(node) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 171
def html_converter(node)
  IsoDoc::Unece::HtmlConvert.new(html_extract_attributes(node))
end
html_extract_attributes(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/converter.rb, line 163
def html_extract_attributes(node)
  super.merge(toc: node.attributes.has_key?("toc"))
end
makexml(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/converter.rb, line 122
def makexml(node)
  @draft = node.attributes.has_key?("draft")
  super
end
metadata_author(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 18
def metadata_author(node, xml)
  xml.contributor do |c|
    c.role **{ type: "author" }
    c.organization do |a|
      a.name Metanorma::Unece::ORGANIZATION_NAME_SHORT
    end
  end
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 36
def metadata_committee(node, xml)
  return unless node.attr("committee")
  xml.editorialgroup do |a|
    a.committee node.attr("committee"),
      **attr_code(type: node.attr("committee-type"))
    i = 2
    while node.attr("committee_#{i}") do
      a.committee node.attr("committee_#{i}"),
        **attr_code(type: node.attr("committee-type_#{i}"))
      i += 1
    end
  end
end
metadata_distribution(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 84
def metadata_distribution(node, xml)
  xml.distribution node.attr("distribution") if node.attr("distribution")
end
metadata_ext(node, xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/converter.rb, line 111
def metadata_ext(node, xml)
  super
  metadata_distribution(node, xml)
  metadata_session(node, xml)
  metadata_submission_language(node, xml)
end
metadata_id(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 62
def metadata_id(node, xml)
  dn = node.attr("docnumber")
  if docstatus = node.attr("status")
    abbr = IsoDoc::Unece::Metadata.new("en", "Latn", {}).status_abbr(docstatus)
    dn = "#{dn}(#{abbr})" unless abbr.empty?
  end
  xml.docidentifier { |i| i << dn }
  xml.docnumber { |i| i << node.attr("docnumber") }
end
metadata_language(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 101
def metadata_language(node, xml)
  languages = node&.attr("language")&.split(/,[ ]*/) || %w(ar ru en fr zh es)
  languages.each { |l| xml.language l }
end
metadata_publisher(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 27
def metadata_publisher(node, xml)
  xml.contributor do |c|
    c.role **{ type: "publisher" }
    c.organization do |a|
      a.name Metanorma::Unece::ORGANIZATION_NAME_SHORT
    end
  end
end
metadata_session(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 88
def metadata_session(node, xml)
  xml.session do |session|
    session.number node.attr("session") if node.attr("session")
    session.date node.attr("session-date") if node.attr("session-date")
    node&.attr("item-number")&.split(/,[ ]*/)&.each { |i| session.item_number i }
    node&.attr("item-name")&.split(/,[ ]*/)&.each { |i| session.item_name i }
    node&.attr("subitem-name")&.split(/,[ ]*/)&.each { |i| session.subitem_name i }
    session.collaborator node.attr("collaborator") if node.attr("collaborator")
    session.id node.attr("agenda-id") if node.attr("agenda-id")
    session.item_footnote node.attr("item-footnote") if node.attr("item-footnote")
  end
end
metadata_submission_language(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 106
def metadata_submission_language(node, xml)
  languages = node&.attr("submissionlanguage")&.split(/,[ ]*/) || []
  languages.each { |l| xml.submissionlanguage l }
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 179
def pdf_converter(node)
  IsoDoc::Unece::PdfConvert.new(doc_extract_attributes(node))
end
sections_cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/unece/converter.rb, line 183
def sections_cleanup(xmldoc)
  super
  xmldoc.xpath("//clause/p | //annex/p").each do |p|
    cl = Nokogiri::XML::Node.new("clause", xmldoc)
    cl["id"] = p["id"]
    cl["inline-header"]="true" 
    p["id"] = "_" + UUIDTools::UUID.random_create
    p.replace(cl)
    p.parent = cl
    while n = cl.next_element and !%w(p clause).include? n.name
      n.parent = cl
    end
  end
end
stage_validate(xmldoc) click to toggle source
# File lib/asciidoctor/unece/validate.rb, line 13
def stage_validate(xmldoc)
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  %w(proposal working-draft committee-draft draft-standard final-draft
  published withdrawn).include? stage or
    warn "Document Attributes: #{stage} is not a recognised status"
end
style(n, t) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 159
def style(n, t)
  return
end
title(node, xml) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 50
def title(node, xml)
  ["en"].each do |lang|
    xml.title **{ type: "main", language: lang, format: "text/plain" } do |t|
      t << Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("title"))
    end
    node.attr("subtitle") and
      xml.title **{ type: "subtitle", language: lang, format: "text/plain" } do |t|
      t << Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("subtitle"))
    end
  end
end
title_validate(root) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 118
def title_validate(root)
  nil
end
validate(doc) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 153
def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "unece.rng"))
end
word_converter(node) click to toggle source
# File lib/asciidoctor/unece/converter.rb, line 175
def word_converter(node)
  IsoDoc::Unece::WordConvert.new(doc_extract_attributes(node))
end