module IsoDoc::NIST::BaseConvert

Constants

FRONT_CLAUSE
NIST_PUBLISHER_XPATH

Public Instance Methods

abstract(isoxml, out) click to toggle source
# File lib/isodoc/nist/section.rb, line 16
def abstract(isoxml, out)
  f = isoxml.at(ns("//preface/abstract")) || return
  out.div **attr_code(id: f["id"]) do |s|
    clause_name(nil, f.at(ns("./title")) || @i18n.abstract, s, 
                class: "AbstractTitle")
    f.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end
bibliography(isoxml, out) click to toggle source
# File lib/isodoc/nist/refs.rb, line 60
def bibliography(isoxml, out)
  f = isoxml.at(ns("//bibliography/clause | //bibliography/references")) || return
  page_break(out)
  isoxml.xpath(ns("//bibliography/clause | //bibliography/references")).each do |f|
    next if f["hidden"] == "true"
    out.div do |div|
      div.h1 **{ class: "Section3" } do |h1|
        f&.at(ns("./title"))&.children.each { |n| parse(n, h1) }
      end
      biblio_list(f, div, false)
    end
  end
end
bibliography_parse(node, out) click to toggle source
# File lib/isodoc/nist/refs.rb, line 49
def bibliography_parse(node, out)
  return if node["hidden"] == "true"
  title = node&.at(ns("./title"))&.text || ""
  out.div do |div|
    unless suppress_biblio_title(node)
      clause_parse_title(node, div, node.at(ns("./title")), out)
    end
    biblio_list(node, div, true)
  end
end
boilerplate(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 54
  def boilerplate(node, out)
  boilerplate = node.at(ns("//boilerplate")) or return
  out.div **{class: "authority"} do |s|
    boilerplate.children.each do |n|
      if n.name == "title"
        s.h1 do |h|
          n.children.each { |nn| parse(nn, h) }
        end
      else
        parse(n, s)
      end
    end
    page_break(s)
  end
end
bracket_if_num(x) click to toggle source
# File lib/isodoc/nist/refs.rb, line 38
def bracket_if_num(x)
  return nil if x.nil?
  x = x.text.sub(/^\[/, "").sub(/\]$/, "")
  "[#{x}]"
end
children_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 70
def children_parse(node, out)
  node.children.each do |n|
    parse(n, out)
  end
end
dl_parse(node, out) click to toggle source
Calls superclass method
# File lib/isodoc/nist/base_convert.rb, line 22
def dl_parse(node, out)
  return glossary_parse(node, out) if node["type"] == "glossary"
  return glossary_parse(node, out) if node.parent.name == "definitions"
  super
end
errata_body(t, node) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 100
def errata_body(t, node)
  t.tbody do |b|
    node.xpath(ns("./row")).each do |row|
      b.tr do |tr|
        %w{date type change pages}.each do |hdr|
          tr.td do |td|
            row&.at(ns("./#{hdr}"))&.children.each do |n|
              parse(n, td)
            end
          end
        end
      end
    end
  end
end
errata_head(t) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 90
def errata_head(t)
  t.thead do |h|
    h.tr do |tr|
      %w(Date Type Change Pages).each do |hdr|
        tr.th hdr
      end
    end
  end
end
errata_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 82
def errata_parse(node, out)
  out.a **{ name: "errata_XYZZY" }
  out.table **table_attrs(node) do |t|
    errata_head(t)
    errata_body(t, node)
  end
end
error_parse(node, out) click to toggle source
Calls superclass method
# File lib/isodoc/nist/base_convert.rb, line 42
def error_parse(node, out)
  case node.name
  when "nistvariable" then nistvariable_parse(node, out)
  when "recommendation" then recommendation_parse(node, out)
  when "requirement" then requirement_parse(node, out)
  when "permission" then permission_parse(node, out)
  when "errata" then errata_parse(node, out)
  else
    super
  end
end
foreword(isoxml, out) click to toggle source
# File lib/isodoc/nist/section.rb, line 52
def foreword(isoxml, out)
  f = isoxml.at(ns("//foreword")) || return
  out.div **attr_code(id: f["id"]) do |s|
    title = f.at(ns("./title"))
    s.h1(**{ class: "ForewordTitle" }) do |h1|
      title and title.children.each { |e| parse(e, h1) }
    end
    f.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end
glossary_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 28
def glossary_parse(node, out)
  out.dl  **attr_code(id: node["id"], class: "glossary") do |v|
    node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
      v.dt **attr_code(id: dt["id"]) do |term|
        dt_parse(dt, term)
      end
      v.dd  **attr_code(id: dd["id"]) do |listitem|
        dd.children.each { |n| parse(n, listitem) }
      end
    end
  end
  node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, out) }
