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",
}.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",
}.freeze
CALL_FOR_PATENT_CLAIMS =
"nist-cswp": "NIST CSWP",
}.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 =
"csrc-building-block": "CSRC Building Block",
  "nist-cswp": "NIST CSWP",
}.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-use-case": "CSRC Use Case",
  "csrc-building-block": "CSRC Building Block",
  "nist-cswp": "NIST CSWP",
}.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



126
127
128
129
130
# File 'lib/asciidoctor/nist/converter.rb', line 126

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



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

def add_id_parts(args, long)
  args[:series] and series_name = long ?
    SERIES.dig(args[:series].to_sym) :
    SERIES_ABBR.dig(args[:series].to_sym)
  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



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/asciidoctor/nist/front_id.rb', line 108

def add_id_parts_mr(args)
  ret = ["NIST"]
  args[:series] and
    ret << SERIES_ABBR&.dig(args[:series].to_sym)&.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)
  Asciidoctor::Standoc::Utils::asciidoc_sub(text)
end

#audience_parse(attrs, xml, node) ⇒ Object



132
133
134
135
136
# File 'lib/asciidoctor/nist/converter.rb', line 132

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



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/asciidoctor/nist/converter.rb', line 173

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



167
168
169
170
171
# File 'lib/asciidoctor/nist/converter.rb', line 167

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



102
103
104
# File 'lib/asciidoctor/nist/boilerplate.rb', line 102

def boilerplate_file(xmldoc)
  File.join(@libdir, @series == "nist-cswp" ? "nist_intro_cswp.xml" : "nist_intro.xml")
end

#boilerplate_isodoc(xmldoc) ⇒ Object



95
96
97
98
99
100
# File 'lib/asciidoctor/nist/boilerplate.rb', line 95

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



73
74
75
76
77
78
79
80
81
82
# File 'lib/asciidoctor/nist/cleanup.rb', line 73

def callforpatentclaims(x, preface)
  return if @series == "nist-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



120
121
122
123
124
# File 'lib/asciidoctor/nist/converter.rb', line 120

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



138
139
140
141
142
# File 'lib/asciidoctor/nist/converter.rb', line 138

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



68
69
70
# File 'lib/asciidoctor/nist/front.rb', line 68

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



219
220
221
# File 'lib/asciidoctor/nist/converter.rb', line 219

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



206
207
208
209
# File 'lib/asciidoctor/nist/converter.rb', line 206

def fetch_ref(xml, code, year, **opts)
  code.sub!(Regexp.new("^(#{NIST_PREFIX_REFS}) "), "NIST \\1 ")
  super
end

#get_all_nist_refs(docxml) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/asciidoctor/nist/cleanup.rb', line 124

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: Asciidoctor::Standoc::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



215
216
217
# File 'lib/asciidoctor/nist/converter.rb', line 215

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
# File 'lib/asciidoctor/nist/front_id.rb', line 22

