lib/isodoc/presentation_function/terms.rb in isodoc-2.5.4 vs lib/isodoc/presentation_function/terms.rb in isodoc-2.5.5

- old
+ new

@@ -1,94 +1,7 @@ module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert - def concept(docxml) - @definition_ids = docxml.xpath(ns("//definitions//dt")) - .each_with_object({}) { |x, m| m[x["id"]] = true } - docxml.xpath(ns("//concept")).each { |f| concept1(f) } - end - - def concept1(node) - xref = node&.at(ns("./xref/@target"))&.text or - return concept_render(node, ital: "true", ref: "true", bold: "false", - linkref: "true", linkmention: "false") - if @definition_ids[xref] - concept_render(node, ital: "false", ref: "false", bold: "false", - linkref: "true", linkmention: "false") - else concept_render(node, ital: "true", ref: "true", bold: "false", - linkref: "true", linkmention: "false") - end - end - - def concept_render(node, defaults) - opts, render, ref = concept_render_init(node, defaults) - node&.at(ns("./refterm"))&.remove - ref && opts[:ref] != "false" and render&.next = " " - concept1_linkmention(ref, render, opts) - concept1_ref(node, ref, opts) - concept1_style(node, opts) - node.replace(node.children) - end - - def concept1_style(node, opts) - r = node.at(ns(".//renderterm")) or return - opts[:ital] == "true" and r.children = "<em>#{to_xml(r.children)}</em>" - opts[:bold] == "true" and - r.children = "<strong>#{to_xml(r.children)}</strong>" - r.replace(r.children) - end - - def concept_render_init(node, defaults) - opts = %i(bold ital ref linkref linkmention) - .each_with_object({}) { |x, m| m[x] = node[x.to_s] || defaults[x] } - [opts, node.at(ns("./renderterm")), - node.at(ns("./xref | ./eref | ./termref"))] - end - - def concept1_linkmention(ref, renderterm, opts) - (opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?) or return - ref2 = ref.clone - r2 = renderterm.clone - renderterm.replace(ref2).children = r2 - end - - def concept1_ref(_node, ref, opts) - ref.nil? and return - opts[:ref] == "false" and return ref.remove - concept1_ref_content(ref) - %w(xref eref).include? ref.name and get_linkend(ref) - opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and - ref.replace(ref.children) - end - - def concept1_ref_content(ref) - prev = "[" - foll = "]" - non_locality_elems(ref).select do |c| - !c.text? || /\S/.match(c) - end.empty? and - (prev, foll = @i18n.term_defined_in.split("%")) - ref.previous = prev - ref.next = foll - end - - def related(docxml) - docxml.xpath(ns("//related")).each { |f| related1(f) } - end - - def related1(node) - p = node.at(ns("./preferred")) - ref = node.at(ns("./xref | ./eref | ./termref")) - label = @i18n.relatedterms[node["type"]].upcase - if p && ref - node.replace(l10n("<p><strong>#{label}:</strong> " \ - "<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>")) - else - node.replace(l10n("<p><strong>#{label}:</strong> " \ - "<strong>**RELATED TERM NOT FOUND**</strong></p>")) - end - end - def designation(docxml) docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) } docxml.xpath(ns("//preferred | //admitted | //deprecates")) .each { |p| designation1(p) } docxml.xpath(ns("//deprecates")).each { |d| deprecates(d) } @@ -223,27 +136,38 @@ end end end def termsource(docxml) - docxml.xpath(ns("//termsource/modification")).each do |f| - termsource_modification(f) - end + docxml.xpath(ns("//termsource")).each { |f| termsource_modification(f) } docxml.xpath(ns("//termsource")).each { |f| termsource1(f) } end def termsource1(elem) while elem&.next_element&.name == "termsource" elem << "; #{to_xml(elem.next_element.remove.children)}" end elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]") end - def termsource_modification(mod) - mod.previous_element.next = l10n(", #{@i18n.modified}") + def termsource_modification(elem) + origin = elem.at(ns("./origin")) + s = termsource_status(elem["status"]) and origin.next = l10n(", #{s}") + termsource_add_modification_text(elem.at(ns("./modification"))) + end + + def termsource_add_modification_text(mod) + mod or return mod.text.strip.empty? or mod.previous = " &#x2013; " mod.elements.size == 1 and mod.elements[0].replace(mod.elements[0].children) mod.replace(mod.children) + end + + def termsource_status(status) + case status + when "modified" then @i18n.modified + when "adapted" then @i18n.adapted + end end end end