end
info(isoxml, out) click to toggle source
Calls superclass method
# File lib/isodoc/nist/base_convert.rb, line 127
def info(isoxml, out)
  @meta.series isoxml, out
  @meta.commentperiod isoxml, out
  super
end
is_clause?(name) click to toggle source
Calls superclass method
# File lib/isodoc/nist/section.rb, line 63
def is_clause?(name)
  return true if %w(reviewernote executivesummary).include? name
  super
end
keywords(docxml, out) click to toggle source
# File lib/isodoc/nist/section.rb, line 4
def keywords(docxml, out)
  f = docxml.at(ns("//preface/clause[@type = 'keyword']")) || return
  preface1(f, f&.at(ns("./title")), false, out)
end
middle(isoxml, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 120
def middle(isoxml, out)
  middle_admonitions(isoxml, out)
  clause isoxml, out
  bibliography isoxml, out
  annex isoxml, out
end
middle_clause(_docxml) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 116
def middle_clause(_docxml)
  "//clause[parent::sections] | //terms[parent::sections]"
end
modification_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 176
def modification_parse(node, out)
  out << @i18n.modified
  node.at(ns("./p[text()[normalize-space() != '']]")) and out << " &mdash; "
  node.at(ns("./p")).children.each { |n| parse(n, out) }
end
nistvariable_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 76
def nistvariable_parse(node, out)
  out.span **{class: "nistvariable"} do |s|
    node.children.each { |n| parse(n, s) }
  end
end
nonstd_bibitem(list, b, ordinal, bibliography) click to toggle source

we are taking the ref number/code out as prefix to reference

# File lib/isodoc/nist/refs.rb, line 9
def nonstd_bibitem(list, b, ordinal, bibliography)
  list.p **attr_code(iso_bibitem_entry_attrs(b, bibliography)) do |r|
      reference_format(b, r)
  end
end
ol_depth(node) click to toggle source
Calls superclass method
# File lib/isodoc/nist/base_convert.rb, line 182
def ol_depth(node)
  return super unless node["class"] == "steps" or
    node.at(".//ancestor::xmlns:ol[@class = 'steps']")
  depth = node.ancestors("ul, ol").size + 1
  type = :arabic
  type = :alphabet if [2, 7].include? depth
  type = :roman if [3, 8].include? depth
  type = :alphabet_upper if [4, 9].include? depth
  type = :roman_upper if [5, 10].include? depth
  ol_style(type)
end
omit_docid_prefix(prefix) click to toggle source
Calls superclass method
# File lib/isodoc/nist/refs.rb, line 44
def omit_docid_prefix(prefix)
  return true if prefix.nil? || prefix.empty?
  super || prefix == "NIST"
end
preface(isoxml, out) click to toggle source

All “[preface]” sections should have class “IntroTitle” to prevent page breaks, but for the Exec Summary

# File lib/isodoc/nist/section.rb, line 30
def preface(isoxml, out)
  isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
    next if skip_render(c, isoxml) || !is_clause?(c.name)
    title = c&.at(ns("./title"))
    patent = ["Call for Patent Claims",
              "Patent Disclosure Notice"].include? title&.text
    preface1(c, title, patent, out)
  end
end
preface1(c, title, patent, out) click to toggle source
# File lib/isodoc/nist/section.rb, line 40
def preface1(c, title, patent, out)
  out.div **attr_code(id: c["id"]) do |s|
    page_break(s) if patent
    clause_name(nil, title, s,
                class: (c.name == "executivesummary") ? "NormalTitle" :
                "IntroTitle")
    c.elements.reject { |c1| c1.name == "title" }.each do |c1|
      parse(c1, s)
    end
  end
end
reference_format(b, r) click to toggle source
# File lib/isodoc/nist/refs.rb, line 19
def reference_format(b, r)
  if code = b.at(ns("./docidentifier[@display = 'true']"))
    r << code.text
    insert_tab(r, 1)
  end
  reference_format1(b, r)
end
reference_format1(b, r) click to toggle source
# File lib/isodoc/nist/refs.rb, line 27
def reference_format1(b, r)
  if ftitle = b.at(ns("./formattedref"))
    ftitle&.children&.each { |n| parse(n, r) }
  else
    title = b.at(ns("./title[@language = '#{@lang}']")) || b.at(ns("./title"))
    r.i do |i|
      title&.children&.each { |n| parse(n, i) }
    end
  end
end
requirement_cleanup(docxml) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 9
def requirement_cleanup(docxml)
  docxml.xpath("//div[@class = 'recommend' or @class = 'require' "\
               "or @class = 'permission']").each do |d|
    title = d.at("./p[@class = 'RecommendationTitle']") or next
    title.name = "b"
    title.delete("class")
    n = title.next_element
    n&.children&.first&.add_previous_sibling(" ")
    n&.children&.first&.add_previous_sibling(title.remove)
  end
  docxml
end
skip_render(c, isoxml) click to toggle source
# File lib/isodoc/nist/section.rb, line 9
def skip_render(c, isoxml)
  return false unless c.name == "reviewernote"
  status = isoxml&.at(ns("//bibdata/status/stage"))&.text
  return true if status.nil?
  /^final/.match status
end
std_bibitem_entry(list, b, ordinal, biblio) click to toggle source
# File lib/isodoc/nist/refs.rb, line 15
def std_bibitem_entry(list, b, ordinal, biblio)
  nonstd_bibitem(list, b, ordinal, biblio)
end
term_and_termref_parse(node, dt) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 157
def term_and_termref_parse(node, dt)
  pref = node.at(ns("./preferred"))
  source = node.xpath(ns("./termsource"))
  pref.children.each { |n| parse(n, dt) }
  return if source.empty?
  dt << "<br/>"
  source.each_with_index do |s, i|
    i > 0 and dt << "; "
    s.elements.each { |n| parse(n, dt) }
  end
end
term_cleanup(docxml) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 146
def term_cleanup(docxml)
  docxml.xpath("//table[@class = 'terms_dl']").each do |d|
    prev = d.previous_element
    next unless prev && prev.name == "table" &&
      prev["class"] == "terms_dl"
    d.children.each { |n| prev.add_child(n.remove) }
    d.remove
  end
  docxml
end
term_rest_parse(node, dd) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 169
def term_rest_parse(node, dd)
  set_termdomain("")
  node.children.each do |n|
    parse(n, dd) unless %w(preferred termsource name).include?(n.name)
  end
end
termref_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 143
def termref_parse(node, out)
end
terms_parse(node, out) click to toggle source
# File lib/isodoc/nist/base_convert.rb, line 133
def terms_parse(node, out)
  out.div **attr_code(id: node["id"]) do |div|
    node.at(ns("./title")) and
      clause_parse_title(node, div, node.at(ns("./title")), out)
    node.elements.each do |e|
      parse(e, div) unless %w{title source}.include? e.name
    end
  end
end