class IsoDoc::UN::WordConvert
A {Converter} implementation that generates Word output, and a document schema encapsulation of the document for validation
Constants
- ENDLINE
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/isodoc/un/word_convert.rb, line 11 def initialize(options) @libdir = File.dirname(__FILE__) super @toc = options[:toc] end
Public Instance Methods
abstract(isoxml, out)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 157 def abstract(isoxml, out) f = isoxml.at(ns("//abstract")) || return out.div **attr_code(id: f["id"]) do |s| page_break(out) s.p(**{ class: "AbstractTitle" }) do |h1| f&.at(ns("./title"))&.children&.each { |n| parse(n, h1) } end f.elements.each { |e| parse(e, s) unless e.name == "title" } end end
default_file_locations(options)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 31 def default_file_locations(options) { wordstylesheet: html_doc_path("wordstyle.scss"), standardstylesheet: html_doc_path("unece.scss"), header: html_doc_path("header.html"), wordcoverpage: html_doc_path("word_unece_titlepage.html"), wordintropage: html_doc_path("word_unece_intro.html"), ulstyle: "l3", olstyle: "l2", } end
default_fonts(options)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 17 def default_fonts(options) { bodyfont: (options[:script] == "Hans" ? '"Source Han Sans",serif' : '"Times New Roman",serif'), headerfont: (options[:script] == "Hans" ? '"Source Han Sans",sans-serif' : '"Times New Roman",serif'), monospacefont: '"Courier New",monospace', normalfontsize: "10.5pt", monospacefontsize: "10.0pt", smallerfontsize: "10.0pt", footnotefontsize: "9.0pt", } end
end_line(_isoxml, out)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 94 def end_line(_isoxml, out) out.parent.add_child(ENDLINE) end
footnotes(div)
click to toggle source
Calls superclass method
# File lib/isodoc/un/word_convert.rb, line 43 def footnotes(div) if @meta.get[:item_footnote] fn = noko do |xml| xml.aside **{ id: "ftnitem" } do |div| div.p @meta.get[:item_footnote] end end.join("\n") @footnotes.unshift fn end super end
foreword(isoxml, out)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 119 def foreword(isoxml, out) f = isoxml.at(ns("//foreword")) || return out.div **attr_code(id: f["id"]) do |s| page_break(out) s.p(**{ class: "ForewordTitle" }) do |h1| f&.at(ns("./title"))&.children&.each { |n| parse(n, h1) } end f.elements.each { |e| parse(e, s) unless e.name == "title" } end end
introduction(isoxml, out)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 106 def introduction(isoxml, out) f = isoxml.at(ns("//introduction")) || return out.div **{ class: "Section3", id: f["id"] } do |div| page_break(out) div.p(**{ class: "IntroTitle" }) do |h1| f&.at(ns("./title"))&.children&.each { |n| parse(n, h1) } end f.elements.each do |e| parse(e, div) unless e.name == "title" end end end
make_body(xml, docxml)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 55 def make_body(xml, docxml) plenary = is_plenary?(docxml) if plenary && @wordcoverpage == html_doc_path("word_unece_titlepage.html") @wordcoverpage = html_doc_path("word_unece_plenary_titlepage.html") end @wordintropage = nil if plenary && !@toc body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" } xml.body **body_attr do |body| make_body1(body, docxml) make_body2(body, docxml) make_body3(body, docxml) end end
make_body2(body, docxml)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 70 def make_body2(body, docxml) body.div **{ class: "WordSection2" } do |div2| info docxml, div2 boilerplate docxml, div2 preface_block docxml, div2 abstract docxml, div2 foreword docxml, div2 introduction docxml, div2 preface docxml, div2 acknowledgements docxml, div2 div2.p { |p| p << " " } # placeholder end section_break(body) end
middle(isoxml, out)
click to toggle source
# File lib/isodoc/un/word_convert.rb, line 98 def middle(isoxml, out) middle_admonitions(isoxml, out) clause isoxml, out annex isoxml, out bibliography isoxml, out end_line(isoxml, out) end
word_preface(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/un/word_convert.rb, line 130 def word_preface(docxml) super preface_container = docxml.at("//div[@id = 'preface_container']") # recommendation abstractbox = docxml.at("//div[@id = 'abstractbox']") # plenary foreword = docxml.at("//p[@class = 'ForewordTitle']/..") intro = docxml.at("//p[@class = 'IntroTitle']/..") abstract = docxml.at("//p[@class = 'AbstractTitle']/..") abstract.parent = (abstractbox || preface_container) if abstract && (abstractbox || preface_container) abstractbox and abstract&.xpath(".//p/br")&.each do |a| a.parent.remove if /page-break-before:always/.match(a["style"]) end docxml&.at("//p[@class = 'AbstractTitle']")&.remove if abstractbox foreword.parent = preface_container if foreword && preface_container intro.parent = preface_container if intro && preface_container if preface_container && (foreword || intro) preface_container.at("./div/p[br]").remove # remove initial page break end if abstractbox && !intro && !foreword && !@toc sect2 = docxml.at("//div[@class='WordSection2']") sect2.next_element.remove # pagebreak sect2.remove # pagebreak end abstractbox.parent.remove if abstractbox && !abstract end