class IsoDoc::BSI::Xref

Public Instance Methods

annex_name_lbl(clause, num) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 39
def annex_name_lbl(clause, num)
  obl = if clause["obligation"] == "normative"
          l10n("(#{@labels['norm_annex']})")
        else
          l10n("(#{@labels['inform_annex']})")
        end
  l10n("<strong>#{@labels['annex']} #{num}</strong><tab/>#{obl}")
end
annex_names(clause, num) click to toggle source
Calls superclass method
# File lib/isodoc/bsi/xref.rb, line 91
def annex_names(clause, num)
  super
  @anchors[clause["id"]][:subtype] = "annex"
end
annex_names1(clause, num, level) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 96
def annex_names1(clause, num, level)
  @anchors[clause["id"]] =
    { xref: "<strong>#{num}</strong>", label: num, level: level }
  i = ::IsoDoc::XrefGen::Counter.new
  clause.xpath(ns("./clause | ./references")).each do |c|
    i.increment(c)
    annex_names1(c, "#{num}.#{i.print}", level + 1)
  end
end
commentary_anchor_names(docxml) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 9
def commentary_anchor_names(docxml)
  commentary_anchors(docxml).each do |target, comms|
    link = commentary_link(target, docxml)
    comms.each_with_index do |id, i|
      idx = comms.size == 1 ? "" : " #{i + 1}"
      label = @labels["commentary"].sub(/ %1/, idx).sub(/%2/, link)
      xref = @labels["commentary_xref"].sub(/ %1/, idx).sub(/%2/, link)
      @anchors[id] = { type: "commentary", label: label, xref: xref }
    end
  end
end
commentary_anchors(docxml) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 31
def commentary_anchors(docxml)
  docxml.xpath(ns("//admonition[@type = 'commentary']"))
    .each_with_object({}) do |a, m|
    m[a["target"]] ||= []
    m[a["target"]] << a["id"]
  end
end
list_anchor_names(sections) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 106
def list_anchor_names(sections)
  sections.each do |s|
    notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
      s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
    c = ::IsoDoc::XrefGen::Counter.new
    notes.each do |n|
      next if n["id"].nil? || n["id"].empty?

      idx =
        notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
      @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list",
                                        false)
      list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size > 3)
    end
    list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
  end
end
list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 124
def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
  c = ::IsoDoc::XrefGen::Counter
    .new(list["start"] ? list["start"].to_i - 1 : 0)
  list.xpath(ns("./li")).each do |li|
    label = c.increment(li).listlabel(list, depth)
    label = "#{prev_label}.#{label}" unless prev_label.empty?
    label = "#{list_anchor[:xref]} #{label}" if refer_list
    li["id"] and @anchors[li["id"]] =
      { xref: "#{label})", type: "listitem",
        container: @klass.get_clause_id(li) }
    li.xpath(ns("./ol")).each do |ol|
      list_item_anchor_names(ol, list_anchor, depth + 1, label, false)
    end
  end
end
parse(docxml) click to toggle source
Calls superclass method
# File lib/isodoc/bsi/xref.rb, line 4
def parse(docxml)
  super
  commentary_anchor_names(docxml)
end
section_names(clause, num, lvl) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 63
def section_names(clause, num, lvl)
  return num if clause.nil?

  num.increment(clause)
  @anchors[clause["id"]] =
    { label: num.print, level: lvl, type: "clause",
      xref: l10n("#{@labels['clause']} <strong>#{num.print}</strong>") }
  i = ::IsoDoc::XrefGen::Counter.new
  clause.xpath(ns(SUBCLAUSES)).each do |c|
    i.increment(c)
    section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
  end
  num
end
section_names1(clause, num, level) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 78
def section_names1(clause, num, level)
  @anchors[clause["id"]] =
    { xref: "<strong>#{num}</strong>", level: level, label: num }
  # subclauses are not prefixed with "Clause"
  i = ::IsoDoc::XrefGen::Counter.new
  clause.xpath(ns("./clause | ./terms | ./term | ./definitions | "\
                  "./references"))
    .each do |c|
    i.increment(c)
    section_names1(c, "#{num}.#{i.print}", level + 1)
  end
end
termnote_anchor_names(docxml) click to toggle source
# File lib/isodoc/bsi/xref.rb, line 48
def termnote_anchor_names(docxml)
  docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
    c = ::IsoDoc::XrefGen::Counter.new
    notes = t.xpath(ns(".//termnote"))
    notes.each do |n|
      next if n["id"].nil? || n["id"].empty?

      idx =
        notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
      @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
                                        "note", false)
    end
  end
end