class Asciidoctor::Generic::Converter

Constants

EXT_STRUCT
XML_NAMESPACE
XML_ROOT_TAG

Public Instance Methods

baselocation(loc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 22
def baselocation(loc)
  return nil if loc.nil?

  return loc
  File.expand_path(File.join(File.dirname(
                               self.class::_file || __FILE__,
                             ), "..", "..", "..", loc))
end
bibdata_validate(doc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 100
def bibdata_validate(doc)
  stage_validate(doc)
  committee_validate(doc)
end
blank_method(*args) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 131
def blank_method(*args); end
Also aliased as: style, title_validate
boilerplate_file(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 162
def boilerplate_file(xmldoc)
  f = configuration.boilerplate
  f.nil? and return super
  f.is_a? String and return baselocation(f)
  f.is_a? Hash and f[@lang] and return baselocation(f[@lang])
  super
end
boilerplate_isodoc(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 154
def boilerplate_isodoc(xmldoc)
  conv = super
  Metanorma::Generic::Configuration::CONFIG_ATTRS.each do |a|
    conv.meta.set(a, configuration.send(a))
  end
  conv
end
cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 170
def cleanup(xmldoc)
  super
  empty_metadata_cleanup(xmldoc)
  xmldoc
end
committee_validate(xmldoc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 114
def committee_validate(xmldoc)
  committees = Array(configuration&.committees) || return
  committees.empty? and return
  xmldoc.xpath("//bibdata/ext/editorialgroup/committee").each do |c|
    committees.include? c.text or
      @log.add("Document Attributes", nil,
               "#{c.text} is not a recognised committee")
  end
end
configuration() click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 150
def configuration
  Metanorma::Generic.configuration
end
content_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 95
def content_validate(doc)
  super
  bibdata_validate(doc.root)
end
default_publisher() click to toggle source
# File lib/asciidoctor/generic/front.rb, line 4
def default_publisher
  configuration.organization_name_long
end
doc_converter(node) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 146
def doc_converter(node)
  IsoDoc::Generic::WordConvert.new(doc_extract_attributes(node))
end
docidentifier_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 31
def docidentifier_cleanup(xmldoc)
  template = configuration.docid_template ||
    "{{ organization_name_short }} {{ docnumeric }}"
  docid = xmldoc.at("//bibdata/docidentifier")
  id = boilerplate_isodoc(xmldoc).populate_template(template, nil)
  id.empty? and docid.remove or docid.children = id
end
doctype(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 39
def doctype(node)
  d = super
  configuration.doctypes or return d == "article" ?
    (configuration.default_doctype || "standard") : d
  type = configuration.default_doctype ||
    configuration.doctypes.keys.dig(0) || "standard"
  unless configuration.doctypes.keys.include? d
    @log.add("Document Attributes", nil,
             "#{d} is not a legal document type: reverting to '#{type}'")
    d = type
  end
  d
end
document(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 72
def document(node)
  read_config_file(node.attr("customize")) if node.attr("customize")
  super
end
empty_metadata_cleanup(xmldoc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 176
def empty_metadata_cleanup(xmldoc)
  xmldoc.xpath("//bibdata/ext//*").each do |x|
    x.remove if x.children.empty?
  end
end
html_converter(node) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 133
def html_converter(node)
  IsoDoc::Generic::HtmlConvert.new(html_extract_attributes(node))
end
Also aliased as: pdf_converter
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 24
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_doctype(node, xml) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 66
def metadata_doctype(node, xml)
  d = doctype(node)
  xml.doctype d, attr_code(abbreviation: configuration&.doctypes&.dig(d))
end
metadata_ext(node, ext) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/front.rb, line 55
def metadata_ext(node, ext)
  super
  if configuration.metadata_extensions.is_a? Hash
    metadata_ext_hash(node, ext, configuration.metadata_extensions)
  else
    Array(configuration.metadata_extensions).each do |e|
      a = node.attr(e) and ext.send e, a
    end
  end
end
metadata_ext_attrs(hash, node) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 97
def metadata_ext_attrs(hash, node)
  return {} unless hash.is_a?(Hash)
  ret = {}
  hash.each do |k, v|
    next unless v.is_a?(Hash) && v["_attribute"]
    ret[(v["_output"] || k).to_sym] = node.attr(k)
  end
  ret
end
metadata_ext_hash(node, ext, hash) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 73
def metadata_ext_hash(node, ext, hash)
  hash.each do |k, v|
    next if EXT_STRUCT.include?(k) || !v&.is_a?(Hash) && !node.attr(k)
    if v&.is_a?(Hash) && v["_list"]
      csv_split(node.attr(k), ",").each do |val|
        metadata_ext_hash1(k, val, ext, v, node)
      end
    else
      metadata_ext_hash1(k, node.attr(k), ext, v, node)
    end
  end
end
metadata_ext_hash1(key, value, ext, hash, node) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 86
def metadata_ext_hash1(key, value, ext, hash, node)
  return if hash&.is_a?(Hash) && hash["_attribute"]
  is_hash = hash&.is_a?(Hash) &&
      !hash.keys.reject { |n| EXT_STRUCT.include?(n) }.empty?
  return if !is_hash && (value.nil? || value.empty?)
  name = hash&.is_a?(Hash) ? (hash["_output"] || key) : key
  ext.send name, **attr_code(metadata_ext_attrs(hash, node)) do |e|
      is_hash ? metadata_ext_hash(node, e, hash) : (e << value)
  end
end
metadata_id(node, xml) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 47
def metadata_id(node, xml)
  xml.docidentifier **{ type:
                        configuration.organization_name_short } do |i|
    i << "DUMMY"
  end
  xml.docnumber { |i| i << node.attr("docnumber") }
end
metadata_status(node, xml) click to toggle source
# File lib/asciidoctor/generic/front.rb, line 38
def metadata_status(node, xml)
  xml.status do |s|
    s.stage ( node.attr("status") || node.attr("docstage") ||
             configuration.default_stage || "published" )
    x = node.attr("substage") and s.substage x
    x = node.attr("iteration") and s.iteration x
  end
end
org_abbrev() click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/front.rb, line 8
def org_abbrev
  if !configuration.organization_name_long.empty? &&
      !configuration.organization_name_short.empty? &&
      configuration.organization_name_long !=
      configuration.organization_name_short
    { configuration.organization_name_long =>
      configuration.organization_name_short }
  else
    super
  end
end
outputs(node, ret) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 77
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)
Alias for: html_converter
presentation_xml_converter(node) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 137
def presentation_xml_converter(node)
  IsoDoc::Generic::PresentationXMLConvert
    .new(html_extract_attributes(node))
end
read_config_file(path_to_config_file) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 53
def read_config_file(path_to_config_file)
  Metanorma::Generic.configuration
    .set_default_values_from_yaml_file(path_to_config_file)
end
relaton_relations() click to toggle source
# File lib/asciidoctor/generic/front.rb, line 20
def relaton_relations
  Array(configuration.relations) || []
end
sections_cleanup(xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/generic/converter.rb, line 124
def sections_cleanup(xml)
  super
  xml.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end
sectiontype_streamline(ret) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 58
def sectiontype_streamline(ret)
  if configuration&.termsdefs_titles&.map(&:downcase)&.include? ret
    "terms and definitions"
  elsif configuration&.symbols_titles&.map(&:downcase)&.include? ret
    "symbols and abbreviated terms"
  elsif configuration&.normref_titles&.map(&:downcase)&.include? ret
    "normative references"
  elsif configuration&.bibliography_titles&.map(&:downcase)&.include? ret
    "bibliography"
  else
    ret
  end
end
stage_validate(xmldoc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 105
def stage_validate(xmldoc)
  stages = configuration&.stage_abbreviations&.keys || return
  stages.empty? and return
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  stages.include? stage or
    @log.add("Document Attributes", nil,
             "#{stage} is not a recognised status")
end
style(*args)
Alias for: blank_method
title_validate(*args)
Alias for: blank_method
validate(doc) click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 88
def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  baselocation(configuration.validate_rng_file) ||
                  File.join(File.dirname(__FILE__), "generic.rng"))
end
xml_namespace() click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 18
def xml_namespace
  configuration.document_namespace || XML_NAMESPACE
end
xml_root_tag() click to toggle source
# File lib/asciidoctor/generic/converter.rb, line 14
def xml_root_tag
  configuration.xml_root_tag || XML_ROOT_TAG
end