class Asciidoctor::CC::Converter

Constants

NON_DL_SYMBOLS_WARNING
ONE_SYMBOLS_WARNING
SECTIONS_XPATH
SEQ

spec of permissible section sequence we skip normative references, it goes to end of list

XML_NAMESPACE
XML_ROOT_TAG

Public Instance Methods

configuration() click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 18
def configuration
  Metanorma::CC.configuration
end
doc_converter(node) click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 56
def doc_converter(node)
  IsoDoc::CC::WordConvert.new(doc_extract_attributes(node))
end
html_converter(node) click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 47
def html_converter(node)
  IsoDoc::CC::HtmlConvert.new(html_extract_attributes(node))
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 22
def metadata_committee(node, xml)
  return unless node.attr("technical-committee")
  xml.editorialgroup do |a|
    a.committee node.attr("technical-committee"),
      **attr_code(type: node.attr("technical-committee-type"))
    i = 2
    while node.attr("technical-committee_#{i}") do
      a.committee node.attr("technical-committee_#{i}"),
        **attr_code(type: node.attr("technical-committee-type_#{i}"))
      i += 1
    end
  end
end
outputs(node, ret) click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 36
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")
    pdf_converter(node)&.convert(@filename + ".presentation.xml", 
                                 nil, false, "#{@filename}.pdf")
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 51
def pdf_converter(node)
  return if node.attr("no-pdf")
  IsoDoc::CC::PdfConvert.new(html_extract_attributes(node))
end
presentation_xml_converter(node) click to toggle source
# File lib/asciidoctor/cc/converter.rb, line 60
def presentation_xml_converter(node)
  IsoDoc::CC::PresentationXMLConvert.new(doc_extract_attributes(node))
end
section_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/cc/validate_section.rb, line 7
def section_validate(doc)
  advisory = doc.root.at("//bibdata/ext[doctype = 'advisory']")
  symbols_validate(doc.root) unless advisory
  sections_sequence_validate(doc.root) unless advisory
  super
end
sections_sequence_validate(root) click to toggle source
# File lib/asciidoctor/cc/validate_section.rb, line 72
def sections_sequence_validate(root)
  names = root.xpath(SECTIONS_XPATH)
  names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val])
  n = names[0]
  names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val])
  if n&.at("./self::introduction")
    names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val])
  end
  names = seqcheck(names, SEQ[3][:msg], SEQ[3][:val])
  n = names.shift
  if n&.at("./self::definitions")
    n = names.shift
  end
  if n.nil? || n.name != "clause"
    @log.add("Style", nil, "Document must contain at least one clause")
  end
  n&.at("./self::clause") ||
    @log.add("Style", nil, "Document must contain clause after "\
                           "Terms and Definitions")
  n&.at("./self::clause[@type = 'scope']") &&
    @log.add("Style", nil,
             "Scope must occur before Terms and Definitions")
  n = names.shift
  while n&.name == "clause"
    n&.at("./self::clause[@type = 'scope']")
    @log.add("Style", nil,
             "Scope must occur before Terms and Definitions")
    n = names.shift
  end
  unless %w(annex references).include? n&.name
    @log.add("Style", nil,
             "Only annexes and references can follow clauses")
  end
  while n&.name == "annex"
    n = names.shift
    if n.nil?
      @log.add("Style", nil, "Document must include (references) "\
                             "Normative References")
    end
  end
  n&.at("./self::references[@normative = 'true']") ||
    @log.add("Style", nil, "Document must include (references) "\
                           "Normative References")
  n = names&.shift
  n&.at("./self::references[@normative = 'false']") ||
    @log.add("Style", nil,
             "Final section must be (references) Bibliography")
  names.empty? ||
    @log.add("Style", nil,
             "There are sections after the final Bibliography")
end
seqcheck(names, msg, accepted) click to toggle source
# File lib/asciidoctor/cc/validate_section.rb, line 32
def seqcheck(names, msg, accepted)
  n = names.shift
  return [] if n.nil?

  test = accepted.map { |a| n.at(a) }
  if test.all?(&:nil?)
    @log.add("Style", nil, msg)
  end
  names
end
style_warning(node, msg, text = nil) click to toggle source
# File lib/asciidoctor/cc/validate_section.rb, line 124
def style_warning(node, msg, text = nil)
  return if @novalid

  w = msg
  w += ": #{text}" if text
  @log.add("Style", node, w)
end
symbols_validate(root) click to toggle source
# File lib/asciidoctor/cc/validate_section.rb, line 20
def symbols_validate(root)
  f = root.xpath("//definitions")
  f.empty? && return
  (f.size == 1) || @log.add("Style", f.first, ONE_SYMBOLS_WARNING)
  f.first.elements.each do |e|
    unless e.name == "dl"
      @log.add("Style", f.first, NON_DL_SYMBOLS_WARNING)
      return
    end
  end
end