class IsoDoc::ITU::WordConvert
Constants
- TOPLIST
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/isodoc/itu/word_convert.rb, line 9 def initialize(options) @libdir = File.dirname(__FILE__) @hierarchical_assets = options[:hierarchical_assets] super end
Public Instance Methods
abstract(isoxml, out)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 37 def abstract(isoxml, out) f = isoxml.at(ns("//preface/abstract")) || return out.div **attr_code(id: f["id"], class: "Abstract") do |s| clause_name(nil, "Summary", s, class: "AbstractTitle") f.elements.each { |e| parse(e, s) unless e.name == "title" } end end
clause_attrs(node)
click to toggle source
Calls superclass method
# File lib/isodoc/itu/word_convert.rb, line 118 def clause_attrs(node) ret = {} %w(source history).include?(node["type"]) and ret = { class: node["type"] } super.merge(ret) end
convert1(docxml, filename, dir)
click to toggle source
Calls superclass method
# File lib/isodoc/itu/word_convert.rb, line 67 def convert1(docxml, filename, dir) if docxml&.at(ns("//bibdata/ext/doctype"))&.text == "service-publication" @wordcoverpage = html_doc_path("word_itu_titlepage_sp.html") options[:bodyfont] = "Arial" options[:headerfont] = "Arial" end super end
default_file_locations(options)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 89 def default_file_locations(options) { wordstylesheet: html_doc_path("wordstyle.scss"), standardstylesheet: html_doc_path("itu.scss"), header: html_doc_path("header.html"), wordcoverpage: html_doc_path("word_itu_titlepage.html"), wordintropage: html_doc_path("word_itu_intro.html"), ulstyle: "l3", olstyle: "l2", } end
default_fonts(options)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 76 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: "12.0pt", footnotefontsize: "11.0pt", smallerfontsize: "11.0pt", monospacefontsize: "10.0pt", } end
formula_parse1(node, out)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 54 def formula_parse1(node, out) out.div **attr_code(class: "formula") do |div| div.p **attr_code(class: "formula") do |p| insert_tab(div, 1) parse(node.at(ns("./stem")), div) if lbl = node&.at(ns("./name"))&.text insert_tab(div, 1) div << "(#{lbl})" end end end end
indent_list(list, num)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 159 def indent_list(list, num) list["style"] = (list["style"] ? "#{list['style']};" : "") list["style"] += "margin-left: #{num * 0.5}cm;text-indent: -0.5cm;" end
keywords(_docxml, out)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 45 def keywords(_docxml, out) kw = @meta.get[:keywords] kw.nil? || kw.empty? and return out.div **attr_code(class: "Keyword") do |div| clause_name(nil, "Keywords", div, class: "IntroTitle") div.p kw.join(", ") + "." end end
link_parse(node, out)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 107 def link_parse(node, out) out.a **attr_code(href: node["target"], title: node["alt"], class: "url") do |l| if node.text.empty? l << node["target"].sub(/^mailto:/, "") else node.children.each { |n| parse(n, l) } end end end
make_body(xml, docxml)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 15 def make_body(xml, docxml) 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/itu/word_convert.rb, line 24 def make_body2(body, docxml) body.div **{ class: "WordSection2" } do |div2| info docxml, div2 boilerplate docxml, div2 preface_block docxml, div2 abstract docxml, div2 keywords docxml, div2 preface docxml, div2 div2.p { |p| p << " " } # placeholder end section_break(body) end
make_tr_attr(td, row, totalrows, header)
click to toggle source
Calls superclass method
# File lib/isodoc/itu/word_convert.rb, line 99 def make_tr_attr(td, row, totalrows, header) super.merge(valign: "top") end
ol_attrs(node)
click to toggle source
# File lib/isodoc/itu/word_convert.rb, line 103 def ol_attrs(node) { class: node["class"], id: node["id"], style: keep_style(node) } end
table_list_style(xml)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 140 def table_list_style(xml) xml.xpath("//table//ul#{TOPLIST} | //table//ol#{TOPLIST}").each do |t| table_list_style1(t, 1) end end
table_list_style1(tab, num)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 146 def table_list_style1(tab, num) (tab.xpath(".//li") - tab.xpath(".//ol//li | .//ul//li")).each do |t1| indent_list(t1, num) t1.xpath("./div | ./p").each { |p| indent_list(p, num) } (t1.xpath(".//ul") - t1.xpath(".//ul//ul | .//ol//ul")).each do |t2| table_list_style1(t2, num + 1) end (t1.xpath(".//ol") - t1.xpath(".//ul//ol | .//ol//ol")).each do |t2| table_list_style1(t2, num + 1) end end end
toWord(result, filename, dir, header)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 70 def toWord(result, filename, dir, header) result = populate_template(result, :word) result = from_xhtml(word_cleanup(to_xhtml(result))) unless @landscapestyle.nil? || @landscapestyle.empty? @wordstylesheet&.open @wordstylesheet&.write(@landscapestyle) @wordstylesheet&.close end Html2Doc.process( result, filename: filename, stylesheet: @wordstylesheet&.path, header_file: header&.path, dir: dir, asciimathdelims: [@openmathdelim, @closemathdelim], liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" } ) header&.unlink @wordstylesheet&.unlink end
word_cleanup(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/itu/word_cleanup.rb, line 14 def word_cleanup(docxml) word_footnote_cleanup(docxml) word_title_cleanup(docxml) word_preface_cleanup(docxml) word_term_cleanup(docxml) word_history_cleanup(docxml) authority_hdr_cleanup(docxml) table_list_style(docxml) super docxml end
word_footnote_cleanup(docxml)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 26 def word_footnote_cleanup(docxml) docxml.xpath("//aside").each do |a| a.first_element_child.children.first.previous = '<span style="mso-tab-count:1"/>' end end
word_history_cleanup(docxml)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 44 def word_history_cleanup(docxml) docxml.xpath("//div[@id='_history']//table").each do |t| t["class"] = "MsoNormalTable" t.xpath(".//td").each { |td| td["style"] = nil } end end
word_preface(docxml)
click to toggle source
Calls superclass method
# File lib/isodoc/itu/word_cleanup.rb, line 51 def word_preface(docxml) super abstractbox = docxml.at("//div[@id='abstractbox']") historybox = docxml.at("//div[@id='historybox']") sourcebox = docxml.at("//div[@id='sourcebox']") keywordsbox = docxml.at("//div[@id='keywordsbox']") changelogbox = docxml.at("//div[@id='change_logbox']") abstract = docxml.at("//div[@class = 'Abstract']") history = docxml.at("//div[@class = 'history']") source = docxml.at("//div[@class = 'source']") keywords = docxml.at("//div[@class = 'Keyword']") changelog = docxml.at("//div[@id = 'change_log']") abstract.parent = abstractbox if abstract && abstractbox history.parent = historybox if history && historybox source.parent = sourcebox if source && sourcebox keywords.parent = keywordsbox if keywords && keywordsbox changelog.parent = changelogbox if changelog && changelogbox end
word_preface_cleanup(docxml)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 4 def word_preface_cleanup(docxml) docxml.xpath("//h1[@class = 'AbstractTitle'] | "\ "//h1[@class = 'IntroTitle']").each do |h2| h2.name = "p" h2["class"] = "h1Preface" end end
word_term_cleanup(docxml)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 12 def word_term_cleanup(docxml); end
word_title_cleanup(docxml)
click to toggle source
# File lib/isodoc/itu/word_cleanup.rb, line 33 def word_title_cleanup(docxml) docxml.xpath("//p[@class = 'annex_obligation']").each do |h| h&.next_element&.name == "p" or next h.next_element["class"] ||= "Normalaftertitle" end docxml.xpath("//p[@class = 'FigureTitle']").each do |h| h&.parent&.next_element&.name == "p" or next h.parent.next_element["class"] ||= "Normalaftertitle" end end