Class: IsoDoc::Ogc::WordConvert

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

Overview

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

Instance Method Summary collapse

Methods included from Init

#fileloc, #i18n_init, #metadata_init, #ogc_draft_ref?, #submittingorgs_path, #xref_init

Methods included from BaseConvert

#abstract, #acknowledgements, #admitted_term_parse, #cleanup, #conformance, #deprecated_term_parse, #error_parse, #example_label, #example_name_parse, #example_parse, #executivesummary, #foreword, #hi_parse, #intro_clause, #is_clause?, #keywords, #make_tr_attr, #middle, #middle_clause, #nonstd_bibitem, #ol_depth, #para_class, #preface, #security, #std_bibitem_entry, #submitters, #submittingorgs, #term_cleanup, #term_cleanup_merge_admitted, #term_cleanup_merge_termnum

Constructor Details

#initialize(options) ⇒ WordConvert

Returns a new instance of WordConvert.



13
14
15
16
# File 'lib/isodoc/ogc/word_convert.rb', line 13

def initialize(options)
  @libdir = File.dirname(__FILE__)
  super
end

Instance Method Details

#convert1(docxml, filename, dir) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/isodoc/ogc/word_convert.rb', line 42

def convert1(docxml, filename, dir)
  if docxml&.at(ns("//bibdata/ext/doctype"))&.text == "white-paper"
    @wordstylesheet_name = html_doc_path("wordstyle_wp.scss")
    @standardstylesheet_name = html_doc_path("ogc_wp.scss")
    @wordcoverpage = html_doc_path("word_ogc_titlepage_wp.html")
    @wordintropage = html_doc_path("word_ogc_intro_wp.html")
    @header = html_doc_path("header_wp.html")
    @doctype = "white-paper"
    options[:bodyfont] = '"Arial",sans-serif'
    options[:headerfont] = '"Lato",sans-serif'
    options[:normalfontsize] = "11.0pt"
    options[:footnotefontsize] = "11.0pt"
  end
  super
end

#default_file_locations(_options) ⇒ Object



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

def default_file_locations(_options)
  {
    wordstylesheet: html_doc_path("wordstyle.scss"),
    standardstylesheet: html_doc_path("ogc.scss"),
    header: html_doc_path("header.html"),
    wordcoverpage: html_doc_path("word_ogc_titlepage.html"),
    wordintropage: html_doc_path("word_ogc_intro.html"),
    ulstyle: "l3",
    olstyle: "l2",
  }
end

#default_fonts(_options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/isodoc/ogc/word_convert.rb', line 18

def default_fonts(_options)
  {
    bodyfont: '"Times New Roman",serif',
    headerfont: '"Times New Roman",serif',
    monospacefont: '"Courier New",monospace',
    normalfontsize: "10.5pt",
    monospacefontsize: "10.0pt",
    footnotefontsize: "10.0pt",
    smallerfontsize: "10.0pt",
  }
end

#header_strip(hdr) ⇒ Object



67
68
69
70
# File 'lib/isodoc/ogc/word_convert.rb', line 67

def header_strip(hdr)
  hdr = hdr.to_s.gsub(/<\/?p[^>]*>/, "")
  super
end

#make_body(xml, docxml) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/isodoc/ogc/word_convert.rb', line 58

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/isodoc/ogc/word_convert.rb', line 89

def make_body2(body, docxml)
  body.div **{ class: "WordSection2" } do |div2|
    @prefacenum = 0
    info docxml, div2
    boilerplate docxml, div2
    preface_block docxml, div2
    abstract docxml, div2
    executivesummary docxml, div2
    keywords docxml, div2
    foreword docxml, div2
    introduction docxml, div2
    security docxml, div2
    submittingorgs docxml, div2
    submitters docxml, div2
    preface docxml, div2
    acknowledgements docxml, div2
    div2.p { |p| p << "&#xA0;" } # placeholder
  end
  section_break(body)
end

#recommmendation_sort_key1(type) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/isodoc/ogc/word_convert.rb', line 72

def recommmendation_sort_key1(type)
  case type.downcase
  when "requirements class" then "01"
  when "recommendations class" then "02"
  when "permissions class" then "03"
  when "requirement" then "04"
  when "recommendation" then "05"
  when "permission" then "06"
  when "conformance class" then "07"
  when "abstract test" then "08"
  when "requirements test" then "09"
  when "recommendations test" then "10"
  when "permissions test" then "11"
  else "z"
  end
end

#table_attrs(node) ⇒ Object



173
174
175
176
# File 'lib/isodoc/ogc/word_convert.rb', line 173

def table_attrs(node)
  node["class"] == "modspec" and node["width"] = "100%"
  super
end

#toWord(result, filename, dir, header) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/isodoc/ogc/word_convert.rb', line 158

def toWord(result, filename, dir, header)
  result = from_xhtml(word_cleanup(to_xhtml(result)))
    .gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
  @wordstylesheet = wordstylesheet_update
  Html2Doc.new(
    filename: filename, imagedir: @localdir,
    stylesheet: @wordstylesheet&.path,
    header_file: header&.path, dir: dir,
    asciimathdelims: [@openmathdelim, @closemathdelim],
    liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" }
  ).process(result)
  header&.unlink
  @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
end

#word_cleanup(docxml) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/isodoc/ogc/word_convert.rb', line 110

def word_cleanup(docxml)
  super
  word_recommend_cleanup(docxml)
  word_copyright_cleanup(docxml)
  word_license_cleanup(docxml)
  word_term_cleanup(docxml)
  docxml
end

center only the Copyright notice



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

def word_copyright_cleanup(docxml)
  x = "//div[@class = 'boilerplate-copyright']/div[1]/p[not(@class)]"
  docxml.xpath(x).each { |p| p["align"] = "center" }
  return unless @doctype == "white-paper"

  docxml.xpath("//div[@class = 'boilerplate-copyright']//p[not(@class)]")
    .each { |p| p["class"] = "license" }
  docxml.xpath("//div[@class = 'boilerplate-legal']//p[not(@class)]")
    .each { |p| p["class"] = "license" }
end

#word_license_cleanup(docxml) ⇒ Object



119
120
121
122
123
124
# File 'lib/isodoc/ogc/word_convert.rb', line 119

def word_license_cleanup(docxml)
  x = "//div[@class = 'boilerplate-license']//p[not(@class)]"
  docxml.xpath(x).each do |p|
    p["class"] = "license"
  end
end

#word_recommend_cleanup(docxml) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/isodoc/ogc/word_convert.rb', line 144

def word_recommend_cleanup(docxml)
  docxml.xpath("//table[@class = 'recommendtest']/thead/tr").each do |tr|
    style_update(tr, "background:#C9C9C9;")
  end
  docxml.xpath("//table[@class = 'recommend']/thead/tr").each do |tr|
    style_update(tr, "background:#A5A5A5;")
  end
  docxml.xpath("//table[@class = 'recommend']/tbody").each do |tr|
    tr.xpath("./tr").each_slice(2) do |_tr1, tr2|
      tr2 && style_update(tr2, "background:#C9C9C9;")
    end
  end
end

#word_term_cleanup(docxml) ⇒ Object



138
139
140
141
142
# File 'lib/isodoc/ogc/word_convert.rb', line 138

def word_term_cleanup(docxml)
  docxml.xpath("//p[@class = 'TermNum']//p[@class = 'Terms']").each do |p|
    p.replace(p.children)
  end
end