Class: IsoDoc::JIS::WordConvert
- Inherits:
-
WordConvert
- Object
- WordConvert
- IsoDoc::JIS::WordConvert
show all
- Includes:
- BaseConvert, Init
- Defined in:
- lib/isodoc/jis/word_convert.rb
Instance Method Summary
collapse
-
#biblio_paras(docxml) ⇒ Object
-
#bibliography(isoxml, out) ⇒ Object
-
#boldface(docxml) ⇒ Object
-
#cover_split(xml) ⇒ Object
-
#default_file_locations(_options) ⇒ Object
-
#default_fonts(options) ⇒ Object
-
#initialize(options) ⇒ WordConvert
constructor
A new instance of WordConvert.
-
#main_split(xml) ⇒ Object
-
#new_styles(docxml) ⇒ Object
-
#norm_ref(isoxml, out, num) ⇒ Object
-
#postprocess(result, filename, dir) ⇒ Object
-
#to_word1(result, filename, dir, header) ⇒ Object
-
#toWord(result, filename, dir, header) ⇒ Object
-
#word_cleanup(docxml) ⇒ Object
-
#word_note_cleanup(docxml) ⇒ Object
-
#word_split(xml) ⇒ Object
Methods included from Init
#i18n_init, #metadata_init, #omit_docid_prefix, #std_docid_semantic, #xref_init
#middle_subtitle_main, #middle_title, #middle_title_main
Constructor Details
#initialize(options) ⇒ WordConvert
Returns a new instance of WordConvert.
9
10
11
12
|
# File 'lib/isodoc/jis/word_convert.rb', line 9
def initialize(options)
@libdir = File.dirname(__FILE__)
super
end
|
Instance Method Details
#biblio_paras(docxml) ⇒ Object
143
144
145
146
147
|
# File 'lib/isodoc/jis/word_convert.rb', line 143
def biblio_paras(docxml)
docxml.xpath("//div[@class = 'normref']//p[not(@class)]").each do |p|
p["class"] = "NormRefText"
end
end
|
#bibliography(isoxml, out) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/isodoc/jis/word_convert.rb', line 126
def bibliography(isoxml, out)
(f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true") or
return
page_break(out)
out.div class: "bibliography" do |div|
div.h1 class: "Section3" do |h1|
f.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
end
biblio_list(f, div, true)
end
end
|
#boldface(docxml) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/jis/word_convert.rb', line 60
def boldface(docxml)
docxml.xpath("//h1 | h2 | h3 | h4 | h5 | h6").each do |h|
h.children = "<b>#{to_xml(h.children)}</b>"
end
docxml.xpath("//b").each do |b|
b.name = "span"
b["class"] = "Strong"
end
end
|
#cover_split(xml) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/isodoc/jis/word_convert.rb', line 97
def cover_split(xml)
xml.at("//body").elements.each do |e|
e.name == "div" && e["class"] == "WordSection1" and next
e.remove
end
xml
end
|
#default_file_locations(_options) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/isodoc/jis/word_convert.rb', line 24
def default_file_locations(_options)
{ htmlstylesheet: html_doc_path("htmlstyle.scss"),
htmlcoverpage: html_doc_path("html_jis_titlepage.html"),
htmlintropage: html_doc_path("html_jis_intro.html"),
wordstylesheet: html_doc_path("wordstyle.scss"),
standardstylesheet: html_doc_path("isodoc.scss"),
header: html_doc_path("header.html"),
wordcoverpage: html_doc_path("word_jis_titlepage.html"),
wordintropage: html_doc_path("word_jis_intro.html"),
ulstyle: "l9",
olstyle: "l8" }
end
|
#default_fonts(options) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/isodoc/jis/word_convert.rb', line 14
def default_fonts(options)
{ bodyfont: (options[:script] == "Jpan" ? '"MS Mincho",serif' : '"Times New Roman",serif'),
headerfont: (options[:script] == "Jpan" ? '"MS Gothic",sans-serif' : '"Arial",sans-serif'),
monospacefont: '"Courier New",monospace',
normalfontsize: "10.0pt",
monospacefontsize: "9.0pt",
smallerfontsize: "10.0pt",
footnotefontsize: "10.0pt" }
end
|
#main_split(xml) ⇒ Object
105
106
107
108
109
110
|
# File 'lib/isodoc/jis/word_convert.rb', line 105
def main_split(xml)
c = xml.at("//div[@class = 'WordSection1']")
c.next_element&.remove
c.remove
xml
end
|
#new_styles(docxml) ⇒ Object
138
139
140
141
|
# File 'lib/isodoc/jis/word_convert.rb', line 138
def new_styles(docxml)
super
biblio_paras(docxml)
end
|
#norm_ref(isoxml, out, num) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/isodoc/jis/word_convert.rb', line 112
def norm_ref(isoxml, out, num)
(f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true") or
return num
out.div class: "normref" do |div|
num += 1
clause_name(f, f.at(ns("./title")), div, nil)
if f.name == "clause"
f.elements.each { |e| parse(e, div) unless e.name == "title" }
else biblio_list(f, div, false)
end
end
num
end
|
#postprocess(result, filename, dir) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/isodoc/jis/word_convert.rb', line 37
def postprocess(result, filename, dir)
filename = filename.sub(/\.doc$/, "")
= (filename, dir)
result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
toWord(result, filename, dir, )
@files_to_delete.each { |f| FileUtils.rm_f f }
end
|
#to_word1(result, filename, dir, header) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/isodoc/jis/word_convert.rb', line 80
def to_word1(result, filename, dir, )
result or return
result = from_xhtml(result).gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
::Html2Doc::JIS.new(
filename: filename, imagedir: @localdir,
stylesheet: @wordstylesheet&.path,
header_file: &.path, dir: dir,
asciimathdelims: [@openmathdelim, @closemathdelim],
liststyles: { ul: @ulstyle, ol: @olstyle }
).process(result)
end
|
#toWord(result, filename, dir, header) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/isodoc/jis/word_convert.rb', line 70
def toWord(result, filename, dir, )
result = word_split(word_cleanup(to_xhtml(result)))
@wordstylesheet = wordstylesheet_update
result.each do |k, v|
to_word1(v, "#{filename}#{k}", dir, )
end
&.unlink
@wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
end
|
#word_cleanup(docxml) ⇒ Object
45
46
47
48
49
|
# File 'lib/isodoc/jis/word_convert.rb', line 45
def word_cleanup(docxml)
word_note_cleanup(docxml)
boldface(docxml)
super
end
|
#word_note_cleanup(docxml) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/isodoc/jis/word_convert.rb', line 51
def word_note_cleanup(docxml)
docxml.xpath("//p[@class = 'Note']").each do |p|
p.xpath("//following-sibling::p").each do |p2|
p2["class"] == "Note" and
p2["class"] = "NoteCont"
end
end
end
|
#word_split(xml) ⇒ Object
92
93
94
95
|
# File 'lib/isodoc/jis/word_convert.rb', line 92
def word_split(xml)
b = xml.dup
{ _cover: cover_split(xml), "": main_split(b) }
end
|