Class: Asciidoctor::NIST::Converter

Inherits:
Standoc::Converter
  • Object
show all
Defined in:
lib/asciidoctor/nist/front.rb,
lib/asciidoctor/nist/cleanup.rb,
lib/asciidoctor/nist/front_id.rb,
lib/asciidoctor/nist/validate.rb,
lib/asciidoctor/nist/converter.rb,
lib/asciidoctor/nist/boilerplate.rb

Constant Summary collapse

TERM_CLAUSE =
"//sections/terms | "\
"//sections/clause[descendant::terms] | "\
"//annex[descendant::terms]".freeze
REF_SECTIONS_TO_VALIDATE =
"//references[not(parent::clause)]/title | "\
"//clause[descendant::references][not(parent::clause)]/title".freeze
XML_ROOT_TAG =
"nist-standard".freeze
XML_NAMESPACE =
"https://www.metanorma.org/ns/nist".freeze
NIST_PREFIX_REFS =
"SP|FIPS"
SERIES =
{
  "nist-ams": "NIST Advanced Manufacturing Series",
  "building-science": "NIST Building Science Series",
  "nist-fips": "NIST Federal Information Processing Standards",
  "nist-gcr": "NIST Grant/Contract Reports",
  "nist-hb": "NIST Handbook",
  "itl-bulletin": "ITL Bulletin",
  "jpcrd": "Journal of Physical and Chemical Reference Data",
  "nist-jres": "NIST Journal of Research",
  "letter-circular": "NIST Letter Circular",
  "nist-monograph": "NIST Monograph",
  "nist-ncstar": "NIST National Construction Safety Team Act Reports",
  "nist-nsrds": "NIST National Standard Reference Data Series",
  "nistir": "NIST Interagency/Internal Report",
  "product-standards": "NIST Product Standards",
  "nist-sp": "NIST Special Publication",
  "nist-tn": "NIST Technical Note",
  "other": "NIST Other",
  "csrc-white-paper": "CSRC White Paper",
  "csrc-book": "CSRC Book",
  "csrc-use-case": "CSRC Use Case",
  "csrc-building-block": "CSRC Building Block",
  "nist-cswp": "NIST Cybersecurity White Paper",
  "nist-csts": "NIST Cybersecurity Technical Specification",
}.freeze
SERIES_ABBR =
{
  "nist-ams": "NIST AMS",
  "building-science": "NIST Building Science Series",
  "nist-fips": "NIST FIPS",
  "nist-gcr": "NISTGCR",
  "nist-hb": "NIST HB",
  "itl-bulletin": "ITL Bulletin",
  "jpcrd": "JPCRD",
  "nist-jres": "NIST JRES",
  "letter-circular": "NIST Letter Circular",
  "nist-monograph": "NIST MN",
  "nist-ncstar": "NIST NCSTAR",
  "nist-nsrds": "NIST NSRDS",
  "nistir": "NISTIR",
  "product-standards": "NIST Product Standards",
  "nist-sp": "NIST SP",
  "nist-tn": "NIST TN",
  "other": "NIST Other",
  "csrc-white-paper": "CSRC White Paper",
  "csrc-book": "CSRC Book",
  "csrc-use-case": "CSRC Use Case",
  "csrc-building-block": "CSRC Building Block",
  "nist-cswp": "NIST CSWP",
  "nist-csts": "NIST CSTS",
}.freeze
CALL_FOR_PATENT_CLAIMS =
"nist-csts": "NIST CSTS",
}.freeze

CALL_FOR_PATENT_CLAIMS = <<~END.freeze
<clause><title>Call for Patent Claims</title>
<p>This public review includes a call for information on essential patent claims (claims whose use would be required for compliance with the guidance or requirements in this Information Technology Laboratory (ITL) draft publication). Such guidance and/or requirements may be directly stated in this ITL Publication or by reference to another publication. This call also includes disclosure, where known, of the existence of pending U.S. or foreign patent applications relating to this ITL draft publication and of any relevant unexpired U.S. or foreign patents.</p>

<p>ITL may require from the patent holder, or a party authorized to make assurances on its behalf, in written or electronic form, either:</p>

<ol type="arabic"><li><p>assurance in the form of a general disclaimer to the effect that such party does not hold and does not currently intend holding any essential patent claim(s); or</p></li>

