Module: IsoDoc::Function::Section

Included in:
Common
Defined in:
lib/isodoc/function/section.rb,
lib/isodoc/function/section_titles.rb

Constant Summary collapse

TERM_CLAUSE =
"//sections/terms | " \
"//sections/clause[descendant::terms]".freeze

Instance Method Summary collapse

Instance Method Details

#abstract(clause, out) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/isodoc/function/section.rb', line 130

def abstract(clause, out)
  page_break(out)
  out.div **attr_code(id: clause["id"]) do |s|
    clause_name(clause, clause.at(ns("./title")), s,
                { class: "AbstractTitle" })
    clause.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#acknowledgements(clause, out) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/isodoc/function/section.rb', line 119

def acknowledgements(clause, out)
  title_attr = { class: "IntroTitle" }
  page_break(out)
  out.div class: "Section3", id: clause["id"] do |div|
    clause_name(clause, clause.at(ns("./title")), div, title_attr)
    clause.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#annex(isoxml, out) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/isodoc/function/section.rb', line 35

def annex(isoxml, out)
  isoxml.xpath(ns("//annex")).each do |c|
    page_break(out)
    out.div **attr_code(annex_attrs(c)) do |s|
      c.elements.each do |c1|
        if c1.name == "title" then annex_name(c, c1, s)
        else parse(c1, s)
        end
      end
    end
  end
end

#annex_attrs(node) ⇒ Object



31
32
33
# File 'lib/isodoc/function/section.rb', line 31

def annex_attrs(node)
  { id: node["id"], class: "Section3" }
end

#annex_name(_annex, name, div) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/isodoc/function/section_titles.rb', line 71

def annex_name(_annex, name, div)
  preceding_floating_titles(name, div)
  return if name.nil?

  div.h1 class: "Annex" do |t|
    name.children.each { |c2| parse(c2, t) }
    clause_parse_subtitle(name, t)
  end
end

#clause(isoxml, out) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/isodoc/function/section.rb', line 20

def clause(isoxml, out)
  isoxml.xpath(ns(middle_clause(isoxml))).each do |c|
    out.div **attr_code(clause_attrs(c)) do |s|
      clause_name(c, c&.at(ns("./title")), s, nil)
      c.elements.reject { |c1| c1.name == "title" }.each do |c1|
        parse(c1, s)
      end
    end
  end
end

#clause_attrs(node) ⇒ Object



6
7
8
# File 'lib/isodoc/function/section.rb', line 6

def clause_attrs(node)
  { id: node["id"] }
end

#clause_name(node, title, div, header_class) ⇒ Object

top level clause names



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/function/section_titles.rb', line 58

def clause_name(node, title, div, header_class)
  preceding_floating_titles(node, div)
  header_class = {} if header_class.nil?
  div.h1 **attr_code(header_class) do |h1|
    if title.is_a?(String) then h1 << title
    else
      title&.children&.each { |c2| parse(c2, h1) }
      clause_parse_subtitle(title, h1)
    end
  end
  div.parent.at(".//h1")
end

#clause_parse(node, out) ⇒ Object

used for subclauses



11
12
13
14
15
16
17
18
# File 'lib/isodoc/function/section.rb', line 11

def clause_parse(node, out)
  out.div **attr_code(clause_attrs(node)) do |div|
    clause_parse_title(node, div, node.at(ns("./title")), out)
    node.children.reject { |c1| c1.name == "title" }.each do |c1|
      parse(c1, div)
    end
  end
end

#clause_parse_subtitle(title, heading) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/isodoc/function/section_titles.rb', line 48

def clause_parse_subtitle(title, heading)
  if var = title&.at("./following-sibling::xmlns:variant-title" \
                     "[@type = 'sub']")&.remove
    heading.br nil
    heading.br nil
    var.children.each { |c2| parse(c2, heading) }
  end
end

#clause_parse_title(node, div, title, out, header_class = {}) ⇒ Object

used for subclauses



22
23
24
25
26
27
28
29
30
# File 'lib/isodoc/function/section_titles.rb', line 22

def clause_parse_title(node, div, title, out, header_class = {})
  return if title.nil?

  if node["inline-header"] == "true"
    inline_header_title(out, node, title)
  else
    clause_parse_title1(node, div, title, out, header_class)
  end
end

#clause_parse_title1(node, div, title, _out, header_class = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/isodoc/function/section_titles.rb', line 32

