-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metadata dl for reqts: metanorma/ogcapi-processes#2
- Loading branch information
Showing
6 changed files
with
231 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,92 @@ | ||
module Asciidoctor | ||
module Standoc | ||
module Cleanup | ||
def requirement_cleanup(reqt) | ||
requirement_descriptions(reqt) | ||
requirement_inherit(reqt) | ||
def requirement_cleanup(xmldoc) | ||
requirement_metadata(xmldoc) | ||
requirement_descriptions(xmldoc) | ||
requirement_inherit(xmldoc) | ||
end | ||
|
||
def requirement_inherit(reqt) | ||
reqt.xpath("//requirement | //recommendation | //permission") | ||
.each do |r| | ||
REQRECPER = "//requirement | //recommendation | //permission".freeze | ||
|
||
def requirement_inherit(xmldoc) | ||
xmldoc.xpath(REQRECPER).each do |r| | ||
ins = r.at("./classification") || | ||
r.at("./description | ./measurementtarget | ./specification | "\ | ||
"./verification | ./import | ./description | ./requirement | "\ | ||
"./recommendation | ./permission") | ||
"./recommendation | ./permission | ./component") | ||
r.xpath("./*//inherit").each { |i| ins.previous = i } | ||
end | ||
end | ||
|
||
def requirement_descriptions(reqt) | ||
reqt.xpath("//requirement | //recommendation | //permission") | ||
.each do |r| | ||
def requirement_descriptions(xmldoc) | ||
xmldoc.xpath(REQRECPER).each do |r| | ||
r.children.each do |e| | ||
unless e.element? && (reqt_subpart(e.name) || | ||
%w(requirement recommendation permission).include?(e.name)) | ||
t = Nokogiri::XML::Element.new("description", reqt) | ||
t = Nokogiri::XML::Element.new("description", r) | ||
e.before(t) | ||
t.children = e.remove | ||
end | ||
end | ||
requirement_cleanup1(r) | ||
requirement_description_cleanup1(r) | ||
end | ||
end | ||
|
||
def requirement_cleanup1(reqt) | ||
def requirement_description_cleanup1(reqt) | ||
while d = reqt.at("./description[following-sibling::*[1]"\ | ||
"[self::description]]") | ||
"[self::description]]") | ||
n = d.next.remove | ||
d << n.children | ||
end | ||
reqt.xpath("./description[normalize-space(.)='']").each do |r| | ||
r.replace("\n") | ||
end | ||
end | ||
|
||
def requirement_metadata(xmldoc) | ||
xmldoc.xpath(REQRECPER).each do |r| | ||
dl = r&.at("./dl[@metadata = 'true']")&.remove or next | ||
requirement_metadata1(r, dl) | ||
end | ||
end | ||
|
||
def requirement_metadata1(reqt, dlist) | ||
unless ins = reqt.at("./title") | ||
reqt.children.first.previous = " " | ||
ins = reqt.children.first | ||
end | ||
%w(label subject inherit).each do |a| | ||
ins = reqt_dl_to_elems(ins, reqt, dlist, a) | ||
end | ||
reqt_dl_to_classif(ins, reqt, dlist) | ||
end | ||
|
||
def reqt_dl_to_elems(ins, reqt, dlist, name) | ||
if a = reqt.at("./#{name}[last()]") | ||
ins = a | ||
end | ||
dlist.xpath("./dt[text()='#{name}']").each do |e| | ||
val = e.at("./following::dd/p") || e.at("./following::dd") | ||
val.name = name | ||
ins.next = val | ||
ins = ins.next | ||
end | ||
ins | ||
end | ||
|
||
def reqt_dl_to_classif(ins, reqt, dlist) | ||
if a = reqt.at("./classification[last()]") | ||
ins = a | ||
end | ||
dlist.xpath("./dt[text()='classification']").each do |e| | ||
val = e.at("./following::dd/p") || e.at("./following::dd") | ||
req_classif_parse(val.text).each do |r| | ||
ins.next = "<classification><tag>#{r[0]}</tag>"\ | ||
"<value>#{r[1]}</value></classification>" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.