module IsoDoc::Function
module Section
def clausedelim
"."
end
def inline_header_title(out, node, c1)
title = c1&.content || ""
out.span **{ class: "zzMoveToFollowing" } do |s|
s.b do |b|
#if get_anchors[node['id']][:label] && !@suppressheadingnumbers
if anchor(node['id'], :label, false) && !@suppressheadingnumbers
#b << "#{get_anchors[node['id']][:label]}#{clausedelim} "
b << "#{anchor(node['id'], :label)}#{clausedelim} "
end
b << "#{title} "
end
end
end
def clause_parse_title(node, div, c1, out)
if node["inline-header"] == "true"
inline_header_title(out, node, c1)
else
#div.send "h#{get_anchors[node['id']][:level]}" do |h|
div.send "h#{anchor(node['id'], :level) || '1'}" do |h|
#lbl = get_anchors[node['id']][:label]
lbl = anchor(node['id'], :label, false)
h << "#{lbl}#{clausedelim} " if lbl && !@suppressheadingnumbers
c1&.children&.each { |c2| parse(c2, h) }
end
end
end
def clause_parse(node, out)
out.div **attr_code(id: node["id"]) 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
def clause_name(num, title, div, header_class)
header_class = {} if header_class.nil?
div.h1 **attr_code(header_class) do |h1|
if num && !@suppressheadingnumbers
h1 << "#{num}#{clausedelim}"
insert_tab(h1, 1)
end
h1 << title
end
div.parent.at(".//h1")
end
MIDDLE_CLAUSE =
"//clause[parent::sections][not(xmlns:title = 'Scope')]"\
"[not(descendant::terms)]".freeze
def clause(isoxml, out)
isoxml.xpath(ns(self.class::MIDDLE_CLAUSE)).each do |c|
out.div **attr_code(id: c["id"]) do |s|
#clause_name(get_anchors[c['id']][:label],
clause_name(anchor(c['id'], :label),
c&.at(ns("./title"))&.content, s, nil)
c.elements.reject { |c1| c1.name == "title" }.each do |c1|
parse(c1, s)
end
end
end
end
def annex_name(annex, name, div)
div.h1 **{ class: "Annex" } do |t|
#t << "#{get_anchors[annex['id']][:label]}
"
t << "#{anchor(annex['id'], :label)}
"
t.b do |b|
name&.children&.each { |c2| parse(c2, b) }
end
end
end
def annex(isoxml, out)
isoxml.xpath(ns("//annex")).each do |c|
page_break(out)
out.div **attr_code(id: c["id"], class: "Section3") 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
def scope(isoxml, out, num)
f = isoxml.at(ns("//clause[title = 'Scope']")) or return num
out.div **attr_code(id: f["id"]) do |div|
num = num + 1
clause_name(num, @scope_lbl, div, nil)
f.elements.each do |e|
parse(e, div) unless e.name == "title"
end
end
num
end
def terms_defs_title(f)
symbols = f.at(ns(".//definitions"))
return @termsdefsymbols_lbl if symbols
@termsdef_lbl
end
TERM_CLAUSE = "//sections/terms | "\
"//sections/clause[descendant::terms]".freeze
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(num, terms_defs_title(f), div, nil)
f.elements.each do |e|
parse(e, div) unless %w{title source}.include? e.name
end
end
num
end
# subclause
def terms_parse(isoxml, out)
clause_parse(isoxml, out)
end
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(num, f&.at(ns("./title"))&.content || @symbols_lbl, div, nil)
f.elements.each do |e|
parse(e, div) unless e.name == "title"
end
end
num
end
# subclause
def symbols_parse(isoxml, out)
isoxml.at(ns("./title")) or
isoxml.children.first.previous = "