lib/metanorma/modspec/cleanup.rb in mn-requirements-0.2.0 vs lib/metanorma/modspec/cleanup.rb in mn-requirements-0.2.2

- old
+ new

@@ -19,11 +19,11 @@ reqt["type"] = ret end def requirement_metadata_component_tags %w(test-purpose test-method test-method-type conditions part description - reference step guidance) + + statement reference step guidance) + requirement_metadata_requirement_tags end def requirement_metadata_requirement_tags %w(conformance-test conformance-class abstract-test requirement-class @@ -33,10 +33,11 @@ def requirement_metadata1(reqt, dlist, ins) ins1 = super dlist.xpath("./dt").each do |e| tag = e.text&.gsub(/ /, "-")&.downcase + tag = "description" if tag == "statement" next unless requirement_metadata_component_tags.include?(tag) ins1.next = requirement_metadata1_component(e, tag) ins1 = ins1.next end @@ -73,19 +74,19 @@ requirement_target_identifiers(reqt) end def requirement_target_identifiers(reqt) reqt.xpath("./classification[tag][value/link]").each do |c| - %w(target indirect-dependency implements) + %w(target indirect-dependency implements identifier-base) .include?(c.at("./tag").text.downcase) or next v = c.at("./value[link]") v.children = v.at("./link/@target").text end end def requirement_metadata_to_component(reqt) - xpath = requirement_metadata_component_tags - %w(description) - + xpath = requirement_metadata_component_tags - %w(statement description) - requirement_metadata_requirement_tags reqt.xpath(xpath.map { |x| ".//#{x}" }.join(" | ")).each do |c| c["class"] = c.name c.name = "component" end @@ -116,9 +117,43 @@ next if %w(p ol ul dl table component description) .include?(c&.elements&.first&.name) c.children = "<p>#{c.children.to_xml}</p>" end + end + + def add_misc_container(xmldoc) + unless ins = xmldoc.at("//misc-container") + a = xmldoc.at("//termdocsource") || xmldoc.at("//bibdata") + a.next = "<misc-container/>" + ins = xmldoc.at("//misc-container") + end + ins + end + + def add_misccontainer_anchor_aliases(xmldoc) + m = add_misc_container(xmldoc) + x = ".//table[@id = '_misccontainer_anchor_aliases']/tbody" + unless ins = m.at(x) + m << "<table id = '_misccontainer_anchor_aliases'><tbody/></table>" + ins = m.at(x) + end + ins + end + + def requirement_anchor_aliases(reqt) + x = reqt.xpath("./identifier") + x.empty? and return + table = add_misccontainer_anchor_aliases(reqt.document) + ids = x.each_with_object([]) do |i, m| + m << "<td>#{i.text}</td>" + end + table << "<tr><th>#{reqt['id']}</th>#{ids.join}</tr>" + end + + def requirement_identifier_cleanup(reqt) + super + requirement_anchor_aliases(reqt) end end end end