module Asciidoctor::Standoc::Front

Public Instance Methods

committee_component(compname, node, out) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 10
def committee_component(compname, node, out)
  out.send compname.gsub(/-/, "_"), node.attr(compname),
           **attr_code(number: node.attr("#{compname}-number"),
                       type: node.attr("#{compname}-type"))
  i = 2
  while node.attr(compname + "_#{i}")
    out.send compname.gsub(/-/, "_"), node.attr(compname + "_#{i}"),
             **attr_code(number: node.attr("#{compname}-number_#{i}"),
                         type: node.attr("#{compname}-type_#{i}"))
    i += 1
  end
end
csv_split(text, delim = ";") click to toggle source

, “ => ,” : CSV definition does not deal with space followed by quote at start of field

# File lib/asciidoctor/standoc/front_contributor.rb, line 49
def csv_split(text, delim = ";")
  return if text.nil?

  CSV.parse_line(text&.gsub(/#{delim} "(?!")/, "#{delim}\""),
                 liberal_parsing: true,
                 col_sep: delim)&.compact&.map(&:strip)
end
datetypes() click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 72
def datetypes
  %w{ published accessed created implemented obsoleted
      confirmed updated issued circulated unchanged received
      vote-started vote-ended announced }
end
default_publisher() click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 157
def default_publisher
  nil
end
metadata(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 152
def metadata(node, xml)
  title node, xml
  metadata_source(node, xml)
  metadata_id(node, xml)
  metadata_other_id(node, xml)
  metadata_date(node, xml)
  metadata_author(node, xml)
  metadata_publisher(node, xml)
  metadata_version(node, xml)
  metadata_note(node, xml)
  metadata_language(node, xml)
  metadata_script(node, xml)
  metadata_status(node, xml)
  metadata_copyright(node, xml)
  metadata_relations(node, xml)
  metadata_series(node, xml)
  metadata_classifications(node, xml)
  metadata_keywords(node, xml)
  xml.ext do
    metadata_ext(node, xml)
  end
end
metadata_author(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 57
def metadata_author(node, xml)
  csv_split(node.attr("publisher") || default_publisher || "")
    &.each do |p|
    xml.contributor do |c|
      c.role **{ type: "author" }
      c.organization do |a|
        organization(a, p, false, node, !node.attr("publisher"))
      end
    end
  end
  personal_author(node, xml)
end
metadata_classifications(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 144
def metadata_classifications(node, xml)
  csv_split(node.attr("classification"), ",")&.each do |c|
    vals = c.split(/:/, 2)
    vals.size == 1 and vals = ["default", vals[0]]
    xml.classification vals[1], type: vals[0]
  end
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 40
def metadata_committee(node, xml)
  return unless node.attr("technical-committee")

  xml.editorialgroup do |a|
    committee_component("technical-committee", node, a)
  end
end
metadata_date(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 78
def metadata_date(node, xml)
  datetypes.each { |t| metadata_date1(node, xml, t) }
  node.attributes.each_key do |a|
    next unless a == "date" || /^date_\d+$/.match(a)

    type, date = node.attr(a).split(/ /, 2)
    type or next
    xml.date **{ type: type } do |d|
      d.on date
    end
  end
end
metadata_date1(node, xml, type) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 65
def metadata_date1(node, xml, type)
  date = node.attr("#{type}-date")
  date and xml.date **{ type: type } do |d|
    d.on date
  end
end
metadata_doctype(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 182
def metadata_doctype(node, xml)
  xml.doctype doctype(node)
end
metadata_ext(node, ext) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 175
def metadata_ext(node, ext)
  metadata_doctype(node, ext)
  metadata_subdoctype(node, ext)
  metadata_committee(node, ext)
  metadata_ics(node, ext)
end
metadata_getrelation(node, xml, type, desc = nil) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 122
def metadata_getrelation(node, xml, type, desc = nil)
  docs = node.attr(desc || type) || return
  HTMLEntities.new.decode(docs).split(/;\s*/).each do |d|
    id = d.split(/,\s*/)
    xml.relation **{ type: relation_normalise(type) } do |r|
      desc.nil? or r.description relation_normalise(desc)
      fetch_ref(r, d, nil, **{}) or r.bibitem do |b|
        b.title id[1] || "--"
        b.docidentifier id[0]
      end
    end
  end
end
metadata_ics(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 48
def metadata_ics(node, xml)
  ics = node.attr("library-ics")
  ics&.split(/,\s*/)&.each do |i|
    xml.ics { |elem| elem.code i }
  end
end
metadata_id(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 10
def metadata_id(node, xml)
  part, subpart = node&.attr("partnumber")&.split(/-/)
  id = node.attr("docnumber") || ""
  id += "-#{part}" if part
  id += "-#{subpart}" if subpart
  xml.docidentifier id
  xml.docnumber node.attr("docnumber")
end
metadata_keywords(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 136
def metadata_keywords(node, xml)
  return unless node.attr("keywords")

  node.attr("keywords").split(/,\s*/).each do |kw|
    xml.keyword kw
  end
end
metadata_language(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 91
def metadata_language(node, xml)
  xml.language (node.attr("language") || "en")
end
metadata_note(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 190
def metadata_note(node, xml); end
metadata_other_id(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 19
def metadata_other_id(node, xml)
  a = node.attr("isbn") and xml.docidentifier a, type: "ISBN"
  a = node.attr("isbn10") and xml.docidentifier a, type: "ISBN10"
end
metadata_publisher(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 165
def metadata_publisher(node, xml)
  publishers = node.attr("publisher") || default_publisher || return
  csv_split(publishers)&.each do |p|
    xml.contributor do |c|
      c.role **{ type: "publisher" }
      c.organization do |a|
        organization(a, p, true, node, !node.attr("publisher"))
      end
    end
  end
end
metadata_relations(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 108
def metadata_relations(node, xml)
  relaton_relations.each do |t|
    metadata_getrelation(node, xml, t)
  end
  relaton_relation_descriptions.each do |k, v|
    metadata_getrelation(node, xml, v, k)
  end
end
metadata_script(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 95
def metadata_script(node, xml)
  xml.script (node.attr("script") ||
              default_script(node.attr("language")))
end
metadata_series(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 192
def metadata_series(node, xml); end
metadata_source(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 55
def metadata_source(node, xml)
  node.attr("uri") && xml.uri(node.attr("uri"))
  node.attr("xml-uri") && xml.uri(node.attr("xml-uri"), type: "xml")
  node.attr("html-uri") && xml.uri(node.attr("html-uri"), type: "html")
  node.attr("pdf-uri") && xml.uri(node.attr("pdf-uri"), type: "pdf")
  node.attr("doc-uri") && xml.uri(node.attr("doc-uri"), type: "doc")
  node.attr("relaton-uri") && xml.uri(node.attr("relaton-uri"),
                                      type: "relaton")
end
metadata_status(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 32
def metadata_status(node, xml)
  xml.status do |s|
    s.stage (node.attr("status") || node.attr("docstage") || "published")
    node.attr("docsubstage") and s.substage node.attr("docsubstage")
    node.attr("iteration") and s.iteration node.attr("iteration")
  end
end
metadata_subdoctype(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 186
def metadata_subdoctype(node, xml)
  s = node.attr("docsubtype") and xml.subdoctype s
end
metadata_version(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 24
def metadata_version(node, xml)
  xml.edition node.attr("edition") if node.attr("edition")
  xml.version do |v|
    v.revision_date node.attr("revdate") if node.attr("revdate")
    v.draft node.attr("draft") if node.attr("draft")
  end
end
org_abbrev() click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 161
def org_abbrev
  {}
end
org_address(node, person) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 34
def org_address(node, person)
  node.attr("pub-address") and person.address do |ad|
    ad.formattedAddress do |f|
      f << node.attr("pub-address").gsub(/ \+\n/, "<br/>")
    end
  end
  node.attr("pub-phone") and person.phone node.attr("pub-phone")
  node.attr("pub-fax") and
    person.phone node.attr("pub-fax"), **{ type: "fax" }
  node.attr("pub-email") and person.email node.attr("pub-email")
  node.attr("pub-uri") and person.uri node.attr("pub-uri")
end
organization(org, orgname, is_pub, node = nil, default_org = nil) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 23
def organization(org, orgname, is_pub, node = nil, default_org = nil)
  abbrevs = org_abbrev
  n = abbrevs.invert[orgname] and orgname = n
  org.name orgname
  default_org and a = node.attr("subdivision") and org.subdivision a
  abbr = org_abbrev[orgname]
  default_org && b = node.attr("subdivision-abbr") and abbr = b
  abbr and org.abbreviation abbr
  is_pub && node and org_address(node, org)
end
person_address(node, suffix, xml) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 135
def person_address(node, suffix, xml)
  if node.attr("address#{suffix}")
    xml.address do |ad|
      ad.formattedAddress do |f|
        f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
      end
    end
  elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
    person_address_components(node, suffix, xml)
  end
end
person_address_components(node, suffix, xml) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 147
def person_address_components(node, suffix, xml)
  xml.address do |ad|
    s = node.attr("street#{suffix}") and ad.street s
    s = node.attr("city#{suffix}") and ad.city s
    s = node.attr("state#{suffix}") and ad.state s
    s = node.attr("country#{suffix}") and ad.country s
    s = node.attr("postcode#{suffix}") and ad.postcode s
  end
end
person_affiliation(node, _xml, suffix, person) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 117
def person_affiliation(node, _xml, suffix, person)
  node.attr("affiliation#{suffix}") and person.affiliation do |a|
    a.organization do |o|
      person_organization(node, suffix, o)
    end
  end
end
person_name(node, _xml, suffix, person) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 105
def person_name(node, _xml, suffix, person)
  person.name do |n|
    if node.attr("fullname#{suffix}")
      n.completename node.attr("fullname#{suffix}")
    else
      n.forename node.attr("givenname#{suffix}")
      n.initial node.attr("initials#{suffix}")
      n.surname node.attr("surname#{suffix}")
    end
  end
end
person_organization(node, suffix, xml) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 125
def person_organization(node, suffix, xml)
  xml.name node.attr("affiliation#{suffix}")
  abbr = node.attr("affiliation_abbrev#{suffix}") and
    xml.abbreviation abbr
  csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
    xml.subdivision s
  end
  person_address(node, suffix, xml)
end
personal_author(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 70
def personal_author(node, xml)
  (node.attr("fullname") || node.attr("surname")) and
    personal_author1(node, xml, "")
  i = 2
  while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
    personal_author1(node, xml, "_#{i}")
    i += 1
  end
end
personal_author1(node, xml, suffix) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 94
def personal_author1(node, xml, suffix)
  xml.contributor do |c|
    personal_role(node, c, suffix)
    c.person do |p|
      person_name(node, xml, suffix, p)
      person_affiliation(node, xml, suffix, p)
      personal_contact(node, suffix, p)
    end
  end
end
personal_contact(node, suffix, person) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 85
def personal_contact(node, suffix, person)
  node.attr("phone#{suffix}") and person.phone node.attr("phone#{suffix}")
  node.attr("fax#{suffix}") and
    person.phone node.attr("fax#{suffix}"), **{ type: "fax" }
  node.attr("email#{suffix}") and person.email node.attr("email#{suffix}")
  node.attr("contributor-uri#{suffix}") and
    person.uri node.attr("contributor-uri#{suffix}")
end
personal_role(node, contrib, suffix) click to toggle source
# File lib/asciidoctor/standoc/front_contributor.rb, line 80
def personal_role(node, contrib, suffix)
  type = node.attr("role#{suffix}")&.downcase || "author"
  contrib.role **{ type: type }
end
relation_normalise(type) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 117
def relation_normalise(type)
  type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
    .sub(/-in$/, "In")
end
relaton_relation_descriptions() click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 104
def relaton_relation_descriptions
  {}
end
relaton_relations() click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 100
def relaton_relations
  %w(part-of translated-from)
end
title(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 194
def title(node, xml)
  title_english(node, xml)
  title_otherlangs(node, xml)
end
title_english(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 199
def title_english(node, xml)
  ["en"].each do |lang|
    at = { language: lang, format: "text/plain" }
    xml.title **attr_code(at) do |t|
      t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
                                           node.attr("title-en")) ||
      node.title)
    end
  end
end
title_otherlangs(node, xml) click to toggle source
# File lib/asciidoctor/standoc/front.rb, line 210
def title_otherlangs(node, xml)
  node.attributes.each do |k, v|
    next unless /^title-(?<titlelang>.+)$/ =~ k
    next if titlelang == "en"

    xml.title v, { language: titlelang, format: "text/plain" }
  end
end