module IsoDoc module NIST module BaseConvert NIST_PUBLISHER_XPATH = "./contributor[xmlns:role/@type = 'publisher']/"\ "organization[abbreviation = 'NIST' or xmlns:name = 'NIST']".freeze # we are taking the ref number/code out as prefix to reference def nonstd_bibitem(list, b, ordinal, bibliography) list.p **attr_code(iso_bibitem_entry_attrs(b, bibliography)) do |r| if !b.at(ns("./formattedref")) nist_reference_format(b, r) else reference_format(b, r) end end end def std_bibitem_entry(list, b, ordinal, biblio) nonstd_bibitem(list, b, ordinal, biblio) end def reference_format(b, r) code = render_identifier(bibitem_ref_code(b)) if code[0] r << "#{code[0]} " insert_tab(r, 1) end reference_format1(b, r) r << " [#{code[1]}] " if code[1] end def reference_format1(b, r) if ftitle = b.at(ns("./formattedref")) ftitle&.children&.each { |n| parse(n, r) } else title = b.at(ns("./title[@language = '#{@language}']")) || b.at(ns("./title")) r.i do |i| title&.children&.each { |n| parse(n, i) } end end end def bracket_if_num(x) return nil if x.nil? x = x.text.sub(/^\[/, "").sub(/\]$/, "") "[#{x}]" end def omit_docid_prefix(prefix) return true if prefix.nil? || prefix.empty? super || prefix == "NIST" end def nist_reference_format(b, r) code = render_identifier(bibitem_ref_code(b)) if code[0] r << "#{code[0]} " insert_tab(r, 1) end bibitem = b.dup.to_xml r.parent.add_child ::Iso690Render.render(bibitem, true) end def bibliography_parse(node, out) title = node&.at(ns("./title"))&.text || "" out.div do |div| unless suppress_biblio_title(node) @xrefs.anchor(node['id'], :label, false) and clause_parse_title(node, div, node.at(ns("./title")), out) or div.h2 title, **{ class: "Section3" } end biblio_list(node, div, true) end end def bibliography(isoxml, out) f = isoxml.at(ns("//bibliography/clause | //bibliography/references")) || return page_break(out) isoxml.xpath(ns("//bibliography/clause | //bibliography/references")).each do |f| out.div do |div| div.h1 **{ class: "Section3" } do |h1| if @bibliographycount == 1 then h1 << "References" else f&.at(ns("./title"))&.children.each { |n| parse(n, h1) } end end biblio_list(f, div, false) end end end def suppress_biblio_title(node) return false unless node.parent.name == "annex" return false if node.parent.xpath("./references | ./clause | "\ "./terms | ./definitions").size > 1 title1 = node&.at(ns("./title"))&.text return true unless title1 title2 = node&.parent&.at(ns("./title"))&.text title1&.casecmp(title2) == 0 end end end end