def clause_parse_title1(node, div, title, _out, header_class = {})
  depth = clause_title_depth(node, title)
  div.send "h#{depth}", **attr_code(header_class) do |h|
    title&.children&.each { |c2| parse(c2, h) }
    clause_parse_subtitle(title, h)
  end
end

#clause_title_depth(node, title) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/isodoc/function/section_titles.rb', line 40

def clause_title_depth(node, title)
  depth = node.ancestors("clause, annex, terms, references, " \
                         "definitions, acknowledgements, introduction, " \
                         "foreword").size + 1
  depth = title["depth"] if title && title["depth"]
  depth
end

#clausedelimObject



4
5
6
# File 'lib/isodoc/function/section_titles.rb', line 4

def clausedelim
  "."
end

#clausedelimspace(_node, out) ⇒ Object



8
9
10
# File 'lib/isodoc/function/section_titles.rb', line 8

def clausedelimspace(_node, out)
  insert_tab(out, 1)
end

#colophon(isoxml, out) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/isodoc/function/section.rb', line 174

def colophon(isoxml, out)
  isoxml.at(ns("//colophon")) or return
  page_break(out)
  isoxml.xpath(ns("//colophon/clause")).each do |f|
    out.div class: "Section3", id: f["id"] do |div|
      clause_name(f, f&.at(ns("./title")), div, { class: "IntroTitle" })
      f.elements.each do |e|
        parse(e, div) unless e.name == "title"
      end
    end
  end
end


224
225
226
227
228
229
230
# File 'lib/isodoc/function/section.rb', line 224

def copyright_parse(node, out)
  return if @bare

  out.div class: "boilerplate-copyright" do |div|
    node.children.each { |n| parse(n, div) }
  end
end

#executivesummary(clause, out) ⇒ Object



215
216
217
# File 'lib/isodoc/function/section.rb', line 215

def executivesummary(clause, out)
  introduction clause, out
end

#feedback_parse(node, out) ⇒ Object



248
249
250
251
252
253
254
# File 'lib/isodoc/function/section.rb', line 248

def feedback_parse(node, out)
  return if @bare

  out.div class: "boilerplate-feedback" do |div|
    node.children.each { |n| parse(n, div) }
  end
end

#foreword(clause, out) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/isodoc/function/section.rb', line 110

def foreword(clause, out)
  page_break(out)
  out.div **attr_code(id: clause["id"]) do |s|
    clause_name(clause, clause.at(ns("./title")) || @i18n.foreword, s,
                { class: "ForewordTitle" })
    clause.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#front(isoxml, out) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/isodoc/function/section.rb', line 197

def front(isoxml, out)
  p = isoxml.at(ns("//preface")) or return
  p.elements.each do |e|
    if is_clause?(e.name)
      case e.name
      when "abstract" then abstract e, out
      when "foreword" then foreword e, out
      when "introduction" then introduction e, out
      when "executivesummary" then executivesummary e, out
      when "clause" then preface e, out
      when "acknowledgements" then acknowledgements e, out
      end
    else
      preface_block(e, out)
    end
  end
end

#inline_header_title(out, node, title) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/isodoc/function/section_titles.rb', line 12

def inline_header_title(out, node, title)
  out.span class: "zzMoveToFollowing" do |s|
    s.b do |b|
      title&.children&.each { |c2| parse(c2, b) }
      clausedelimspace(node, out) if /\S/.match?(title&.text)
    end
  end
end

#introduction(clause, out) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/isodoc/function/section.rb', line 99

def introduction(clause, out)
  page_break(out)
  out.div class: "Section3", id: clause["id"] do |div|
    clause_name(clause, clause.at(ns("./title")), div,
                { class: "IntroTitle" })
    clause.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#is_clause?(name) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
190
# File 'lib/isodoc/function/section.rb', line 187

def is_clause?(name)
  %w(clause references definitions terms foreword introduction abstract
     acknowledgements).include? name
end


240
241
242
243
244
245
246
# File 'lib/isodoc/function/section.rb', line 240

def legal_parse(node, out)
  return if @bare

  out.div class: "boilerplate-legal" do |div|
    node.children.each { |n| parse(n, div) }
  end
end

#license_parse(node, out) ⇒ Object



232
233
234
235
236
237
238
# File 'lib/isodoc/function/section.rb', line 232

