Module: IsoDoc::NIST::BaseConvert

Included in:
HtmlConvert, WordConvert
Defined in:
lib/isodoc/nist/refs.rb,
lib/isodoc/nist/section.rb,
lib/isodoc/nist/base_convert.rb

Constant Summary collapse

NIST_PUBLISHER_XPATH =
"./contributor[xmlns:role/@type = 'publisher']/"\
"organization[abbreviation = 'NIST' or xmlns:name = 'NIST']".freeze
FRONT_CLAUSE =
"//*[parent::preface][not(local-name() = 'abstract' or "\
"local-name() = 'foreword' or @type = 'keyword')]".freeze

Instance Method Summary collapse

Instance Method Details

#abstract(isoxml, out) ⇒ Object



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



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



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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



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



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



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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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) ⇒ Object



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



82
83
84
85
86
87
88
# 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) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



127
128
129
130
131
# 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) ⇒ Boolean

Returns:

  • (Boolean)


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



4
5
6
7
# 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) ⇒ Object



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



116
117
118
# File 'lib/isodoc/nist/base_convert.rb', line 116

def middle_clause(_docxml)
  "//clause[parent::sections] | //terms[parent::sections]"
end

#modification_parse(node, out) ⇒ Object



176
177
178
179
180
# 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) ⇒ Object



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

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



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



182
183
184
185
186
187
188
189
190
191
192
# 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) ⇒ Object



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

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



30
31
32
33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# 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) ⇒ Object



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



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



9
10
11
12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



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



15
16
17
# 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) ⇒ Object



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



146
147
148
149
150
151
152
153
154
155
# 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) ⇒ Object



169
170
171
172
173
174
# 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) ⇒ Object



143
144
# File 'lib/isodoc/nist/base_convert.rb', line 143

def termref_parse(node, out)
end

#terms_parse(node, out) ⇒ Object



133
134
135
136
137
138
139
140
141
# 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