class Asciidoctor::Csand::Converter

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

Public Instance Methods

bibdata_validate(doc) click to toggle source
# File lib/asciidoctor/csand/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/csand/validate.rb, line 4
def content_validate(doc)
  super
  bibdata_validate(doc.root)
end
doctype(node) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 92
def doctype(node)
  d = node.attr("doctype")
  unless %w{guidance proposal standard report whitepaper charter policy glossary case-study}.include? d
    warn "#{d} is not a legal document type: reverting to 'standard'"
    d = "standard"
  end
  d
end
document(node) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 101
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")
    pdf_converter(node).convert filename unless node.attr("nodoc")
    word_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/csand/converter.rb, line 134
def html_converter(node)
  IsoDoc::Csand::HtmlConvert.new(html_extract_attributes(node))
end
makexml(node) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 79
def makexml(node)
  result = ["<?xml version='1.0' encoding='UTF-8'?>\n<csand-standard>"]
  @draft = node.attributes.has_key?("draft")
  result << noko { |ixml| front node, ixml }
  result << noko { |ixml| middle node, ixml }
  result << "</csand-standard>"
  result = textcleanup(result)
  ret1 = cleanup(Nokogiri::XML(result))
  validate(ret1) unless @novalid
  ret1.root.add_namespace(nil, CSAND_NAMESPACE)
  ret1
end
metadata_author(node, xml) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 18
def metadata_author(node, xml)
  xml.contributor do |c|
    c.role **{ type: "author" }
    c.organization do |a|
      a.name "Cloud Security Alliance"
    end
  end
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 36
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
metadata_id(node, xml) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 50
def metadata_id(node, xml)
  docstatus = node.attr("status")
  dn = node.attr("docnumber")
  if docstatus
    abbr = IsoDoc::Csand::Metadata.new("en", "Latn", {}).
      status_abbr(docstatus)
    dn = "#{dn}(#{abbr})" unless abbr.empty?
  end
  node.attr("copyright-year") and dn += ":#{node.attr("copyright-year")}"
  xml.docidentifier dn, **{type: "csand"}
  xml.docnumber { |i| i << node.attr("docnumber") }
end
metadata_publisher(node, xml) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 27
def metadata_publisher(node, xml)
  xml.contributor do |c|
    c.role **{ type: "publisher" }
    c.organization do |a|
      a.name "Cloud Security Alliance"
    end
  end
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 137
def pdf_converter(node)
  IsoDoc::Csand::PdfConvert.new(html_extract_attributes(node))
end
sections_cleanup(x) click to toggle source
Calls superclass method
# File lib/asciidoctor/csand/converter.rb, line 123
def sections_cleanup(x)
  super
  x.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end
stage_validate(xmldoc) click to toggle source
# File lib/asciidoctor/csand/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/csand/converter.rb, line 130
def style(n, t)
  return
end
title_validate(root) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 75
def title_validate(root)
  nil
end
validate(doc) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 117
def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "csand.rng"))
end
word_converter(node) click to toggle source
# File lib/asciidoctor/csand/converter.rb, line 140
def word_converter(node)
  IsoDoc::Csand::WordConvert.new(doc_extract_attributes(node))
end