<li><p>assurance that a license to such essential patent claim(s) will be made available to applicants desiring to utilize the license for the purpose of complying with the guidance or requirements in this ITL draft publication either:</p>

  <ol type="roman"><li><p>under reasonable terms and conditions that are demonstrably free of any unfair discrimination; or</p></li>

  <li><p>without compensation and under reasonable terms and conditions that are demonstrably free of any unfair discrimination.</p></li></ol>
</li></ol>

<p>Such assurance shall indicate that the patent holder (or third party authorized to make assurances on its behalf) will include in any documents transferring ownership of patents subject to the assurance, provisions sufficient to ensure that the commitments in the assurance are binding on the transferee, and that the transferee will similarly include appropriate provisions in the event of future transfers with the goal of binding each successor-in-interest.</p>

<p>The assurance shall also indicate that it is intended to be binding on successors-in-interest regardless of whether such provisions are included in the relevant transfer documents.</p>

<p>Such statements should be addressed to: ITL-POINT-OF_CONTACT.</p>
</clause>
END
PATENT_DISCLOSURE_NOTICE1 =
"nist-cswp": "NIST CSWP",
  "nist-csts": "NIST CSTS",
}.freeze

CALL_FOR_PATENT_CLAIMS = <<~END.freeze
<clause><title>Call for Patent Claims</title>
<p>This public review includes a call for information on essential patent claims (claims whose use would be required for compliance with the guidance or requirements in this Information Technology Laboratory (ITL) draft publication). Such guidance and/or requirements may be directly stated in this ITL Publication or by reference to another publication. This call also includes disclosure, where known, of the existence of pending U.S. or foreign patent applications relating to this ITL draft publication and of any relevant unexpired U.S. or foreign patents.</p>

<p>ITL may require from the patent holder, or a party authorized to make assurances on its behalf, in written or electronic form, either:</p>

<ol type="arabic"><li><p>assurance in the form of a general disclaimer to the effect that such party does not hold and does not currently intend holding any essential patent claim(s); or</p></li>

<li><p>assurance that a license to such essential patent claim(s) will be made available to applicants desiring to utilize the license for the purpose of complying with the guidance or requirements in this ITL draft publication either:</p>

  <ol type="roman"><li><p>under reasonable terms and conditions that are demonstrably free of any unfair discrimination; or</p></li>

  <li><p>without compensation and under reasonable terms and conditions that are demonstrably free of any unfair discrimination.</p></li></ol>
</li></ol>

<p>Such assurance shall indicate that the patent holder (or third party authorized to make assurances on its behalf) will include in any documents transferring ownership of patents subject to the assurance, provisions sufficient to ensure that the commitments in the assurance are binding on the transferee, and that the transferee will similarly include appropriate provisions in the event of future transfers with the goal of binding each successor-in-interest.</p>

<p>The assurance shall also indicate that it is intended to be binding on successors-in-interest regardless of whether such provisions are included in the relevant transfer documents.</p>

<p>Such statements should be addressed to: ITL-POINT-OF_CONTACT.</p>
</clause>
END

PATENT_DISCLOSURE_NOTICE1 = <<~END.freeze
      <clause><title>Patent Disclosure Notice</title>
<p>NOTICE: The Information Technology Laboratory (ITL) has requested that holders of patent claims whose use may be required for compliance with the guidance or requirements of this publication disclose such patent claims to ITL. However, holders of patents are not obligated to respond to ITL calls for patents and ITL has not undertaken a patent search in order to identify which, if any, patents may apply to this publication. </p>
<p>Following the ITL call for the identification of patent claims whose use may be required for compliance with the guidance or requirements of this publication, notice of one or more such claims has been received. </p>
<p>By publication, no position is taken by ITL with respect to the validity or scope of any patent claim or of any rights in connection therewith. The known patent holder(s) has (have), however, provided to NIST a letter of assurance stating either (1) a general disclaimer to the effect that it does (they do) not hold and does (do) not currently intend holding any essential patent claim(s), or (2) that it (they) will negotiate royalty-free or royalty-bearing licenses with other parties on a demonstrably nondiscriminatory basis with reasonable terms and conditions. </p>
<p>Details may be obtained from ITL-POINT-OF_CONTACT. </p>
<p>No representation is made or implied that this is the only license that may be required to avoid patent infringement in the use of this publication. </p>
</clause>
END
PATENT_DISCLOSURE_NOTICE2 =
"csrc-building-block": "CSRC Building Block",
  "nist-cswp": "NIST CSWP",
  "nist-csts": "NIST CSTS",
}.freeze

