module IsoDoc module ITU class PresentationXMLConvert < IsoDoc::PresentationXMLConvert def insert_preface_sections(docxml) if @doctype == "contribution" x = contribution_table(docxml) and contribution_table_insert_pt(docxml).next = x else x = insert_editors_clause(docxml) and editors_insert_pt(docxml).next = x end end def editors_insert_pt(docxml) docxml.at(ns("//preface")) || docxml.at(ns("//sections")) .add_previous_sibling(" ").first ins = docxml.at(ns("//preface/acknolwedgements")) and return ins docxml.at(ns("//preface")).children[-1] end def contribution_table_insert_pt(docxml) docxml.at(ns("//preface")) || docxml.at(ns("//sections")) .add_previous_sibling(" ").first docxml.at(ns("//preface")).children.first.before(" ").previous end def contribution_table(_doc) @doctype == "contribution" or return bureau = bold_and_upcase(@meta.get[:bureau_full]) <<~TABLE #{contribution_table_contacts}

#{@i18n.international_telecommunication_union.upcase}

#{bureau}

#{@i18n.studyperiod.sub('%', @meta.get[:study_group_period]).upcase}

#{@meta.get[:docnumber]}

#{@meta.get[:group].upcase}

#{@i18n.l10n("#{@i18n.original}: #{@i18n.current_language}")}

#{colon_i18n(@i18n.questions)}#{@meta.get[:questions]} #{@i18n.l10n("#{@meta.get[:meeting_place]}, #{@meta.get[:meeting_date]}")}
#{@i18n.get['doctype_dict']['contribution'].upcase}
#{colon_i18n(@i18n.document_source)}#{@meta.get[:source]}
#{colon_i18n(@i18n.title)}#{@meta.get[:doctitle_en]}
TABLE end def colon_i18n(text) @i18n.l10n("#{text}:") end def bold_and_upcase(xml) x = Nokogiri::XML("#{xml}") x.traverse do |e| e.text? or next e.replace("#{e.text.upcase}") end x.root.children.to_xml end def contribution_table_contacts n = (0..@meta.get[:authors]&.size).each_with_object([]) do |i, ret| ret << contribution_table_contact(i) end n.map do |x| lbl = colon_i18n(@i18n.contact) "#{lbl}#{x}" end.join("\n") end def contribution_table_contact(idx) <<~CELL #{@meta.get[:authors][idx]}
#{@meta.get[:affiliations][idx]}
#{@meta.get[:addresses][idx]} #{@i18n.tel_abbrev}#{@meta.get[:phones][idx]}
#{@i18n.email}#{@meta.get[:emails][idx]} CELL end def insert_editors_clause(doc) ret = extract_editors(doc) or return eds = ret[:names].each_with_object([]).with_index do |(_x, acc), i| acc << { name: ret[:names][i], affiliation: ret[:affiliations][i], email: ret[:emails][i] } end editors_clause(eds) end def extract_editors(doc) e = doc.xpath(ns("//bibdata/contributor[role/@type = 'editor']/person")) e.empty? and return { names: @meta.extract_person_names(e), affiliations: @meta.extract_person_affiliations(e), emails: e.reduce([]) { |ret, p| ret << p.at(ns("./email"))&.text } } end def editors_clause(eds) ed_lbl = @i18n.inflect(@i18n.get["editor_full"], number: eds.size > 1 ? "pl" : "sg") ed_lbl &&= l10n("#{ed_lbl.capitalize}:") mail_lbl = l10n("#{@i18n.get['email']}: ") ret = <<~SUBMITTING SUBMITTING ret += editor_table_entries(eds, ed_lbl, mail_lbl) "#{ret}
" end def editor_table_entries(eds, ed_lbl, mail_lbl) eds.each_with_index.with_object([]) do |(n, i), m| mail = "" n[:email] and mail = "#{mail_lbl}" \ "#{n[:email]}" aff = n[:affiliation].empty? ? "" : "
#{n[:affiliation]}" th = "#{i.zero? ? ed_lbl : ''}" m << "#{th}#{n[:name]}#{aff}#{mail}" end.join("\n") end def rearrange_clauses(docxml) super insert_preface_sections(docxml) a = docxml.at(ns("//preface/abstract")) keywords_abstract_swap(a, keywords(docxml), docxml) c = docxml.at(ns("//preface/clause[@type='contribution-metadata']")) and a and c.next = a abstract_render(a) end def keywords_abstract_swap(abstract, keywords, docxml) @doctype == "contribution" and return keywords or return if abstract then abstract.next = keywords else p = contribution_table_insert_pt(docxml) p.next = keywords end end def abstract_render(abstract) @doctype == "contribution" or return abstract.at(ns("./title"))&.remove abstract.children = <<~TABLE

#{colon_i18n(@i18n.abstract)}

#{abstract.children.to_xml}
TABLE end def keywords(_docxml) kw = @meta.get[:keywords] kw.nil? || kw.empty? || @doctype == "contribution" and return "#{@i18n.keywords}" \ "

#{@i18n.l10n(kw.join(', '))}.

" end def toc_title(docxml) %w(resolution contribution).include?(@doctype) and return super end include Init end end end