Class: IsoDoc::UN::WordConvert

Inherits:
WordConvert
  • Object
show all
Includes:
BaseConvert, Init
Defined in:
lib/isodoc/un/word_convert.rb

Overview

A Converter implementation that generates Word output, and a document schema encapsulation of the document for validation

Constant Summary collapse

ENDLINE =
<<~ENDLINE.freeze
       <v:line
  alt="" style='position:absolute;left:0;text-align:left;z-index:251662848;
  mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;
  mso-width-percent:0;mso-height-percent:0'
  from="6.375cm,20.95pt" to="10.625cm,20.95pt"
  strokeweight="1.5pt"/>
ENDLINE

Instance Method Summary collapse

Methods included from Init

#fileloc, #i18n_init, #metadata_init, #xref_init

Methods included from BaseConvert

#admonition_parse, #bibliography_xpath, #convert_i18n_init1, #inline_header_title, #middle_clause, #norm_ref, #norm_ref_xpath, #plenary?

Constructor Details

#initialize(options) ⇒ WordConvert

Returns a new instance of WordConvert.



11
12
13
14
15
# File 'lib/isodoc/un/word_convert.rb', line 11

def initialize(options)
  @libdir = File.dirname(__FILE__)
  super
  @toc = options[:toc]
end

Instance Method Details

#abstract(clause, out) ⇒ Object



143
144
145
146
147
148
149
150
151
# File 'lib/isodoc/un/word_convert.rb', line 143

def abstract(clause, out)
  out.div **attr_code(id: clause["id"]) do |s|
    page_break(out)
    s.p(class: "AbstractTitle") do |h1|
      clause.at(ns("./title"))&.children&.each { |n| parse(n, h1) }
    end
    clause.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#authority_cleanup(docxml) ⇒ Object



153
154
155
156
157
158
# File 'lib/isodoc/un/word_convert.rb', line 153

def authority_cleanup(docxml)
  super
  a = docxml.at("//div[@id = 'boilerplate-ECEhdr']") and
    a["class"] = "boilerplate-ECEhdr"
  docxml.at("//div[@class = 'authority']")&.remove
end

#default_file_locations(_options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/isodoc/un/word_convert.rb', line 37

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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/un/word_convert.rb', line 17

def default_fonts(options)
  {
    bodyfont: (if options[:script] == "Hans"
                 '"Source Han Sans",serif'
               else
                 '"Times New Roman",serif'
               end),
    headerfont: (if options[:script] == "Hans"
                   '"Source Han Sans",sans-serif'
                 else
                   '"Times New Roman",serif'
                 end),
    monospacefont: '"Courier New",monospace',
    normalfontsize: "10.5pt",
    monospacefontsize: "10.0pt",
    smallerfontsize: "10.0pt",
    footnotefontsize: "9.0pt",
  }
end

#end_line(_isoxml, out) ⇒ Object



85
86
87
# File 'lib/isodoc/un/word_convert.rb', line 85

def end_line(_isoxml, out)
  out.parent.add_child(ENDLINE)
end

#footnotes(_div) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/un/word_convert.rb', line 49

def footnotes(_div)
  if @meta.get[:item_footnote]
    fn = noko do |xml|
      xml.aside id: "ftnitem" do |d|
        d.p @meta.get[:item_footnote]
      end
    end.join("\n")
    @footnotes.unshift fn
  end
  super
end

#foreword(clause, out) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/isodoc/un/word_convert.rb', line 106

def foreword(clause, out)
  out.div **attr_code(id: clause["id"]) do |s|
    page_break(out)
    s.p(class: "ForewordTitle") do |h1|
      clause.at(ns("./title"))&.children&.each { |n| parse(n, h1) }
    end
    clause.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#introduction(clause, out) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/isodoc/un/word_convert.rb', line 94

def introduction(clause, out)
  out.div class: "Section3", id: clause["id"] do |div|
    page_break(out)
    div.p(class: "IntroTitle") do |h1|
      clause.at(ns("./title"))&.children&.each { |n| parse(n, h1) }
    end
    clause.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#make_body(xml, docxml) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/isodoc/un/word_convert.rb', line 61

def make_body(xml, docxml)
  plenary = 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_body3(out, isoxml) ⇒ Object



89
90
91
92
# File 'lib/isodoc/un/word_convert.rb', line 89

def make_body3(out, isoxml)
  super
  end_line(isoxml, out)
end

#word_preface(docxml) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/isodoc/un/word_convert.rb', line 116

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 a["style"].include?("page-break-before:always")
  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