lib/isodoc/nist/render.rb in metanorma-nist-1.2.9 vs lib/isodoc/nist/render.rb in metanorma-nist-1.2.10

- old
+ new

@@ -16,10 +16,14 @@ def self.medium(doc) doc&.at("./medium")&.text end + def self.blank?(x) + x.nil? || x.empty? + end + =begin def self.edition(doc) x = doc.at("./edition") return "" unless x return x.text unless /^\d+$/.match x.text @@ -49,32 +53,27 @@ ret += publisher if publisher ret end def self.series_title(doc) - s = doc.at("./series[@type = 'main']") || - doc.at("./series[not(@type)]") || - doc.at("./series") + s = doc.at("./series[@type = 'main']") || doc.at("./series[not(@type)]") || doc.at("./series") s&.at("./title")&.text end def self.series(doc, type) - s = doc.at("./series[@type = 'main']") || - doc.at("./series[not(@type)]") || - doc.at("./series") + s = doc.at("./series[@type = 'main']") || doc.at("./series[not(@type)]") || doc.at("./series") return "" unless s - f = s.at("./formattedref") - return f.text if f + f = s.at("./formattedref") and return f.text t = s.at("./title") a = s.at("./abbreviation") n = s.at("./number") p = s.at("./partnumber") dn = doc.at("./docnumber") rev = doc&.at(".//edition")&.text&.sub(/^Revision /, "") ret = "" if t - title = included(type) ? wrap(t.text, " <I>", "</I>") : wrap(t.text, " ", "") + title = included(type) ? wrap(t.text, " <em>", "</em>") : wrap(t.text, " ", "") ret += title ret += " (#{a.text.sub(/^NIST /, "")})" if a end if n || p ret += " #{n.text}" if n @@ -95,20 +94,17 @@ ret.join(". ") end def self.standardidentifier1(id) r = "" - r += "#{id['type']} " if id["type"] and - !%w(ISO IEC NIST).include? id["type"] + r += "#{id['type']} " if id["type"] and !%w(ISO IEC NIST).include? id["type"] r += id.text r end def self.uri(doc) - uri = doc.at("./uri[@type = 'doi']") || - doc.at("./uri[@type = 'uri']") || - doc.at("./uri") + uri = doc.at("./uri[@type = 'doi']") || doc.at("./uri[@type = 'uri']") || doc.at("./uri") uri&.text end def self.accessLocation(doc) s = doc.at("./accessLocation") or return "" @@ -118,11 +114,11 @@ def self.included(type) ["article", "inbook", "incollection", "inproceedings"].include? type end def self.wrap(text, startdelim = " ", enddelim = ".") - return "" if text.nil? || text.empty? + return "" if blank?(text) "#{startdelim}#{text}#{enddelim}" end def self.type(doc) type = doc.at("./@type") and return type&.text @@ -143,12 +139,11 @@ end def self.extent1(localities) ret = [] localities.each do |l| - ret << extent2(l["type"] || "page", - l.at("./referenceFrom"), l.at("./referenceTo")) + ret << extent2(l["type"] || "page", l.at("./referenceFrom"), l.at("./referenceTo")) end ret.join(", ") end def self.extent(localities) @@ -197,55 +192,62 @@ when "final" then "Final" when "final-review" then "Under Review" end end + # converting bibitem to <formattedref> + <docidentifier> def self.parse(doc, embedded = false) - ret = "" f = doc.at("./formattedref") and - return embedded ? f.children.to_xml : "<p>#{f.children.to_xml}</p>" + return embedded ? f.children.to_xml : doc.to_xml + ret = "" type = type(doc) container = doc.at("./relation[@type='includedIn']") if container && !date(doc) && date(container&.at("./bibitem")) - doc << - ( container&.at("./bibitem/date[@type = 'issued' or @type = 'published' or "\ + doc << ( container&.at("./bibitem/date[@type = 'issued' or @type = 'published' or "\ "@type = 'circulated']")&.remove ) end - ser = series_title(doc) dr = draft(doc) - + cr = creatornames(doc) # NIST has seen fit to completely change rendering based on the type of publication. - if ser == "NIST Federal Information Processing Standards" - ret += "National Institute of Standards and Technology" - else - ret += embedded ? wrap(creatornames(doc), "", "") : wrap(creatornames(doc), "", "") + if series_title(doc) == "NIST Federal Information Processing Standards" + cr = "National Institute of Standards and Technology" end + pub = placepub(doc) + + ret += wrap(cr, "", "") if dr mdy = MMMddyyyy(date(doc)) and ret += wrap(mdy, " (", ")") else yr = year(date(doc)) and ret += wrap(yr, " (", ")") end - ret += included(type) ? wrap(title(doc)) : wrap(title(doc), " <I>", "</I>.") - ret += wrap(medium(doc), " [", "].") + ret += included(type) ? wrap(title(doc), " ", "") : wrap(title(doc), " <em>", "</em>") + ret += wrap(medium(doc), " [", "]") #ret += wrap(edition(doc), "", " edition.") - s = series(doc, type) - ret += wrap(placepub(doc), " (", "),") + if cr != pub + ret += wrap(pub, " (", ")") + end + if cr != pub && pub && !pub.empty? && (dr || !blank?(series(doc, type))) + ret += "," + end if dr ret += " Draft (#{dr})" end ret += wrap(series(doc, type), " ", "") - ret += "," if !series(doc, type).empty? && date(doc) - ret += wrap(date(doc)) - ret += wrap(standardidentifier(doc)) unless is_nist(doc) - ret += wrap(uri(doc)) - ret += wrap(accessLocation(doc), " At: ", ".") + ret += wrap(date(doc), ", ", "") + ret += wrap(standardidentifier(doc), ". ", "") unless is_nist(doc) + ret += wrap(uri(doc), ". ", "") + ret += wrap(accessLocation(doc), ". At: ", "") if container - ret += wrap(parse(container.at("./bibitem"), true), " In: ", "") + ret += wrap(parse(container.at("./bibitem"), true), ". In: ", "") locality = doc.xpath("./extent") - ret += wrap(extent(locality)) + ret += wrap(extent(locality), ", " , "") else - ret += wrap(extent(doc.xpath("./extent"))) + ret += wrap(extent(doc.xpath("./extent")), ", ", "") end - embedded ? ret : "<p>#{ret}</p>" + if !embedded + ret += "." + end + + embedded ? ret : "<formattedref>#{ret}</formattedref>#{doc.xpath('./docidentifier').to_xml}" end end