Module: IsoDoc::Function::ToWordHtml

Included in:
Common
Defined in:
lib/isodoc/function/to_word_html.rb

Instance Method Summary collapse

Instance Method Details

#bookmark_parse(node, out) ⇒ Object



132
133
134
# File 'lib/isodoc/function/to_word_html.rb', line 132

def bookmark_parse(node, out)
  out.a **attr_code(id: node["id"])
end

#define_head(html, filename, _dir) ⇒ Object

isodoc.css overrides any CSS injected by Html2Doc, which is inserted before this CSS.



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

def define_head(html, filename, _dir)
  html.head do |head|
    #head.title { |t| t << filename }
    if @standardstylesheet
      head.style do |style|
        stylesheet = File.read(@standardstylesheet, encoding: "utf-8").
          gsub("FILENAME", File.basename(filename))
        style.comment "\n#{stylesheet}\n"
      end
    end
  end
end

#em_parse(node, out) ⇒ Object



143
144
145
146
147
# File 'lib/isodoc/function/to_word_html.rb', line 143

def em_parse(node, out)
  out.i do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#in_sourcecodeObject



10
11
12
# File 'lib/isodoc/function/to_word_html.rb', line 10

def in_sourcecode
  @sourcecode
end

#info(isoxml, out) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/isodoc/function/to_word_html.rb', line 88

def info(isoxml, out)
  @meta.title isoxml, out
  @meta.subtitle isoxml, out
  @meta.docstatus isoxml, out
  @meta.docid isoxml, out
  @meta.doctype isoxml, out
  @meta.author isoxml, out
  @meta.bibdate isoxml, out
  @meta.relations isoxml, out
  @meta.version isoxml, out
  @meta.url isoxml, out
  @meta.get
end

#init_file(filename, debug) ⇒ Object



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

def init_file(filename, debug)
  filename = filename.gsub(%r{\.[^/.]+$}, "")
  dir = "#{filename}_files"
  unless debug
    Dir.mkdir(dir) unless File.exists?(dir)
    FileUtils.rm_rf "#{dir}/*"
  end
  @filename = filename
  @localdir = %r{/}.match(filename) ? filename.sub(%r{/[^/]+$}, "/") : "./"
  [filename, dir]
end

#keyword_parse(node, out) ⇒ Object



136
137
138
139
140
141
# File 'lib/isodoc/function/to_word_html.rb', line 136

def keyword_parse(node, out)
  out.span **{ class: "keyword" } do |s|
    #s << node.inner_html
    node.children.each { |n| parse(n, s) }
  end
end

#make_body(xml, docxml) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/isodoc/function/to_word_html.rb', line 54

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_body1(body, _docxml) ⇒ Object



63
64
65
66
67
68
# File 'lib/isodoc/function/to_word_html.rb', line 63

def make_body1(body, _docxml)
  body.div **{ class: "title-section" } do |div1|
    div1.p { |p| p << "&nbsp;" } # placeholder
  end
  section_break(body)
end

#make_body2(body, docxml) ⇒ Object



70
71
72
73
74
75
# File 'lib/isodoc/function/to_word_html.rb', line 70

def make_body2(body, docxml)
  body.div **{ class: "prefatory-section" } do |div2|
    div2.p { |p| p << "&nbsp;" } # placeholder
  end
  section_break(body)
end

#make_body3(body, docxml) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/isodoc/function/to_word_html.rb', line 77

def make_body3(body, docxml)
  body.div **{ class: "main-section" } do |div3|
    abstract docxml, div3
    foreword docxml, div3
    introduction docxml, div3
    middle docxml, div3
    footnotes div3
    comments div3
  end
end

#middle(isoxml, out) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/isodoc/function/to_word_html.rb', line 106

def middle(isoxml, out)
  middle_title(out)
  i = scope isoxml, out, 0
  i = norm_ref isoxml, out, i
  i = terms_defs isoxml, out, i
  i = symbols_abbrevs isoxml, out, i
  clause isoxml, out
  annex isoxml, out
  bibliography isoxml, out
end

#middle_title(out) ⇒ Object



102
103
104
# File 'lib/isodoc/function/to_word_html.rb', line 102

def middle_title(out)
  out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
end

#note?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/isodoc/function/to_word_html.rb', line 14

def note?
  @note
end

#parse(node, out) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/isodoc/function/to_word_html.rb', line 179

