Module: IsoDoc::Function::XrefSectGen

Included in:
Common
Defined in:
lib/isodoc/function/xref_sect_gen.rb

Instance Method Summary collapse

Instance Method Details

#annex_name_lbl(clause, num) ⇒ Object



74
75
76
77
78
# File 'lib/isodoc/function/xref_sect_gen.rb', line 74

def annex_name_lbl(clause, num)
  obl = l10n("(#{@inform_annex_lbl})")
  obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
  l10n("<b>#{@annex_lbl} #{num}</b><br/>#{obl}")
end

#annex_names(clause, num) ⇒ Object



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

def annex_names(clause, num)
  @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
                             xref: "#{@annex_lbl} #{num}", level: 1 }
  clause.xpath(ns("./clause")).each_with_index do |c, i|
    annex_names1(c, "#{num}.#{i + 1}", 2)
  end
  appendix_names(clause, num)
  hierarchical_asset_names(clause, num)
end

#annex_names1(clause, num, level) ⇒ Object



90
91
92
93
94
95
# File 'lib/isodoc/function/xref_sect_gen.rb', line 90

def annex_names1(clause, num, level)
  @anchors[clause["id"]] = { label: num, xref: num, level: level }
  clause.xpath(ns(".//clause")).each_with_index do |c, i|
    annex_names1(c, "#{num}.#{i + 1}", level + 1)
  end
end

#appendix_names(clause, num) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/isodoc/function/xref_sect_gen.rb', line 97

def appendix_names(clause, num)
  clause.xpath(ns("./appendix")).each_with_index do |c, i|
    @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl)
    @anchors[c["id"]][:level] = 2
    @anchors[c["id"]][:container] = clause["id"]
  end
end

#back_anchor_names(docxml) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/isodoc/function/xref_sect_gen.rb', line 4

def back_anchor_names(docxml)
  docxml.xpath(ns("//annex")).each_with_index do |c, i|
    annex_names(c, (65 + i).chr.to_s)
  end
  docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
    reference_names(ref)
  end
end

#clause_names(docxml, sect_num) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/isodoc/function/xref_sect_gen.rb', line 37

def clause_names(docxml, sect_num)
  q = "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
    "[not(descendant::terms)]"
  docxml.xpath(ns(q)).each_with_index do |c, i|
    section_names(c, (i + sect_num), 1)
  end
end

#initial_anchor_names(d) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/isodoc/function/xref_sect_gen.rb', line 13

def initial_anchor_names(d)
  introduction_names(d.at(ns("//introduction")))
  n = 0
  n = section_names(d.at(ns("//clause[title = 'Scope']")), n, 1)
  n = section_names(d.at(ns(
    "//references[title = 'Normative References' or title = 'Normative references']")), n, 1)
  n = section_names(d.at(ns("//sections/terms | "\
                            "//sections/clause[descendant::terms]")), n, 1)
  n = section_names(d.at(ns("//sections/symbols-abbrevs")), n, 1)
  middle_section_asset_names(d)
  clause_names(d, n)
  termnote_anchor_names(d)
  termexample_anchor_names(d)
end

#introduction_names(clause) ⇒ Object



45
46
47
48
49
50
# File 'lib/isodoc/function/xref_sect_gen.rb', line 45

def introduction_names(clause)
  return if clause.nil?
  clause.xpath(ns("./clause")).each_with_index do |c, i|
    section_names1(c, "0.#{i + 1}", 2)
  end
end

#middle_section_asset_names(d) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/isodoc/function/xref_sect_gen.rb', line 28

def middle_section_asset_names(d)
  middle_sections = "//clause[title = 'Scope'] | "\
    "//foreword | //introduction | "\
    "//references[title = 'Normative References' or title = 'Normative references'] | "\
    "//sections/terms | "\
    "//sections/symbols-abbrevs | //clause[parent::sections]"
  sequential_asset_names(d.xpath(ns(middle_sections)))
end

#section_names(clause, num, lvl) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/isodoc/function/xref_sect_gen.rb', line 52

def section_names(clause, num, lvl)
  return num if clause.nil?
  num = num + 1
  @anchors[clause["id"]] =
    { label: num.to_s, xref: l10n("#{@clause_lbl} #{num}"), level: lvl }
  clause.xpath(ns("./clause | ./term  | ./terms | ./symbols-abbrevs")).
    each_with_index do |c, i|
    section_names1(c, "#{num}.#{i + 1}", lvl + 1)
  end
  num
end

#section_names1(clause, num, level) ⇒ Object



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

def section_names1(clause, num, level)
  @anchors[clause["id"]] =
    { label: num, level: level, xref: num }
  # subclauses are not prefixed with "Clause"
  clause.xpath(ns("./clause | ./terms | ./term | ./symbols-abbrevs")).
    each_with_index do |c, i|
    section_names1(c, "#{num}.#{i + 1}", level + 1)
  end
end