class Asciidoctor::BIPM::Converter

Public Instance Methods

annex_parse(attrs, xml, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 165
def annex_parse(attrs, xml, node)
  node.option?("unnumbered") and attrs[:unnumbered] = true
  super
end
boilerplate_file(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 189
def boilerplate_file(xmldoc)
  return super unless @jcgm

  File.join(File.dirname(__FILE__), "boilerplate-jcgm-en.xml")
end
clause_parse(attrs, xml, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 160
def clause_parse(attrs, xml, node)
  node.option?("unnumbered") and attrs[:unnumbered] = true
  super
end
committee_validate(xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 174
def committee_validate(xml)
  committees = Array(configuration&.committees) || return
  committees.empty? and return
  xml.xpath("//bibdata/ext/editorialgroup/committee/variant").each do |c|
    committees.include? c.text or
      @log.add("Document Attributes", nil,
               "#{c.text} is not a recognised committee")
  end
  xml.xpath("//bibdata/ext/editorialgroup/committee/@acronym").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/bipm/converter.rb, line 9
def configuration
  Metanorma::BIPM.configuration
end
default_publisher() click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 17
def default_publisher
  org_name_long
end
document(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 218
def document(node)
  @jcgm = node.attr("committee-acronym") == "JCGM"
  super
end
html_converter(node) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 232
def html_converter(node)
  IsoDoc::BIPM::HtmlConvert.new(html_extract_attributes(node))
end
inline_anchor_xref_attrs(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 148
def inline_anchor_xref_attrs(node)
  flags = %w(pagenumber nosee nopage).each_with_object({}) do |w, m|
    if /#{w}%/.match?(node.text)
      node.text = node.text.sub(/#{w}%/, "")
      m[w] = true
    end
  end
  ret = super
  flags.each_key { |k| ret[k.to_sym] = true }
  ret
end
jcgm_untitled_sections_cleanup(xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 200
def jcgm_untitled_sections_cleanup(xml)
  xml.xpath("//clause//clause | //annex//clause | //introduction/clause")
    .each do |c|
    next if !c&.at("./title")&.text&.empty?

    c["inline-header"] = true
  end
end
mathml_mi_italics() click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 213
def mathml_mi_italics
  { uppergreek: false, upperroman: false,
    lowergreek: false, lowerroman: true }
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 25
def metadata_committee(node, xml)
  return unless node.attr("committee-en") || node.attr("committee-fr")

  xml.editorialgroup do |a|
    metadata_committee1(node, a)
    i = 2
    while node.attr("committee-en_#{i}") || node.attr("committee-fr_#{i}")
      metadata_committee2(node, a, i)
      i += 1
    end
    metadata_workgroup(node, a)
  end
end
metadata_committee1(node, xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 39
def metadata_committee1(node, xml)
  xml.committee **attr_code(acronym:
                            node.attr("committee-acronym")) do |c|
    e = node.attr("committee-en") and
      c.variant e, language: "en", script: "Latn"
    e = node.attr("committee-fr") and
      c.variant e, language: "fr", script: "Latn"
  end
end
metadata_committee2(node, xml, num) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 49
def metadata_committee2(node, xml, num)
  xml.committee **attr_code(acronym:
                            node.attr("committee-acronym_#{num}")) do |c|
    %w(en fr).each do |lg|
      e = node.attr("committee-#{lg}_#{num}") and
        c.variant e, language: lg, script: "Latn"
    end
  end
end
metadata_relations(node, xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 72
def metadata_relations(node, xml)
  super
  relation_supersedes_self(node, xml, "")
  i = 2
  while relation_supersedes_self(node, xml, "_#{i}")
    i += 1
  end
end
metadata_workgroup(node, xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 59
def metadata_workgroup(node, xml)
  xml.workgroup(node.attr("workgroup"),
                **attr_code(acronym: node.attr("workgroup-acronym")))
  i = 2
  while node.attr("workgroup_#{i}")
    xml.workgroup(
      node.attr("workgroup_#{i}"),
      **attr_code(acronym: node.attr("workgroup-acronym_#{i}"))
    )
    i += 1
  end
end
ol_attrs(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 170
def ol_attrs(node)
  super.merge(attr_code(start: node.attr("start")))
end
org_abbrev() click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 21
def org_abbrev
  { org_name_long => configuration.organization_name_short }
end
org_name_long() click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 13
def org_name_long
  configuration.organization_name_long[@lang]
end
outputs(node, ret) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 223
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")
  pdf_converter(node)&.convert("#{@filename}.presentation.xml",
                               nil, false, "#{@filename}.pdf")
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 240
def pdf_converter(node)
  return nil if node.attr("no-pdf")

  IsoDoc::BIPM::PdfConvert.new(doc_extract_attributes(node))
end
personal_role(node, xml, suffix) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 103
def personal_role(node, xml, suffix)
  role = node.attr("role#{suffix}") || "author"
  unless %w(author editor).include?(role.downcase)
    desc = role
    role = "editor"
  end
  xml.role desc, **{ type: role.downcase }
end
presentation_xml_converter(node) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 236
def presentation_xml_converter(node)
  IsoDoc::BIPM::PresentationXMLConvert.new(html_extract_attributes(node))
end
relation_supersedes_self(node, xml, suffix) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 81
def relation_supersedes_self(node, xml, suffix)
  d = node.attr("supersedes-date#{suffix}")
  draft = node.attr("supersedes-draft#{suffix}")
  edition = node.attr("supersedes-edition#{suffix}")
  return false unless d || draft || edition

  relation_supersedes_self1(xml, d, edition, draft)
end
relation_supersedes_self1(xml, date, edition, draft) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 90
def relation_supersedes_self1(xml, date, edition, draft)
  xml.relation **{ type: "supersedes" } do |r|
    r.bibitem do |b|
      date and b.date(date,
                      **{ type: edition ? "published" : "circulated" })
      edition and b.edition edition
      draft and b.version do |v|
        v.draft draft
      end
    end
  end
end
section_names_refs_cleanup(xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 211
def section_names_refs_cleanup(xml); end
section_names_terms_cleanup(xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 209
def section_names_terms_cleanup(xml); end
sections_cleanup(xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 195
def sections_cleanup(xml)
  super
  jcgm_untitled_sections_cleanup(xml) if @jcgm
end
sectiontype(node, level = true) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 141
def sectiontype(node, level = true)
  ret = sectiontype1(node)
  return ret if ret == "terms and definitions"

  super
end
sectiontype_streamline(ret) click to toggle source
Calls superclass method
# File lib/asciidoctor/bipm/converter.rb, line 133
def sectiontype_streamline(ret)
  case ret
  when "introduction" then @jcgm ? "introduction" : "clause"
  else
    super
  end
end
title(node, xml) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 112
def title(node, xml)
  ["en", "fr"].each do |lang|
    at = { language: lang, format: "text/plain" }
    xml.title **attr_code(at.merge(type: "main")) do |t1|
      t1 << Metanorma::Utils::asciidoc_sub(node.attr("title-#{lang}"))
    end
    %w(cover appendix annex part subpart provenance).each do |w|
      typed_title(node, xml, lang, w)
    end
  end
end
typed_title(node, xml, lang, type) click to toggle source
# File lib/asciidoctor/bipm/converter.rb, line 124
def typed_title(node, xml, lang, type)
  at = { language: lang, format: "text/plain" }
  return unless title = node.attr("title-#{type}-#{lang}")

  xml.title **attr_code(at.merge(type: type)) do |t1|
    t1 << Metanorma::Utils::asciidoc_sub(title)
  end
end