module Metanorma
class Requirements
class Default
def l10n(text)
@i18n.l10n(text)
end
def recommendation_label(elem, type, xrefs)
number = xrefs.anchor(elem["id"], :label, false)
(number.nil? ? type : "#{type} #{number}")
end
def reqt_metadata_node?(node)
%w(identifier title subject classification tag value
inherit name).include? node.name
end
def requirement_render1(node)
out = recommendation_base(node, node.name)
ins = recommendation_header(node, out)
ins = recommendation_attributes(node, ins)
node.elements.reject do |n|
reqt_metadata_node?(n)
end.each { |n| ins = requirement_component_parse(n, ins) }
out
end
def recommendation_base(node, klass)
out = node.document.create_element(klass)
node.attributes.each do |k, v|
out[k] = v
end
out
end
def recommendation_labels(node)
[node.at(ns("./identifier")), node.at(ns("./title")),
node.at(ns("./name"))]
.map do |n|
n&.children&.to_xml
end
end
def recommendation_header(node, out)
label, title, name = recommendation_labels(node)
ret = name ? [name] : []
if label || title
ret << l10n(":") unless ret.empty?
ret += ["
", label]
ret << l10n(". ") if label && title
ret << title
end
out << "
#{ret.join("
\n")}