class Asciidoctor::NIST::Converter

Constants

CALL_FOR_PATENT_CLAIMS
NIST_PREFIX_REFS
PATENT_DISCLOSURE_NOTICE1
PATENT_DISCLOSURE_NOTICE2
REF_SECTIONS_TO_VALIDATE
SERIES
SERIES_ABBR
TERM_CLAUSE
XML_NAMESPACE
XML_ROOT_TAG

Public Instance Methods

MMMddyyyy(isodate) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 63
def MMMddyyyy(isodate)
  return nil if isodate.nil?
  Date.parse(isodate).strftime("%B %d, %Y")
end
acknowledgements_parse(attrs, xml, node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 129
def acknowledgements_parse(attrs, xml, node)
  xml.acknowledgements **attr_code(attrs) do |xml_section|
    xml_section << node.content
  end
end
add_id_parts(args, long) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 84
def add_id_parts(args, long)
  args[:series] and series_name = id_series_name(args, (long ? :long : :short))
  dn = (series_name || "NIST #{args[:series]}")  + " " + args[:id]
  dn += " Volume #{args[:vol]}" if args[:vol]
  dn += "," if args[:vol] && args[:revision]
  dn += " Revision #{args[:revision]}" if args[:revision]
  dn += "/Upd #{args[:update]}:#{args[:year]}" if args[:update]
  stage = status_abbr(args[:stage], args[:iter]) and dn += " (#{stage})"
  dn += " (#{MMMddyyyy(args[:date])})" if args[:date]
  dn
end
add_id_parts_mr(args) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 120
def add_id_parts_mr(args)
  ret = ["NIST"]
  args[:series] and ret << id_series_name(args, :mr)&.sub(/^NIST /, "")
  stage = status_abbr(args[:stage], nil) || ""
  stage += "[-#{args[:iter]}]" if args[:iter]
  ret << stage unless stage.empty?
  ret << args[:id]
  ret += id_parts_mr(args)
  ret += id_editions_mr(args)
  ret << id_lang_mr(args)
  args[:update] and ret << "upd-#{args[:update]}:#{args[:year]}"
  ret.join(".")
end
annex_rename(xmldoc) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 10
def annex_rename(xmldoc)
  return unless xmldoc.xpath("//references").size == 1
  replace_title(xmldoc, "//annex[references]", @i18n&.normref, true)
end
asciidoc_sub(text) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 23
def asciidoc_sub(text)
  Metanorma::Utils::asciidoc_sub(text)
end
audience_parse(attrs, xml, node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 135
def audience_parse(attrs, xml, node)
  xml.audience **attr_code(attrs) do |xml_section|
    xml_section << node.content
  end
end
bibdata_validate(doc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 13
def bibdata_validate(doc)
  doctype_validate(doc)
  stage_validate(doc)
  substage_validate(doc)
  iteration_validate(doc)
  series_validate(doc)
end
bibliography_annex_parse(attrs, xml, node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 178
def bibliography_annex_parse(attrs, xml, node)
  attrs1 = attrs.merge(id: "_" + UUIDTools::UUID.random_create)
  xml.annex **attr_code(attrs1) do |xml_section|
    xml_section.title { |t| t << node.title }
    @biblio = true
    xml.references **attr_code(attrs.merge(normative: true)) do |r|
      r << node.content
    end
  end
  @biblio = false
end
bibliography_parse(a, xml, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 172
def bibliography_parse(a, xml, node)
  @biblioasappendix and node.level == 1 and
    return bibliography_annex_parse(a, xml, node)
  super
end
boilerplate_file(xmldoc) click to toggle source
# File lib/asciidoctor/nist/boilerplate.rb, line 104
def boilerplate_file(xmldoc)
  File.join(@libdir, @cswp ? "nist_intro_cswp.xml" : "nist_intro.xml")
end
boilerplate_isodoc(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/boilerplate.rb, line 97
def boilerplate_isodoc(xmldoc)
  conv = super
  conv.i18n.set("nist_division", @nistdivision)
  conv.i18n.set("nist_division_address", @nistdivisionaddress)
  conv
end
callforpatentclaims(x, preface) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 75
def callforpatentclaims(x, preface)
  return if @cswp
  if @callforpatentclaims
    docemail = x&.at("//uri[@type = 'email']")&.text || "???"
    docnumber = x&.at("//docnumber")&.text || "???"
    status = x&.at("//bibdata/status/stage")&.text
    published = status.nil? || /^final/.match(status)
    preface.add_child patent_text(published, docemail, docnumber)
  end
end
clause_parse(attrs, xml, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 123
def clause_parse(attrs, xml, node)
  role = node.role || node.attr("style")
  attrs[:executivesummary] = true if role == "executive-summary"
  super
end
cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/cleanup.rb, line 4
def cleanup(xmldoc)
  sourcecode_cleanup(xmldoc)
  annex_rename(xmldoc)
  super
end
conformancetesting_parse(attrs, xml, node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 141
def conformancetesting_parse(attrs, xml, node)
  xml.conformancetesting **attr_code(attrs) do |xml_section|
    xml_section << node.content
  end
end
content_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/validate.rb, line 8
def content_validate(doc)
  super
  bibdata_validate(doc.root)
end
datetypes() click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/front.rb, line 9
def datetypes
  super + %w(abandoned superseded)
end
default_publisher() click to toggle source
# File lib/asciidoctor/nist/front.rb, line 70
def default_publisher
  "National Institute of Standards and Technology"
end
dlist(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 58
def dlist(node)
  role = node.role || node.attr("style")
  return glossary(node) if role == "glossary"
  super
end
doc_converter(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 224
def doc_converter(node)
  IsoDoc::NIST::WordConvert.new(doc_extract_attributes(node))
end
doctype(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 90
def doctype(node)
  d = super || "standard"
  d =  "standard" if d == "article" # article is Asciidoctor default
  d
end
doctype_validate(xmldoc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 21
def doctype_validate(xmldoc)
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
  %w(standard).include? doctype or
    @log.add("Document Attributes", nil, 
             "#{doctype} is not a recognised document type")
end
errata(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 45
def errata(node)
  table = errata1(node)
  noko do |xml|
    xml.errata do |errata|
      table.each do |entry|
        errata.row do |row|
          errata_row(row, entry)
        end
      end
    end
  end
end
errata1(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 26
def errata1(node)
  cols = []
  node.rows[:head][-1].each { |c| cols << c.text.downcase }
  table = []
  node.rows[:body].each do |r|
    row = {}
    r.each_with_index { |c, i| row[cols[i]] = c.content.join("") }
    table << row
  end
  table
end
errata_row(row, entry) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 38
def errata_row(row, entry)
  row.date { |x| x << entry["date"] }
  row.type { |x| x << entry["type"] }
  row.change { |x| x << entry["change"] }
  row.pages { |x| x << entry["pages"] }
end
fetch_ref(xml, code, year, **opts) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 211
def fetch_ref(xml, code, year, **opts)
  code.sub!(Regexp.new("^(#{NIST_PREFIX_REFS}) "), "NIST \\1 ")
  super
end
get_all_nist_refs(docxml) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 126
def get_all_nist_refs(docxml)
  ret = {}
  docxml.xpath("//bibitem[not(ancestor::bibitem)]").each do |ref|
    #next unless ref.at("./docidentifier[@type = 'NIST']")
    ret[ref["id"]] = {}
    ret[ref["id"]][:xref] = ref&.at("./docidentifier[not(@type = 'DOI')]")&.text or next
    ret[ref["id"]][:trunc] = truncate_nist_ref(ret[ref["id"]][:xref])
  end
  ret
end
glossary(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 73
def glossary(node)
  noko do |xml|
    xml.dl **{id: Metanorma::Utils::anchor_or_uuid(node),
              type: "glossary"} do |xml_dl|
      node.items.each do |terms, dd|
        dt(terms, xml_dl)
        dd(dd, xml_dl)
      end
    end
  end.join("\n")
end
html_converter(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 220
def html_converter(node)
  IsoDoc::NIST::HtmlConvert.new(html_extract_attributes(node))
end
id_args(node, dn0) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 22
def id_args(node, dn0)
  return nil unless dn0
  {
    id: dn0,
    series: node.attr("series"),
    subseries: node.attr("series-title") || node.attr("series-abbrev"),
    subseries_abbr: node.attr("series-abbrev"),
    subseries_mr: node.attr("series-mrprefix") || node.attr("series-abbrev"),
    edition: node.attr("edition"),
    version: node.attr("version"),
    revision: node.attr("revision"),
    update: node.attr("update"),
    year: (node.attr("copyright-year") || node.attr("updated-date") ||
           node.attr("revdate") || node.attr("circulated-date") || 
           Date.today.year.to_s).sub(/^(....).*$/, "\\1"),
    vol: node.attr("volume"),
    part: node.attr("part") || node.attr("part-number"),
    section: node.attr("section") || node.attr("section-number"),
    supplement: node.attr("supplement") || node.attr("supplement-number"),
    index: node.attr("index") || node.attr("index-number"),
    stage: node.attr("status") || node.attr("docstage"),
    iter: node.attr("iteration"),
    language: node.attr("language") || "en",
    date: /^draft/.match(node.attr("status") || node.attr("docstage")) ?
    (node.attr("circulated-date") || node.attr("revdate")) :
    node.attr("updated-date")
  }
end
id_editions_mr(args) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 106
def id_editions_mr(args)
  part = []
  part << "e-#{args[:edition]}" if args[:edition]
  part << "r-#{args[:revision]}" if args[:revision]
  part << "ver-#{args[:version]}" if args[:version]
  part
end
id_lang_mr(args) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 114
def id_lang_mr(args)
  ret = args[:language].split(/,\s*/).map do |l|
    ISO_639.find(l).alpha3
  end.join(",")
end
id_parts_mr(args) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 96
def id_parts_mr(args)
  part = []
  part << "v-#{args[:vol]}" if args[:vol]
  part << "pt-#{args[:part]}" if args[:part]
  part << "sec-#{args[:section]}" if args[:section]
  part << "sup-#{args[:supplement]}" if args[:supplement]
  part << "indx-#{args[:index]}" if args[:index]
  part
end
id_series_name(args, type) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 72
def id_series_name(args, type)
  if args[:series] == "nist-csts"
    return ret = case type
                 when :long then args[:subseries] 
                 when :short then args[:subseries_abbr]
                 when :mr then args[:subseries_mr]
                 end
  end
  type == :long ?
    SERIES.dig(args[:series].to_sym) : SERIES_ABBR.dig(args[:series].to_sym)
end
init(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 96
def init(node)
  @callforpatentclaims = node.attr("call-for-patent-claims")
  @commitmenttolicence = node.attr("commitment-to-licence")
  @patentcontact = node.attr("patent-contact")
  @biblioasappendix = node.attr("biblio-as-appendix")
  @nistdivision = node.attr("nist-division") ||
    "Computer Security Division, Information Technology Laboratory"
  @nistdivisionaddress = node.attr("nist-division-address") ||
    "100 Bureau Drive (Mail Stop 8930) Gaithersburg, MD 20899-8930"
  @series = node.attr("series")
  @cswp = %w(nist-cswp nist-csts).include?(@series)
  super
  @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{{"
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}}"
end
introduction_validate(doc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 76
def introduction_validate(doc)
  intro = doc.at("//sections/clause/title")
  intro&.text == "Introduction" or
    @log.add("Style", intro, 
             "First section of document body should be Introduction, "\
             "not #{intro&.text}")
end
iteration_validate(xmldoc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 43
def iteration_validate(xmldoc)
  iteration = xmldoc&.at("//bibdata/status/iteration")&.text or return
  %w(final).include? iteration.downcase or /^\d+$/.match(iteration) or
    @log.add("Document Attributes", nil, 
             "#{iteration} is not a recognised iteration")
end
make_preface(x, s) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 97
def make_preface(x, s)
  preface = s.add_previous_sibling("<preface/>").first
  move_sections_into_preface(x, preface)
  make_abstract(x, s)
  summ = x.at("//executivesummary") and preface.add_child summ.remove
end
makexml(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 85
def makexml(node)
  @draft = node.attributes.has_key?("draft")
  super
end
metadata_author(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 66
def metadata_author(node, xml)
  personal_author(node, xml)
end
metadata_commentperiod(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 139
def metadata_commentperiod(node, xml)
  from = node.attr("comment-from") or return
  to = node.attr("comment-to")
  extended = node.attr("comment-extended")
  xml.commentperiod do |c|
    c.from from
    c.to to if to
    c.extended extended if extended
  end
end
metadata_committee(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 89
def metadata_committee(node, xml)
  return unless node.attr("technical-committee") || node.attr("subcommittee") ||
    node.attr("workgroup") || node.attr("workinggroup")

  xml.editorialgroup do |a|
    c = node.attr("technical-committee") and a.committee(c)
    c = node.attr("subcommittee") and
      a.subcommittee(c, **attr_code(type: node.attr("subcommittee-type"),
                                    number: node.attr("subcommittee-number")))
    c = (node.attr("workgroup") || node.attr("workinggroup")) and
      a.workgroup(c,
                  **attr_code(type: node.attr("workgroup-type"), number: node.attr("workgroup-number")))
  end
end
metadata_ext(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 240
def metadata_ext(node, xml)
  metadata_doctype(node, xml)
  metadata_subdoctype(node, xml)
  metadata_committee(node, xml)
  metadata_commentperiod(node, xml)
end
metadata_getrelation(node, xml, type, desc = nil) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/front.rb, line 161
def metadata_getrelation(node, xml, type, desc = nil)
  if type == "obsoleted-by" && desc.nil? &&
      node.attr("superseding-status")
    metadata_superseding_doc(node, xml)
  end
  super
end
metadata_id(node, xml) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 6
def metadata_id(node, xml)
  did = node.attr("docidentifier")
  dn = node.attr("docnumber")
  @series == "nist-cswp" && !node.attr("docnumber") and
    dn = Iso690Render.MMMddyyyy(node.attr("issued-date"))
  metadata_id_compose(node, xml, dn, did)
  xml.docnumber node.attr("docnumber") ||
    did&.sub(/^[^0-9]*/, "")&.sub(/[ -].*$/, "")
end
metadata_id_compose(node, xml, dn0, did) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 51
def metadata_id_compose(node, xml, dn0, did)
  if did
    xml.docidentifier did, **attr_code(type: "NIST")
    xml.docidentifier unabbreviate(did), **attr_code(type: "nist-long")
  else
    args = id_args(node, dn0) || return
    xml.docidentifier add_id_parts(args, false), **attr_code(type: "NIST")
    xml.docidentifier add_id_parts(args, true), **attr_code(type: "nist-long")
    xml.docidentifier add_id_parts_mr(args), **attr_code(type: "nist-mr")
  end
end
metadata_note(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 233
def metadata_note(node, xml)
  note = node.attr("bib-additional-note") and xml.note note, **{ type: "additional-note" }
  note = node.attr("bib-withdrawal-note") and xml.note note, **{ type: "withdrawal-note" }
  note = node.attr("bib-withdrawal-announcement-link") and
    xml.note note, **{ type: "withdrawal-announcement-link" }
end
metadata_publisher(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 74
def metadata_publisher(node, xml)
  publishers = node.attr("publisher") || default_publisher
  csv_split(publishers)&.each do |p|
    xml.contributor do |c|
      c.role **{ type: "publisher" }
      c.organization do |a|
        a.name p
        if p == default_publisher
          d = node.attr("nist-division") and a.subdivision d
        end
      end
    end
  end
end
metadata_series(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 119
def metadata_series(node, xml)
  series = node.attr("series") || "nist-sp"
  series and xml.series **{ type: "main" } do |s|
    s.title (SERIES.dig(series.to_sym) || series)
    SERIES_ABBR.dig(series.to_sym) and s.abbreviation SERIES_ABBR.dig(series.to_sym)
  end
  metadata_subseries(node, xml)
end
metadata_source(node, xml) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/front.rb, line 113
def metadata_source(node, xml)
  super
  node.attr("doc-email") and xml.uri(node.attr("doc-email"), type: "email")
  node.attr("doi") and xml.uri(node.attr("doi"), type: "doi")
end
metadata_status(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 104
def metadata_status(node, xml)
  status = node.attr("status") || node.attr("docstage") || "final"
  xml.status do |s|
    s.stage status 
    s.substage (node.attr("substage") || "active")
    s.iteration node.attr("iteration") if node.attr("iteration") 
  end
end
metadata_subseries(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 128
def metadata_subseries(node, xml)
  title = node.attr("series-title")
  abbrev = node.attr("series-abbrev")
  return unless (title || abbrev)

  xml.series **{ type: "secondary" } do |s|
    title and s.title title
    abbrev and s.abbreviation abbrev
  end
end
metadata_superseding_authors(b, node) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 220
def metadata_superseding_authors(b, node)
  node.attr("superseding-authors") and node.attr("superseding-authors").split(/,\s*/).each do |a|
    b.contributor do |c|
      c.role nil, **{ type: "author" }
      c.person do |p|
        p.name do |f|
          f.completename a
        end
      end
    end
  end
end
metadata_superseding_dates(b, node) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 193
def metadata_superseding_dates(b, node)
  cdate = node.attr("superseding-circulated-date") and b.date **{ type: "circulated" } do |d|
    d.on cdate
  end
  cdate = node.attr("superseding-issued-date") and b.date **{ type: "issued" } do |d|
    d.on cdate
  end
end
metadata_superseding_doc(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 169
def metadata_superseding_doc(node, xml)
  xml.relation **{ type: "obsoletedBy" } do |r|
    r.bibitem **{ type: "standard" } do |b|
      metadata_superseding_titles(b, node)
      doi = node.attr("superseding-doi") and b.uri doi, **{ type: "doi" }
      url = node.attr("superseding-url") and b.uri url, **{ type: "uri" }
      metadata_superseding_ids(b, xml)
      metadata_superseding_authors(b, node)
      metadata_superseding_dates(b, node)
      b.status do |s|
        s.stage node.attr("superseding-status")
        iter = node.attr("superseding-iteration") and s.iteration iter
      end
    end
  end
end
metadata_superseding_ids(b, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 186
def metadata_superseding_ids(b, xml)
  did = xml&.parent&.at("./ancestor::bibdata/docidentifier[@type = 'NIST']")&.text
  didl = xml&.parent&.at("./ancestor::bibdata/docidentifier[@type = 'nist-long']")&.text
  b.docidentifier did, **{ type: "NIST" }
  b.docidentifier didl, **{ type: "nist-long" }
end
metadata_superseding_titles(b, node) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 202
def metadata_superseding_titles(b, node)
  if node.attr("superseding-title")
    b.title **{ type: "main" } do |t|
      t << asciidoc_sub(node.attr("superseding-title"))
    end
    node.attr("superseding-subtitle") and b.title **{ type: "subtitle" } do |t|
      t << asciidoc_sub(node.attr("superseding-subtitle"))
    end
  else
    b.title **{ type: "main" } do |t|
      t << (asciidoc_sub(node.attr("title-main")) || node.title)
    end
    node.attr("title-sub") and b.title **{ type: "subtitle" } do |t|
      t << asciidoc_sub(node.attr("title-sub"))
    end
  end
end
metadata_version(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 13
def metadata_version(node, xml)
  xml.edition node.attr("edition") if node.attr("edition")
  xml.edition "Revision #{node.attr("revision")}" if node.attr("revision")
  xml.edition "Version #{node.attr("version")}" if node.attr("version")
  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
move_clauses_into_preface(x, preface) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 42
def move_clauses_into_preface(x, preface)
  move_clauses_into_preface1(x, preface)
  move_execsummary_into_preface(x, preface)
end
move_clauses_into_preface1(x, preface) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 47
def move_clauses_into_preface1(x, preface)
  x.xpath("//acknowledgements[@preface]").each { |c| c.delete("preface") }
  x.xpath("//clause[@preface]").each do |c|
    c.delete("preface")
    title = c&.at("./title")&.text.downcase
    c.name = "reviewernote" if title == "note to reviewers"
    c.name = "executivesummary" if title == "executive summary"
    preface.add_child c.remove
  end
end
move_execsummary_into_preface(x, preface) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 58
def move_execsummary_into_preface(x, preface)
  x.xpath("//clause[@executivesummary]").each do |c|
    c.delete("executivesummary")
    title = c&.at("./title")&.text.downcase
    c.name = "executivesummary"
    preface.add_child c.remove
  end
end
move_sections_into_preface(x, preface) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 67
def move_sections_into_preface(x, preface)
  foreword = x.at("//foreword") and preface.add_child foreword.remove
  intro = x.at("//introduction") and preface.add_child intro.remove
  move_clauses_into_preface(x, preface)
  intro = x.at("//acknowledgements") and preface.add_child intro.remove
  callforpatentclaims(x, preface)
end
nistvariable_insert(n) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 171
def nistvariable_insert(n)
  acc = []
  n.text.split(/((?<!\{)\{{3}(?!\{)|(?<!\})\}{3}(?!\}))/).each_slice(4).
    map do |a|
    acc << Nokogiri::XML::Text.new(a[0], n.document)
    next unless a.size == 4
    acc << Nokogiri::XML::Node.new("nistvariable", n)
    acc[-1].content = a[2]
  end
  acc
end
olist(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 64
def olist(node)
  id = Metanorma::Utils::anchor_or_uuid(node)
  noko do |xml|
    xml.ol **attr_code(id: id, class: node.attr("class")) do |xml_ol|
      node.items.each { |item| li(xml_ol, item) }
    end
  end.join("\n")
end
outputs(node, ret) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 112
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
patent_text(published, docemail, docnumber) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 86
def patent_text(published, docemail, docnumber)
  patent = (!published ? CALL_FOR_PATENT_CLAIMS :
            (@commitmenttolicence ? PATENT_DISCLOSURE_NOTICE1 :
             PATENT_DISCLOSURE_NOTICE2)).clone
  patent.gsub(/ITL-POINT-OF_CONTACT/, published ?
              (@patentcontact || docemail) :
              (@patentcontact ||
               "#{docemail}, with the Subject: #{docnumber} "\
               "Call for Patent Claims"))
end
pdf_converter(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 228
def pdf_converter(node)
  return nil if node.attr("no-pdf")
  IsoDoc::NIST::PdfConvert.new(html_extract_attributes(node))
end
presentation_xml_converter(node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 216
def presentation_xml_converter(node)
  IsoDoc::NIST::PresentationXMLConvert.new(html_extract_attributes(node))
end
recognised_series_validate(series) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 56
def recognised_series_validate(series)
  found = false
  SERIES.each { |_, v| found = true if v == series }
  found or @log.add("Document Attributes", nil, "#{series} is not a recognised series")
end
reference_names(docxml) click to toggle source

handle NIST references separately doc identifier format, NIST: NIST SP 800-87-1 {Vol./Volume 8}| {Rev./Revision 8}|(Month YYYY)

Calls superclass method
# File lib/asciidoctor/nist/cleanup.rb, line 107
def reference_names(docxml)
  super
  ret = get_all_nist_refs(docxml)
  tallies = ret.inject(Hash.new(0)) do |memo, (k, v)|
    memo[v[:trunc]] += 1 unless v[:trunc].nil?
    memo
  end
  ret.each do |k, v|
    tallies[v[:trunc]] == 1 and @anchors[k][:xref] = v[:trunc]
    @anchors&.dig(k, :xref)&.sub!(/^NIST /, "")
  end
end
references_validate(doc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 93
def references_validate(doc)
  f = doc.xpath(REF_SECTIONS_TO_VALIDATE)
  names = f.map { |s| s&.text }
  return if names.empty?
  return if names == ["References"]
  return if names == ["Bibliography"]
  return if names == ["References", "Bibliography"]
  @log.add("Style", nil, 
           "Reference clauses #{names.join(', ')} do not follow "\
           "expected pattern in NIST")
end
refitem(xml, item, node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 205
def refitem(xml, item, node)
  item.sub!(Regexp.new("^(<ref[^>]+>)\\[(#{NIST_PREFIX_REFS}) "),
            "\\1[NIST \\2 ")
  super
end
relaton_relation_descriptions() click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/front.rb, line 154
def relaton_relation_descriptions
  super.merge(
    { "supersedes" => "obsoletes",
      "superseded-by" => "obsoleted-by" }
  )
end
relaton_relations() click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/front.rb, line 150
def relaton_relations
  super + %w(obsoletes obsoleted-by)
end
section_names_refs_cleanup(x) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 183
def section_names_refs_cleanup(x)
  replace_title(x, "//bibliography//references[@normative = 'true']",
                @i18n&.normref, true)
  replace_title(x, "//bibliography//references[@normative = 'false']",
                @i18n&.bibliography, true)
end
section_names_terms_cleanup(x) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 190
def section_names_terms_cleanup(x)
  replace_title(x, "//definitions[@type = 'symbols']", @i18n&.symbols)
  replace_title(x, "//definitions[@type = 'abbreviated_terms']", @i18n&.abbrev)
  replace_title(x, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
  replace_title(x, "//sections//terms#{SYMnoABBR} | //sections//clause[.//terms]#{SYMnoABBR}",
                @i18n&.termsdefsymbols, true)
  replace_title(x, "//sections//terms#{ABBRnoSYM} | //sections//clause[.//terms]#{ABBRnoSYM}",
                @i18n&.termsdefabbrev, true)
  replace_title(x, "//sections//terms#{SYMABBR} | //sections//clause[.//terms]#{SYMABBR}",
                @i18n&.termsdefsymbolsabbrev, true)
  replace_title(x, "//sections//terms#{NO_SYMABBR} | //sections//clause[.//terms]#{NO_SYMABBR}",
                @i18n&.termsdefsymbolsabbrev, true)
  replace_title(
    x, "//sections//terms[not(.//definitions)] | //sections//clause[.//terms][not(.//definitions)]",
    @i18n&.termsdef, true)
end
section_validate(doc) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/validate.rb, line 87
def section_validate(doc)
  super
  introduction_validate(doc)
  references_validate(doc)
end
sections_cleanup(x) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/cleanup.rb, line 35
def sections_cleanup(x)
  super
  x.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end
sectiontype_streamline(ret) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 151
def sectiontype_streamline(ret)
  case ret
  when "glossary", "terminology"
    "terms and definitions"
  when "introduction"
    "donotrecognise_introduction"
  when "normative references"
    "bibliography"
  else
    super
  end
end
series_validate(xmldoc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 50
def series_validate(xmldoc)
  series = xmldoc&.at("//bibdata/series[@type = 'main']/title")&.text or return
  recognised_series_validate(series)
  subseries_validate(series, xmldoc)
end
sort_biblio(bib) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 141
def sort_biblio(bib)
  @citation_order = {}
  bib.document.xpath("//xref | //origin").each_with_index do |x, i|
    cit = x["target"] || x["bibitemid"]
    next unless refid? cit
    @citation_order[cit] ||= i
  end
  bib.sort do |a, b|
    sort_biblio_key(a) <=> sort_biblio_key(b)
  end
end
sort_biblio_key(bib) click to toggle source

if numeric citation, order by appearance. if alphanumeric, sort alphabetically if identifier, zero-pad numeric component for NIST ids

# File lib/asciidoctor/nist/cleanup.rb, line 155
def sort_biblio_key(bib)
  if metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text&.gsub(%r{[\[\]]}, "")
    key = /^\[\d+\]$/.match(metaid) ? ( @citation_order[metaid] % "09%d" ) : metaid
  elsif metaid = bib&.at("./docidentifier[@type = 'NIST']")&.text
    key = metaid.sub(/-(\d+)/) {|m| sprintf "-%09d", ($1.to_i) }
  elsif metaid = bib&.at("./docidentifier[not(@type = 'DOI' or "\
                         "@type = 'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")&.text
    key = metaid.sub(/-(\d+)/) {|m| sprintf "-%09d", ($1.to_i) }
  else # no usable docid
    key = "000000000" + bib["id"]
  end
  title = bib&.at("./title[@type = 'main']")&.text ||
    bib&.at("./title")&.text || bib&.at("./formattedref")&.text
  "#{key} :: #{title}"
end
sourcecode_cleanup(xmldoc) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/cleanup.rb, line 15
def sourcecode_cleanup(xmldoc)
  xmldoc.xpath("//sourcecode").each do |x|
    x.traverse do |n|
      next unless n.text?
      next unless /\{\{\{/.match(n.text)
      n.replace(Nokogiri::XML::NodeSet.new(n.document, nistvariable_insert(n)))
    end
  end
  super
end
stage_validate(xmldoc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 28
def stage_validate(xmldoc)
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  %w(draft-internal draft-wip draft-prelim draft-public draft-approval
  final final-review).include? stage or
  @log.add("Document Attributes", nil, 
           "#{stage} is not a recognised stage")
end
status_abbr(stage, iter) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 68
def status_abbr(stage, iter)
  IsoDoc::NIST::Metadata.new(nil, nil, @i18n).status_abbr(stage, iter)
end
style(n, t) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 147
def style(n, t)
  return
end
subseries_validate(series, xmldoc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 62
def subseries_validate(series, xmldoc)
  subseries = xmldoc&.at("//bibdata/series[@type = 'secondary']")
  csts = series == "NIST Cybersecurity Technical Specification"
  subseries && !csts and
    @log.add("Document Attributes", nil, "Subseries are not permitted on the series #{series}")
  !subseries && csts and
    @log.add("Document Attributes", nil, "Subseries are required on the series #{series}")
end
substage_validate(xmldoc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 36
def substage_validate(xmldoc)
  substage = xmldoc&.at("//bibdata/status/substage")&.text or return
  %w(active retired withdrawn).include? substage or
    @log.add("Document Attributes", nil, 
             "#{substage} is not a recognised substage")
end
table(node) click to toggle source
Calls superclass method
# File lib/asciidoctor/nist/converter.rb, line 20
def table(node)
  role = node.role || node.attr("style")
  return errata(node) if role == "errata"
  super
end
term_def_parse(attrs, xml, node, toplevel) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 164
def term_def_parse(attrs, xml, node, toplevel)
  if node.attr("style") == "appendix" && node.level == 1
    terms_annex_parse(attrs, xml, node)
  else
    clause_parse(attrs, xml, node)
  end
end
termdef_subclause_cleanup(xmldoc) click to toggle source

skip annex/terms/terms, which is empty node

# File lib/asciidoctor/nist/cleanup.rb, line 27
def termdef_subclause_cleanup(xmldoc)
  xmldoc.xpath("//terms[terms]").each do |t|
    next if t.parent.name == "terms"
    t.children.each { |n| n.parent = t.parent }
    t.remove
  end
end
terms_annex_parse(attrs, xml, node) click to toggle source
# File lib/asciidoctor/nist/converter.rb, line 190
def terms_annex_parse(attrs, xml, node)
  attrs1 = attrs.merge(id: "_" + UUIDTools::UUID.random_create)
  xml.annex **attr_code(attrs1) do |xml_section|
    xml_section.title { |name| name << node.title }
    xml_section.terms **attr_code(attrs) do |terms|
      (s = node.attr("source")) && s.split(/,/).each do |s1|
        terms.termdocsource(nil, **attr_code(bibitemid: s1))
      end
      terms << node.content
    end
  end
end
title(node, xml) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 57
def title(node, xml)
  ["en"].each do |lang|
    at = { language: lang, format: "text/plain" }
    title_main(node, xml, at)
    title_subtitle(node, xml, at)
    title_document_class(node, xml, at)
  end
end
title_document_class(node, t, at) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 38
def title_document_class(node, t, at)
  return unless node.attr("title-document-class")

  t.title(**attr_code(at.merge(type: "document-class"))) do |t1|
    t1 << asciidoc_sub(node.attr("title-document-class"))
  end
end
title_main(node, t, at) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 46
def title_main(node, t, at)
  t.title(**attr_code(at.merge(type: "main"))) do |t1|
    t1 << (asciidoc_sub(node.attr("title-main")) || node.title)
  end
  if node.attr("title-main-short")
    t.title(**attr_code(at.merge(type: "short-title"))) do |t1|
      t1 << asciidoc_sub(node.attr("title-main-short"))
    end
  end
end
title_subtitle(node, t, at) click to toggle source
# File lib/asciidoctor/nist/front.rb, line 27
def title_subtitle(node, t, at)
  return unless node.attr("title-sub")

  t.title(**attr_code(at.merge(type: "subtitle"))) do |t1|
    t1 << asciidoc_sub(node.attr("title-sub"))
  end
  node.attr("title-sub-short") and t.title(**attr_code(at.merge(type: "short-subtitle"))) do |t1|
    t1 << asciidoc_sub(node.attr("title-sub-short"))
  end
end
title_validate(root) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 4
def title_validate(root)
  nil
end
truncate_nist_ref(text) click to toggle source
# File lib/asciidoctor/nist/cleanup.rb, line 120
def truncate_nist_ref(text)
  #text.sub(/\s\((January|February|March|April|May|June|July|August|
  #                September|October|November|December)\s\d\d\d\d\).*$/x, "")
  text
end
unabbreviate(did) click to toggle source
# File lib/asciidoctor/nist/front_id.rb, line 16
def unabbreviate(did)
  SERIES_ABBR.each { |k, v| did = did.sub(/^#{v} /, "#{k} ") }
  SERIES.each { |k, v| did = did.sub(/^#{k} /, "#{v} ") }
  did
end
validate(doc) click to toggle source
# File lib/asciidoctor/nist/validate.rb, line 71
def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "nist.rng"))
end