CALL_FOR_PATENT_CLAIMS = <<~END.freeze
<clause><title>Call for Patent Claims</title>
<p>This public review includes a call for information on essential patent claims (claims whose use would be required for compliance with the guidance or requirements in this Information Technology Laboratory (ITL) draft publication). Such guidance and/or requirements may be directly stated in this ITL Publication or by reference to another publication. This call also includes disclosure, where known, of the existence of pending U.S. or foreign patent applications relating to this ITL draft publication and of any relevant unexpired U.S. or foreign patents.</p>

<p>ITL may require from the patent holder, or a party authorized to make assurances on its behalf, in written or electronic form, either:</p>

<ol type="arabic"><li><p>assurance in the form of a general disclaimer to the effect that such party does not hold and does not currently intend holding any essential patent claim(s); or</p></li>

<li><p>assurance that a license to such essential patent claim(s) will be made available to applicants desiring to utilize the license for the purpose of complying with the guidance or requirements in this ITL draft publication either:</p>

  <ol type="roman"><li><p>under reasonable terms and conditions that are demonstrably free of any unfair discrimination; or</p></li>

  <li><p>without compensation and under reasonable terms and conditions that are demonstrably free of any unfair discrimination.</p></li></ol>
</li></ol>

<p>Such assurance shall indicate that the patent holder (or third party authorized to make assurances on its behalf) will include in any documents transferring ownership of patents subject to the assurance, provisions sufficient to ensure that the commitments in the assurance are binding on the transferee, and that the transferee will similarly include appropriate provisions in the event of future transfers with the goal of binding each successor-in-interest.</p>

<p>The assurance shall also indicate that it is intended to be binding on successors-in-interest regardless of whether such provisions are included in the relevant transfer documents.</p>

<p>Such statements should be addressed to: ITL-POINT-OF_CONTACT.</p>
</clause>
END

PATENT_DISCLOSURE_NOTICE1 = <<~END.freeze
      <clause><title>Patent Disclosure Notice</title>
<p>NOTICE: The Information Technology Laboratory (ITL) has requested that holders of patent claims whose use may be required for compliance with the guidance or requirements of this publication disclose such patent claims to ITL. However, holders of patents are not obligated to respond to ITL calls for patents and ITL has not undertaken a patent search in order to identify which, if any, patents may apply to this publication. </p>
<p>Following the ITL call for the identification of patent claims whose use may be required for compliance with the guidance or requirements of this publication, notice of one or more such claims has been received. </p>
<p>By publication, no position is taken by ITL with respect to the validity or scope of any patent claim or of any rights in connection therewith. The known patent holder(s) has (have), however, provided to NIST a letter of assurance stating either (1) a general disclaimer to the effect that it does (they do) not hold and does (do) not currently intend holding any essential patent claim(s), or (2) that it (they) will negotiate royalty-free or royalty-bearing licenses with other parties on a demonstrably nondiscriminatory basis with reasonable terms and conditions. </p>
<p>Details may be obtained from ITL-POINT-OF_CONTACT. </p>
<p>No representation is made or implied that this is the only license that may be required to avoid patent infringement in the use of this publication. </p>
</clause>
END

PATENT_DISCLOSURE_NOTICE2 = <<~END.freeze
      <clause><title>Patent Disclosure Notice</title>
<p>NOTICE: ITL has requested that holders of patent claims whose use may be required for compliance with the guidance or requirements of this publication disclose such patent claims to ITL. However, holders of patents are not obligated to respond to ITL calls for patents and ITL has not undertaken a patent search in order to identify which, if any, patents may apply to this publication.</p>
<p>As of the date of publication and following call(s) for the identification of patent claims whose use may be required for compliance with the guidance or requirements of this publication, no such patent claims have been identified to ITL.</p>
<p>No representation is made or implied by ITL that licenses are not required to avoid patent infringement in the use of this publication.</p>
</clause>
END

Instance Method Summary collapse

Instance Method Details

#acknowledgements_parse(attrs, xml, node) ⇒ Object



129
130
131
132
133
# 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) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# 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) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# 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) ⇒ Object



10
11
12
13
# 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) ⇒ Object



