Class: IsoDoc::Unece::WordConvert

Inherits:
WordConvert
  • Object
show all
Includes:
BaseConvert
Defined in:
lib/isodoc/unece/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 =
"<v:line \n alt=\"\" style='position:absolute;left:0;text-align:left;z-index:251662848;\n mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;\n mso-width-percent:0;mso-height-percent:0'\n from=\"6.375cm,20.95pt\" to=\"10.625cm,20.95pt\"\n strokeweight=\"1.5pt\"/>\n".freeze

Constants included from BaseConvert

BaseConvert::MIDDLE_CLAUSE, BaseConvert::NONTERMINAL

Instance Method Summary collapse

Methods included from BaseConvert

#admonition_name_parse, #admonition_parse, #annex_levelnum, #annex_name, #annex_name_lbl, #annex_names, #annex_names1, #back_anchor_names, #clause_names, #fileloc, #hierarchical_admonition_names, #hierarchical_asset_names, #i18n_init, #initial_anchor_names, #inline_header_title, #label_annex_leaf_section, #label_leaf_section, #leaf_section?, #levelnumber, #metadata_init, #section_names, #section_names1, #sequential_admonition_names, #sequential_asset_names

Constructor Details

#initialize(options) ⇒ WordConvert

Returns a new instance of WordConvert.



10
11
12
13
14
# File 'lib/isodoc/unece/word_convert.rb', line 10

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

Instance Method Details

#abstract(isoxml, out) ⇒ Object



162
163
164
165
166
167
168
169
# File 'lib/isodoc/unece/word_convert.rb', line 162

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" }) { |h1| h1 << @abstract_lbl }
    f.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#authority_cleanup(docxml) ⇒ Object



171
172
173
174
175
# File 'lib/isodoc/unece/word_convert.rb', line 171

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

#clause_parse_title(node, div, c1, out) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/isodoc/unece/word_convert.rb', line 99

def clause_parse_title(node, div, c1, out)
  if node["inline-header"] == "true"
    inline_header_title(out, node, c1)
  else
    div.send "h#{anchor(node['id'], :level) || '1'}" do |h|
      lbl = anchor(node['id'], :label, false)
      if lbl && !@suppressheadingnumbers
        h << "#{lbl}. "
        insert_tab(h, 1)
      end
      c1&.children&.each { |c2| parse(c2, h) }
    end
  end
end

#default_file_locations(options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/isodoc/unece/word_convert.rb', line 29

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

end



21
22
23
24
25
26
27
# File 'lib/isodoc/unece/word_convert.rb', line 21

def default_fonts(options)
  {
    bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Times New Roman",serif'),
    headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Times New Roman",serif'),
    monospacefont: '"Courier New",monospace'
  }
end

#end_line(_isoxml, out) ⇒ Object



88
89
90
# File 'lib/isodoc/unece/word_convert.rb', line 88

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

#footnotes(div) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/isodoc/unece/word_convert.rb', line 41

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



127
128
129
130
131
132
133
134
135
136
# File 'lib/isodoc/unece/word_convert.rb', line 127

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|
      h1 << @foreword_lbl
    end
    f.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#introduction(isoxml, out) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/isodoc/unece/word_convert.rb', line 114

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|
      h1 << @introduction_lbl
    end
    f.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#make_body(xml, docxml) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/isodoc/unece/word_convert.rb', line 53

def make_body(xml, docxml)
  plenary = docxml.at(ns("//bibdata/ext[doctype = 'plenary']"))
  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) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/isodoc/unece/word_convert.rb', line 67

def make_body2(body, docxml)
  body.div **{ class: "WordSection2" } do |div2|
    info docxml, div2
    boilerplate docxml, div2
    abstract docxml, div2
    foreword docxml, div2
    introduction docxml, div2
    div2.p { |p| p << "&nbsp;" } # placeholder
  end
  section_break(body)
end

#middle(isoxml, out) ⇒ Object



92
93
94
95
96
97
# File 'lib/isodoc/unece/word_convert.rb', line 92

def middle(isoxml, out)
  clause isoxml, out
  annex isoxml, out
  bibliography isoxml, out
  end_line(isoxml, out)
end

#word_preface(docxml) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/isodoc/unece/word_convert.rb', line 138

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 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
end