def license_parse(node, out)
  return if @bare

  out.div class: "boilerplate-license" do |div|
    node.children.each { |n| parse(n, div) }
  end
end

#preceding_floating_titles(node, div) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/isodoc/function/section_titles.rb', line 88

def preceding_floating_titles(node, div)
  return if node.nil?

  out = node.xpath("./preceding-sibling::*")
    .reverse.each_with_object([]) do |p, m|
    break m unless p.name == "p"

    m << p
  end or return
  out.each { |c| parse(c, div) }
end

#preface(clause, out) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/isodoc/function/section.rb', line 144

def preface(clause, out)
  if clause["type"] == "toc"
    table_of_contents(clause, out)
  else
    preface_normal(clause, out)
  end
end

#preface_attrs(node) ⇒ Object



139
140
141
142
# File 'lib/isodoc/function/section.rb', line 139

def preface_attrs(node)
  { id: node["id"],
    class: node["type"] == "toc" ? "TOC" : "Section3" }
end

#preface_block(block, out) ⇒ Object

block, e.g. note, admonition



220
221
222
# File 'lib/isodoc/function/section.rb', line 220

def preface_block(block, out)
  parse(block, out)
end

#preface_normal(clause, out) ⇒ Object



152
153
154
155
156
157
158
159
160
161
# File 'lib/isodoc/function/section.rb', line 152

def preface_normal(clause, out)
  page_break(out)
  out.div **attr_code(preface_attrs(clause)) do |div|
    clause_name(clause, clause.at(ns("./title")), div,
                { class: "IntroTitle" })
    clause.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#scope(isoxml, out, num) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/isodoc/function/section.rb', line 48

def scope(isoxml, out, num)
  f = isoxml.at(ns("//clause[@type = 'scope']")) or return num
  out.div **attr_code(id: f["id"]) do |div|
    num = num + 1
    clause_name(f, f&.at(ns("./title")), div, nil)
    f.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
  num
end

#single_term_clause?(elem) ⇒ Boolean

Returns:

  • (Boolean)


192
193
194
195
# File 'lib/isodoc/function/section.rb', line 192

def single_term_clause?(elem)
  t = elem.xpath(ns("./clause | ./terms | ./definitions | ./references"))
  t.size == 1 && %w(terms definitions references).include?(t[0].name)
end

#symbols_abbrevs(isoxml, out, num) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/isodoc/function/section.rb', line 80

def symbols_abbrevs(isoxml, out, num)
  f = isoxml.at(ns("//sections/definitions")) or return num
  out.div **attr_code(id: f["id"], class: "Symbols") do |div|
    num = num + 1
    clause_name(f, f.at(ns("./title")), div, nil)
    f.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
  num
end

#symbols_parse(isoxml, out) ⇒ Object

subclause



93
94
95
96
97
# File 'lib/isodoc/function/section.rb', line 93

def symbols_parse(isoxml, out)
  isoxml.at(ns("./title")) or
    isoxml.children.first.previous = "<title>#{@i18n.symbols}</title>"
  clause_parse(isoxml, out)
end

#table_of_contents(clause, out) ⇒ Object



163
164
165
166
167
168
169
170
171
172
# File 'lib/isodoc/function/section.rb', line 163

def table_of_contents(clause, out)
  page_break(out)
  out.div **attr_code(preface_attrs(clause)) do |div|
    clause_name(clause, clause.at(ns("./title")), div,
                { class: "IntroTitle" })
    clause.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#terms_defs(isoxml, out, num) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/function/section.rb', line 63

def terms_defs(isoxml, out, num)
  f = isoxml.at(ns(TERM_CLAUSE)) or return num
  out.div **attr_code(id: f["id"]) do |div|
    num = num + 1
    clause_name(f, f&.at(ns("./title")), div, nil)
    f.elements.each do |e|
      parse(e, div) unless %w{title source}.include? e.name
    end
  end
  num
end

#terms_parse(isoxml, out) ⇒ Object

subclause



76
77
78
# File 'lib/isodoc/function/section.rb', line 76

def terms_parse(isoxml, out)
  clause_parse(isoxml, out)
end

#variant_title(node, out) ⇒ Object



81
82
83
84
85
86
# File 'lib/isodoc/function/section_titles.rb', line 81

def variant_title(node, out)
  out.p **attr_code(style: "display:none;",
                    class: "variant-title-#{node['type']}") do |p|
    node.children.each { |c| parse(c, p) }
  end
end