23
24
25
# File 'lib/asciidoctor/nist/front.rb', line 23

def asciidoc_sub(text)
  Metanorma::Utils::asciidoc_sub(text)
end

#audience_parse(attrs, xml, node) ⇒ Object



135
136
137
138
139
# 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) ⇒ Object



13
14
15
16
17
18
19
# 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) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
# 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) ⇒ Object



172
173
174
175
176
# 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) ⇒ Object



104
105
106
# 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) ⇒ Object



97
98
99
100
101
102
# 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) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# 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) ⇒ Object



123
124
125
126
127
# 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) ⇒ Object



4
5
6
7
8
# File 'lib/asciidoctor/nist/cleanup.rb', line 4

def cleanup(xmldoc)
  sourcecode_cleanup(xmldoc)
  annex_rename(xmldoc)
  super
end

#conformancetesting_parse(attrs, xml, node) ⇒ Object



141
142
143
144
145
# 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) ⇒ Object



8
9
10
11
# File 'lib/asciidoctor/nist/validate.rb', line 8

def content_validate(doc)
  super
  bibdata_validate(doc.root)
end

#datetypesObject



9
10
11
# File 'lib/asciidoctor/nist/front.rb', line 9

def datetypes
  super + %w(abandoned superseded)
end

#default_publisherObject



66
67
68
# File 'lib/asciidoctor/nist/front.rb', line 66

def default_publisher
  "National Institute of Standards and Technology"
end

#dlist(node) ⇒ Object



58
59
60
61
62
# 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) ⇒ Object



224
225
226
# File 'lib/asciidoctor/nist/converter.rb', line 224

def doc_converter(node)
  IsoDoc::NIST::WordConvert.new(doc_extract_attributes(node))
end

#doctype(node) ⇒ Object



90
91
92
93
94
# 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) ⇒ Object



21
22
23
24
25
26
# 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) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



38
39
40
41
42
43
# 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) ⇒ Object



211
212
213
214
# 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) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# 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) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



220
221
222
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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) ⇒ Object



106
107
108
109
110
111
112
# 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) ⇒ Object



114
115
116
117
118
# 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) ⇒ Object



96
97
98
99
100
101
102
103
104
# 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) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# 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) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# 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) ⇒ Object



76
77
78
79
80
81
82
# 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) ⇒ Object



43
44
45
46
47
48
# 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) ⇒ Object



97
98
99
100
101
102
# 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) ⇒ Object



85
86
87
88
# File 'lib/asciidoctor/nist/converter.rb', line 85

def makexml(node)
  @draft = node.attributes.has_key?("draft")
  super
end

#metadata_author(node, xml) ⇒ Object



62
63
64
# File 'lib/asciidoctor/nist/front.rb', line 62

def (node, xml)
  personal_author(node, xml)
end

#metadata_commentperiod(node, xml) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'lib/asciidoctor/nist/front.rb', line 133

def (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) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/asciidoctor/nist/front.rb', line 85

def (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) ⇒ Object



230
231
232
233
234
# File 'lib/asciidoctor/nist/front.rb', line 230

