lib/metanorma/modspec/isodoc.rb in mn-requirements-0.1.8 vs lib/metanorma/modspec/isodoc.rb in mn-requirements-0.1.9

- old
+ new

@@ -1,7 +1,8 @@ require_relative "xrefs" require_relative "reqt_label" +require_relative "table_cleanup" module Metanorma class Requirements class Modspec < Default def requirement_render1(node) @@ -32,15 +33,15 @@ end def recommendation_header(reqt, out) n = recommendation_name(reqt, nil) x = if reqt.ancestors("requirement, recommendation, permission").empty? - "<thead><tr><th scope='colgroup' colspan='2'>"\ - "<p class='#{recommend_name_class(reqt)}'>#{n}</p>"\ + "<thead><tr><th scope='colgroup' colspan='2'>" \ + "<p class='#{recommend_name_class(reqt)}'>#{n}</p>" \ "</th></tr></thead>" else - "<thead><tr><td>#{recommendation_class_label(reqt)}</td>"\ + "<thead><tr><th>#{recommendation_class_label(reqt)}</th>" \ "<td>#{n}</td></tr></thead>" end out << x out end @@ -59,18 +60,18 @@ def recommendation_attributes(node, out) ins = out.add_child("<tbody></tbody>").first recommend_title(node, ins) recommendation_attributes1(node).each do |i| - ins.add_child("<tr><td>#{i[0]}</td><td>#{i[1]}</td></tr>") + ins.add_child("<tr><th>#{i[0]}</th><td>#{i[1]}</td></tr>") end ins end def recommend_title(node, out) label = node.at(ns("./identifier")) or return - out.add_child("<tr><td scope='colgroup' colspan='2'>"\ + out.add_child("<tr><td scope='colgroup' colspan='2'>" \ "<tt>#{label.children.to_xml}</tt></td>") end def recommendation_attributes1(node) ret = recommendation_attributes1_head(node, []) @@ -84,41 +85,51 @@ def recommendation_attributes1_head(node, head) oblig = node["obligation"] and head << [@labels["default"]["obligation"], oblig] subj = node.at(ns("./subject"))&.children and head << [rec_subj(node), subj] - node.xpath(ns("./classification[tag = 'target']/value")).each do |v| - xref = recommendation_id(v.text) and - head << [rec_target(node), xref] - end + head = recommendation_attributes1_target(node, head) head += recommendation_backlinks(node) recommendation_attributes1_dependencies(node, head) end + def recommendation_attributes1_target(node, head) + node.xpath(ns("./classification[tag][value]")).each do |c| + c.at(ns("./tag")).text.casecmp("target").zero? or next + xref = recommendation_id(c.at(ns("./value")).text) and + head << [rec_target(node), xref] + end + head + end + def recommendation_backlinks(node) ret = [] id = node.at(ns("./identifier")) or return ret - %w(general class).include?(node["type"]) and - xref = recommendation_link_test(id.text) and - ret << [@labels["modspec"]["conformancetest"], xref] - ret - (node["type"].nil? || node["type"].empty? || - node["type"] == "verification") and - xref = recommendation_link_class(id.text) and - ret << [@labels["modspec"]["included_in"], xref] - ret + ret = recommendation_backlinks_test(node, id, ret) + recommendation_backlinks_class(node, id, ret) end def recommendation_attributes1_dependencies(node, head) + head = recommendation_attributes1_inherit(node, head) + recommendation_attributes_dependencies2(node, head) + end + + def recommendation_attributes1_inherit(node, head) node.xpath(ns("./inherit")).each do |i| head << [@labels["modspec"]["dependency"], recommendation_id(i.children.to_xml)] end - node.xpath(ns("./classification[tag = 'indirect-dependency']/value")) - .each do |v| - xref = recommendation_id(v.children.to_xml) and - head << [@labels["modspec"]["indirectdependency"], xref] + head + end + + def recommendation_attributes_dependencies2(node, head) + %w(indirect-dependency implements).each do |x| + node.xpath(ns("./classification[tag][value]")).each do |c| + c.at(ns("./tag")).text.casecmp(x).zero? or next + xref = recommendation_id(c.at(ns("./value")).children.to_xml) and + head << [@labels["modspec"][x.gsub(/-/, "")], xref] + end end head end def id_attr(node) @@ -128,11 +139,11 @@ def recommendation_steps(node) node.elements.each { |e| recommendation_steps(e) } return node unless node.at(ns("./component[@class = 'step']")) d = node.at(ns("./component[@class = 'step']")) - d = d.replace("<ol class='steps'><li#{id_attr(d)}>"\ + d = d.replace("<ol class='steps'><li#{id_attr(d)}>" \ "#{d.children.to_xml}</li></ol>").first node.xpath(ns("./component[@class = 'step']")).each do |f| f = f.replace("<li#{id_attr(f)}>#{f.children.to_xml}</li>").first d << f end @@ -141,19 +152,20 @@ def recommendation_attributes1_component(node, out) return out if node["class"] == "guidance" node = recommendation_steps(node) - out << "<tr#{id_attr(node)}><td>#{node['label']}</td>"\ + out << "<tr#{id_attr(node)}><th>#{node['label']}</th>" \ "<td>#{node.children}</td></tr>" out end def recommendation_attr_keyvalue(node, key, value) tag = node.at(ns("./#{key}")) or return nil value = node.at(ns("./#{value}")) or return nil - !%w(target indirect-dependency).include?(tag.text) or return nil + !%w(target indirect-dependency implements).include?(tag.text.downcase) or + return nil [Metanorma::Utils.strict_capitalize_first(tag.text), value.children] end def reqt_component_type(node) klass = node.name @@ -179,31 +191,23 @@ end def requirement_guidance_parse(node, out) ins = out.at(ns("./tbody")) node.xpath(ns("./component[@class = 'guidance']")).each do |f| - ins << "<tr#{id_attr(f)}><td>#{@labels['modspec']['guidance']}</td>"\ + ins << "<tr#{id_attr(f)}><th>#{@labels['modspec']['guidance']}</th>" \ "<td>#{f.children}</td></tr>" end out end def reqt_dl(node, out) node.xpath(ns("./dt")).each do |dt| dd = dt.next_element dd&.name == "dd" or next - out.add_child("<tr><td>#{dt.children.to_xml}</td>"\ + out.add_child("<tr><th>#{dt.children.to_xml}</th>" \ "<td>#{dd.children.to_xml}</td></tr>") end out - end - - def requirement_table_cleanup(_node, table) - table.xpath(ns("./tbody/tr/td/table")).each do |t| - x = t.at(ns("./thead/tr")) or next - t.parent.parent.replace(x) - end - table end def rec_subj(node) case node["type"] when "class" then @labels["modspec"]["targettype"]