def id_args(node, dn0)
  return nil unless dn0
  {
    id: dn0,
    series: node.attr("series"),
    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



94
95
96
97
98
99
100
# File 'lib/asciidoctor/nist/front_id.rb', line 94

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



102
103
104
105
106
# File 'lib/asciidoctor/nist/front_id.rb', line 102

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



84
85
86
87
88
89
90
91
92
# File 'lib/asciidoctor/nist/front_id.rb', line 84

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

#init(node) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# 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")
  super
end

#introduction_validate(doc) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/asciidoctor/nist/validate.rb', line 65

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



95
96
97
98
99
100
# File 'lib/asciidoctor/nist/cleanup.rb', line 95

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



64
65
66
# File 'lib/asciidoctor/nist/front.rb', line 64

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

#metadata_commentperiod(node, xml) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/asciidoctor/nist/front.rb', line 130

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/asciidoctor/nist/front.rb', line 87

def (node, xml)
  return unless node.attr("technical-committee") ||
    node.attr("subcommittee") ||
    node.attr("workgroup") || node.attr("workinggroup")
  xml.editorialgroup do |a|
    node.attr("technical-committee") and
      a.committee(node.attr("technical-committee"))
    node.attr("subcommittee") and
      a.subcommittee(
        node.attr("subcommittee"),
        **attr_code(type: node.attr("subcommittee-type"),
                    number: node.attr("subcommittee-number")))
    (node.attr("workgroup") || node.attr("workinggroup")) and
      a.workgroup(node.attr("workgroup") || node.attr("workinggroup"),
                  **attr_code(type: node.attr("workgroup-type"),
                              number: node.attr("workgroup-number")))
  end
end

#metadata_ext(node, xml) ⇒ Object



239
240
241
242
243
# File 'lib/asciidoctor/nist/front.rb', line 239

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

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



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

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



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

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



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

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



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

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



121
122
123
124
125
126
127
128
# File 'lib/asciidoctor/nist/front.rb', line 121

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
end

#metadata_source(node, xml) ⇒ Object



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

def (node, xml)
  super
  node.attr("doc-email") && xml.uri(node.attr("doc-email"), type: "email")
  node.attr("doi") && xml.uri(node.attr("doi"), type: "doi")
end

#metadata_status(node, xml) ⇒ Object



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

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_superseding_authors(b, node) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/asciidoctor/nist/front.rb', line 216

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



185
186
187
188
189
190
191
192
193
194
# File 'lib/asciidoctor/nist/front.rb', line 185

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



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

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
182
183
# 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



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/asciidoctor/nist/front.rb', line 196

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



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

def MMMddyyyy(isodate)
  return nil if isodate.nil?
  Date.parse(isodate).strftime("%B %d, %Y")
end

#move_clauses_into_preface(x, preface) ⇒ Object



41
42
43
44
# File 'lib/asciidoctor/nist/cleanup.rb', line 41

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



46
47
48
49
50
51
52
53
54
# File 'lib/asciidoctor/nist/cleanup.rb', line 46

def move_clauses_into_preface1(x, 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



56
57
58
59
60
61
62
63
# File 'lib/asciidoctor/nist/cleanup.rb', line 56

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



65
66
67
68
69
70
71
# File 'lib/asciidoctor/nist/cleanup.rb', line 65

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



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/asciidoctor/nist/cleanup.rb', line 169

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 = Asciidoctor::Standoc::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



109
110
111
112
113
114
115
116
117
118
# File 'lib/asciidoctor/nist/converter.rb', line 109

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



84
85
86
87
88
89
90
91
92
93
# File 'lib/asciidoctor/nist/cleanup.rb', line 84

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



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

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



211
212
213
# File 'lib/asciidoctor/nist/converter.rb', line 211

def presentation_xml_converter(node)
  IsoDoc::NIST::PresentationXMLConvert.new(html_extract_attributes(node))
end

#reference_names(docxml) ⇒ Object

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



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/asciidoctor/nist/cleanup.rb', line 105

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



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/asciidoctor/nist/validate.rb', line 82

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



200
201
202
203
204
# File 'lib/asciidoctor/nist/converter.rb', line 200

def refitem(xml, item, node)
  item.sub!(Regexp.new("^(<ref[^>]+>)\\[(#{NIST_PREFIX_REFS}) "),
            "\\1[NIST \\2 ")
  super
end

#relaton_relation_descriptionsObject



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

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

#relaton_relationsObject



141
142
143
# File 'lib/asciidoctor/nist/front.rb', line 141

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

#section_names_refs_cleanup(x) ⇒ Object



181
182
183
184
185
186
# File 'lib/asciidoctor/nist/cleanup.rb', line 181

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



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/asciidoctor/nist/cleanup.rb', line 188

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



76
77
78
79
80
# File 'lib/asciidoctor/nist/validate.rb', line 76

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

#sections_cleanup(x) ⇒ Object



34
35
36
37
38
39
# File 'lib/asciidoctor/nist/cleanup.rb', line 34

def sections_cleanup(x)
  super
  x.xpath("//*[@inline-header]").each do |h|
    h.delete("inline-header")
  end
end

#sectiontype_streamline(ret) ⇒ Object



148
149
150
151
152
153
154
155
156
157
# File 'lib/asciidoctor/nist/converter.rb', line 148

def sectiontype_streamline(ret)
  case ret
  when "glossary", "terminology"
    "terms and definitions"
  when "introduction"
    "donotrecognise_introduction"
  else
    super
  end
end

#series_validate(xmldoc) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/asciidoctor/nist/validate.rb', line 50

def series_validate(xmldoc)
  series = xmldoc&.at("//bibdata/series/title")&.text or return
  found = false
  SERIES.each { |_, v| found = true if v == series }
  found or
    @log.add("Document Attributes", nil, 
             "#{series} is not a recognised series")
end

#sort_biblio(bib) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/asciidoctor/nist/cleanup.rb', line 139

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



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/asciidoctor/nist/cleanup.rb', line 153

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
# 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?
      n.replace(Nokogiri::XML::NodeSet.new(n.document,
                                           nistvariable_insert(n)))
    end
  end
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



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

def status_abbr(stage, iter)
  IsoDoc::NIST::Metadata.new(nil, nil, @i18n).status_abbr(stage, iter)
end

#style(n, t) ⇒ Object



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

def style(n, t)
  return
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



159
160
161
162
163
164
165
# File 'lib/asciidoctor/nist/converter.rb', line 159

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



26
27
28
29
30
31
32
# File 'lib/asciidoctor/nist/cleanup.rb', line 26

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



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/asciidoctor/nist/converter.rb', line 185

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



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

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



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



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

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
36
# 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



118
119
120
121
122
# File 'lib/asciidoctor/nist/cleanup.rb', line 118

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



59
60
61
62
63
# File 'lib/asciidoctor/nist/validate.rb', line 59

def validate(doc)
  content_validate(doc)
  schema_validate(formattedstr_strip(doc.dup),
                  File.join(File.dirname(__FILE__), "nist.rng"))
end