def (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
end

#metadata_getrelation(node, xml, type, desc = nil) ⇒ Object



152
153
154
155
156
157
# File 'lib/asciidoctor/nist/front.rb', line 152

def (node, xml, type, desc = nil)
  if type == "obsoleted-by" and desc.nil? and node.attr("superseding-status")
    (node, xml)
  end
  super
end

#metadata_id(node, xml) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/asciidoctor/nist/front_id.rb', line 6

def (node, xml)
  did = node.attr("docidentifier")
  dn = node.attr("docnumber")
  @series == "nist-cswp" && !node.attr("docnumber") and
    dn = Iso690Render.MMMddyyyy(node.attr("issued-date"))
  (node, xml, dn, did)
  xml.docnumber node.attr("docnumber") ||
    did&.sub(/^[^0-9]*/, "")&.sub(/[ -].*$/, "")
end

#metadata_id_compose(node, xml, dn0, did) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asciidoctor/nist/front_id.rb', line 51

def (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) ⇒ Object



223
224
225
226
227
228
# File 'lib/asciidoctor/nist/front.rb', line 223

def (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) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/asciidoctor/nist/front.rb', line 70

def (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) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/asciidoctor/nist/front.rb', line 114

def (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
  (node, xml)
end

#metadata_source(node, xml) ⇒ Object



108
109
110
111
112
# File 'lib/asciidoctor/nist/front.rb', line 108

def (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) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/asciidoctor/nist/front.rb', line 99

def (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) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/asciidoctor/nist/front.rb', line 123

def (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) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/asciidoctor/nist/front.rb', line 210

def (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) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/asciidoctor/nist/front.rb', line 183

def (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) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/asciidoctor/nist/front.rb', line 159

def (node, xml)
  xml.relation **{ type: "obsoletedBy" } do |r|
    r.bibitem **{ type: "standard" } do |b|
      (b, node)
      doi = node.attr("superseding-doi") and b.uri doi, **{ type: "doi" }
      url = node.attr("superseding-url") and b.uri url, **{ type: "uri" }
      (b, xml)
      (b, node)
      (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) ⇒ Object



176
177
178
179
180
181
# File 'lib/asciidoctor/nist/front.rb', line 176

def (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) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/asciidoctor/nist/front.rb', line 192

def (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) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/asciidoctor/nist/front.rb', line 13

def (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

#MMMddyyyy(isodate) ⇒ Object



63
64
65
66
# 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

#move_clauses_into_preface(x, preface) ⇒ Object



42
43
44
45
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object



58
59
60
61
62
63
64
65
# 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) ⇒ Object



67
68
69
70
71
72
73
# 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) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
# 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) ⇒ Object



64
65
66
67
68
69
70
71
# 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) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# 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) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# 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) ⇒ Object



228
229
230
231
# 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) ⇒ Object



216
217
218
# 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) ⇒ Object



56
57
58
59
60
# 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) ⇒ Object

handle NIST references separately doc identifier format, NIST: NIST SP 800-87-1 8| 8|(Month YYYY)



107
108
109
110
111
112
113
114
115
116
117
118
# 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) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# 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) ⇒ Object



205
206
207
208
209
# 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_descriptionsObject



148
149
150
# File 'lib/asciidoctor/nist/front.rb', line 148

def relaton_relation_descriptions
  super.merge({ "supersedes" => "obsoletes", "superseded-by" => "obsoleted-by", })
end

#relaton_relationsObject



144
145
146
# File 'lib/asciidoctor/nist/front.rb', line 144

def relaton_relations
  super + %w(obsoletes obsoleted-by)
end

#section_names_refs_cleanup(x) ⇒ Object



183
184
185
186
187
188
# 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) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# 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) ⇒ Object



87
88
89
90
91
# File 'lib/asciidoctor/nist/validate.rb', line 87

def section_validate(doc)
  super
  introduction_validate(doc)
  references_validate(doc)
end

#sections_cleanup(x) ⇒ Object



35
36
37
38
39
40
# 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) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
# 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) ⇒ Object



50
51
52
53
54
# 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) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# 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) ⇒ Object

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



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# 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) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



28
29
30
31
32
33
34
# 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) ⇒ Object



68
69
70
# 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) ⇒ Object



147
148
149
# File 'lib/asciidoctor/nist/converter.rb', line 147

def style(n, t)
  return
end

#subseries_validate(series, xmldoc) ⇒ Object



62
63
64
65
66
67
68
69
# 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) ⇒ Object



36
37
38
39
40
41
# 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) ⇒ Object



20
21
22
23
24
# 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) ⇒ Object



164
165
166
167
168
169
170
# 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) ⇒ Object

skip annex/terms/terms, which is empty node



27
28
29
30
31
32
33
# 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) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
# 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) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/asciidoctor/nist/front.rb', line 53

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) ⇒ Object



37
38
39
40
41
42
# File 'lib/asciidoctor/nist/front.rb', line 37

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) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/asciidoctor/nist/front.rb', line 44

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
  node.attr("title-main-short") and t.title(**attr_code(at.merge(type: "short-title"))) do |t1|
    t1 << asciidoc_sub(node.attr("title-main-short"))
  end
end

#title_subtitle(node, t, at) ⇒ Object



27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



4
5
6
# File 'lib/asciidoctor/nist/validate.rb', line 4

def title_validate(root)
  nil
end

#truncate_nist_ref(text) ⇒ Object



120
121
122
123
124
# 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) ⇒ Object



16
17
18
19
20
# 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) ⇒ Object



71
72
73
74
# 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