def parse(node, out)
  if node.text?
    text_parse(node, out)
  else
    case node.name
    when "em" then em_parse(node, out)
    when "strong" then strong_parse(node, out)
    when "sup" then sup_parse(node, out)
    when "sub" then sub_parse(node, out)
    when "tt" then tt_parse(node, out)
    when "strike" then strike_parse(node, out)
    when "keyword" then keyword_parse(node, out)
    when "smallcap" then smallcap_parse(node, out)
    when "br" then out.br
    when "hr" then out.hr
    when "bookmark" then bookmark_parse(node, out)
    when "pagebreak" then page_break(out)
    when "callout" then callout_parse(node, out)
    when "stem" then stem_parse(node, out)
    when "clause" then clause_parse(node, out)
    #when "appendix" then clause_parse(node, out)
    when "xref" then xref_parse(node, out)
    when "eref" then eref_parse(node, out)
    when "origin" then eref_parse(node, out)
    when "link" then link_parse(node, out)
    when "ul" then ul_parse(node, out)
    when "ol" then ol_parse(node, out)
    when "li" then li_parse(node, out)
    when "dl" then dl_parse(node, out)
    when "fn" then footnote_parse(node, out)
    when "p" then para_parse(node, out)
    when "quote" then quote_parse(node, out)
    when "tr" then tr_parse(node, out)
    when "note" then note_parse(node, out)
    when "review" then review_note_parse(node, out)
    when "admonition" then admonition_parse(node, out)
    when "formula" then formula_parse(node, out)
    when "table" then table_parse(node, out)
    when "figure" then figure_parse(node, out)
    when "example" then example_parse(node, out)
    when "image" then image_parse(node, out, nil)
    when "sourcecode" then sourcecode_parse(node, out)
    when "pre" then pre_parse(node, out)
    when "annotation" then annotation_parse(node, out)
    when "term" then termdef_parse(node, out)
    when "preferred" then term_parse(node, out)
    when "admitted" then admitted_term_parse(node, out)
    when "deprecates" then deprecated_term_parse(node, out)
    when "domain" then set_termdomain(node.text)
    when "definition" then definition_parse(node, out)
    when "termsource" then termref_parse(node, out)
    when "modification" then modification_parse(node, out)
    when "termnote" then termnote_parse(node, out)
    when "termexample" then example_parse(node, out)
    when "terms" then terms_parse(node, out)
    when "definitions" then symbols_parse(node, out)
    when "references" then bibliography_parse(node, out)
    when "termdocsource" then termdocsource_parse(node, out)
    when "requirement" then requirement_parse(node, out)
    when "recommendation" then recommendation_parse(node, out)
    when "permission" then permission_parse(node, out)
    when "subject" then requirement_skip_parse(node, out)
    when "inherit" then requirement_component_parse(node, out)
    when "description" then requirement_component_parse(node, out)
    when "specification" then requirement_component_parse(node, out)
    when "measurement-target" then requirement_component_parse(node, out)
    when "verification" then requirement_component_parse(node, out)
    when "import" then requirement_component_parse(node, out)
    else
      error_parse(node, out)
    end
  end
end

#rel_tmpimagedirObject



35
36
37
# File 'lib/isodoc/function/to_word_html.rb', line 35

def rel_tmpimagedir
  @filename.sub(%r{^.*/([^/]+)$}, "\\1") + tmpimagedir_suffix
end

#set_termdomain(termdomain) ⇒ Object



6
7
8
# File 'lib/isodoc/function/to_word_html.rb', line 6

def set_termdomain(termdomain)
  @termdomain = termdomain
end

#smallcap_parse(node, xml) ⇒ Object



117
118
119
120
121
122
# File 'lib/isodoc/function/to_word_html.rb', line 117

def smallcap_parse(node, xml)
  xml.span **{ style: "font-variant:small-caps;" } do |s|
    #s << node.inner_html
    node.children.each { |n| parse(n, s) }
  end
end

#strike_parse(node, out) ⇒ Object



173
174
175
176
177
# File 'lib/isodoc/function/to_word_html.rb', line 173

def strike_parse(node, out)
  out.s do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#strong_parse(node, out) ⇒ Object



149
150
151
152
153
# File 'lib/isodoc/function/to_word_html.rb', line 149

def strong_parse(node, out)
  out.b do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#sub_parse(node, out) ⇒ Object



161
162
163
164
165
# File 'lib/isodoc/function/to_word_html.rb', line 161

def sub_parse(node, out)
  out.sub do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#sup_parse(node, out) ⇒ Object



155
156
157
158
159
# File 'lib/isodoc/function/to_word_html.rb', line 155

def sup_parse(node, out)
  out.sup do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#text_parse(node, out) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/isodoc/function/to_word_html.rb', line 124

def text_parse(node, out)
  return if node.nil? || node.text.nil?
  text = node.to_s
  text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&nbsp;").
    gsub(/[ ](?=[ ])/, "&nbsp;") if in_sourcecode
  out << text
end

#tmpimagedirObject

tmp image dir is same directory as @filename



31
32
33
# File 'lib/isodoc/function/to_word_html.rb', line 31

def tmpimagedir
  @filename + tmpimagedir_suffix
end

#tt_parse(node, out) ⇒ Object



167
168
169
170
171
# File 'lib/isodoc/function/to_word_html.rb', line 167

def tt_parse(node, out)
  out.tt do |e|
    node.children.each { |n| parse(n, e) }
  end
end