ebps 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/InstalledFiles +36 -0
- data/LICENSE.txt +339 -0
- data/Manifest.txt +56 -0
- data/README.txt +28 -0
- data/Rakefile +28 -0
- data/SetupConfig +30 -0
- data/bin/ebps +86 -0
- data/example/config.yml +12 -0
- data/example/converter_for_firefox.rb +59 -0
- data/example/data.yml +60 -0
- data/example/example.sh +3 -0
- data/example/sample.epub +0 -0
- data/lib/ebps.rb +5 -0
- data/lib/ebps/config.rb +61 -0
- data/lib/ebps/conversion/de_fachinfo_yaml.rb +81 -0
- data/lib/ebps/conversion/epub.rb +38 -0
- data/lib/ebps/conversion/fachinfo_xml.rb +170 -0
- data/lib/ebps/conversion/fachinfo_yaml.rb +113 -0
- data/lib/ebps/conversion/import_module_sample.rb +86 -0
- data/lib/ebps/conversion/mobi_pocket.rb +30 -0
- data/lib/ebps/conversion/oebps.rb +537 -0
- data/lib/ebps/conversion/patinfo_yaml.rb +107 -0
- data/lib/ebps/data/default_cover.jpg +0 -0
- data/lib/ebps/data/stylesheet.css +16 -0
- data/lib/ebps/postprocess/bookworm.rb +16 -0
- data/lib/ebps/postprocess/copy.rb +28 -0
- data/lib/ebps/postprocess/system_call.rb +18 -0
- data/lib/ebps/preprocess/copy.rb +28 -0
- data/lib/ebps/preprocess/system_call.rb +18 -0
- data/lib/ebps/text/chapter.rb +36 -0
- data/lib/ebps/text/document.rb +36 -0
- data/lib/ebps/text/format.rb +34 -0
- data/lib/ebps/text/paragraph.rb +63 -0
- data/lib/ebps/text/picture.rb +41 -0
- data/lib/ebps/text/table.rb +65 -0
- data/lib/ebps/util/mail.rb +47 -0
- data/lib/ebps/util/smtp_tls.rb +62 -0
- data/spec/conversion/data/DF_15164_1_3.gif +0 -0
- data/spec/conversion/data/DF_15164_2_3.gif +0 -0
- data/spec/conversion/data/appendix.png +0 -0
- data/spec/conversion/data/fachinfo.xml +1151 -0
- data/spec/conversion/data/fachinfo.yaml +1214 -0
- data/spec/conversion/data/fachinfo_with_image.xml +334 -0
- data/spec/conversion/data/fachinfo_with_table.xml +1101 -0
- data/spec/conversion/data/fachinfos.de.oddb.yaml +5789 -0
- data/spec/conversion/data/images/5c/5c54d52c8132230e8c40c37a428fe761.png +0 -0
- data/spec/conversion/de_fachinfo_yaml_spec.rb +86 -0
- data/spec/conversion/epub_spec.rb +59 -0
- data/spec/conversion/fachinfo_xml_spec.rb +245 -0
- data/spec/conversion/fachinfo_yaml_spec.rb +52 -0
- data/spec/conversion/mobi_pocket_spec.rb +55 -0
- data/spec/conversion/oebps_spec.rb +555 -0
- data/spec/text/chapter_spec.rb +65 -0
- data/spec/text/document_spec.rb +78 -0
- data/spec/text/paragraph_spec.rb +77 -0
- metadata +145 -0
@@ -0,0 +1,555 @@
|
|
1
|
+
# - encoding:utf-8
|
2
|
+
$: << File.expand_path('../../lib', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'ebps/conversion/oebps'
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
module EBPS
|
8
|
+
module Conversion
|
9
|
+
describe Oebps, ".export" do
|
10
|
+
before :each do
|
11
|
+
@var = File.expand_path 'var', File.dirname(__FILE__)
|
12
|
+
FileUtils.mkdir_p @var
|
13
|
+
@doc1 = EBPS::Text::Document.new
|
14
|
+
@doc1.title = 'My Title'
|
15
|
+
c1 = EBPS::Text::Chapter.new
|
16
|
+
c1.heading << '1. Introduction'
|
17
|
+
c1.add_paragraph EBPS::Text::Paragraph.new('Some text')
|
18
|
+
@doc1.add_chapter c1
|
19
|
+
c2 = EBPS::Text::Chapter.new
|
20
|
+
c2.heading << '2. Abstract'
|
21
|
+
c2.add_paragraph EBPS::Text::Subheading.new('2.1 Current Status')
|
22
|
+
c2.add_paragraph EBPS::Text::Paragraph.new('Some more text')
|
23
|
+
par = EBPS::Text::Paragraph.new
|
24
|
+
par << 'Some '
|
25
|
+
par.set_format 'i'
|
26
|
+
par << 'formatted '
|
27
|
+
par.set_format 'b'
|
28
|
+
par << 'text '
|
29
|
+
par.set_format 'b', 'i'
|
30
|
+
par << 'bits.'
|
31
|
+
c2.add_paragraph par
|
32
|
+
@doc1.add_chapter c2
|
33
|
+
@doc2 = EBPS::Text::Document.new
|
34
|
+
@doc2.title = 'Much Shorter'
|
35
|
+
c3 = EBPS::Text::Chapter.new
|
36
|
+
c3.heading << '1. Short Story'
|
37
|
+
c3.add_paragraph EBPS::Text::Paragraph.new('Why did the Chicken?')
|
38
|
+
EBPS.config.language = 'en'
|
39
|
+
EBPS.config.xml_indent = 2
|
40
|
+
EBPS.config.content_title = 'Content'
|
41
|
+
EBPS.config.appendix = File.expand_path 'data/appendix.png',
|
42
|
+
File.dirname(__FILE__)
|
43
|
+
end
|
44
|
+
after :each do
|
45
|
+
FileUtils.rm_r @var
|
46
|
+
end
|
47
|
+
it "creates all necessary files and compiles the book to a temporary ouput file" do
|
48
|
+
result = StringIO.new
|
49
|
+
Oebps.export [@doc1, @doc2], result, @var do
|
50
|
+
Dir.entries(@var).should == [
|
51
|
+
".", "..",
|
52
|
+
"1_Much_Shorter.html",
|
53
|
+
"2_My_Title.html",
|
54
|
+
"m.html",
|
55
|
+
"toc.html",
|
56
|
+
"toc.ncx",
|
57
|
+
"default_cover.jpg",
|
58
|
+
"stylesheet.css",
|
59
|
+
"4c71d4170591f67d0e6d348057fb853b.gif",
|
60
|
+
"appendix.html",
|
61
|
+
"Much_Shorter.opf",
|
62
|
+
]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe Oebps, ".document_to_html" do
|
67
|
+
before :each do
|
68
|
+
@var = File.expand_path 'var', File.dirname(__FILE__)
|
69
|
+
FileUtils.mkdir_p @var
|
70
|
+
@doc = EBPS::Text::Document.new
|
71
|
+
@doc.title = 'My Title'
|
72
|
+
EBPS.config.xml_indent = 2
|
73
|
+
EBPS.config.content_title = 'Content'
|
74
|
+
end
|
75
|
+
after :each do
|
76
|
+
FileUtils.rm_r @var
|
77
|
+
end
|
78
|
+
it "returns valid xhtml for formatted text and creates appropriate ids" do
|
79
|
+
c1 = EBPS::Text::Chapter.new
|
80
|
+
c1.heading << '1. Introduction'
|
81
|
+
c1.add_paragraph EBPS::Text::Paragraph.new('Some text')
|
82
|
+
@doc.add_chapter c1
|
83
|
+
c2 = EBPS::Text::Chapter.new
|
84
|
+
c2.heading << '2. Abstract'
|
85
|
+
c2.add_paragraph EBPS::Text::Subheading.new('2.1 Current Status')
|
86
|
+
c2.add_paragraph EBPS::Text::Paragraph.new('Some more text')
|
87
|
+
par = EBPS::Text::Paragraph.new
|
88
|
+
par << 'Some '
|
89
|
+
par.set_format 'i'
|
90
|
+
par << 'formatted '
|
91
|
+
par.set_format 'b'
|
92
|
+
par << 'text '
|
93
|
+
par.set_format 'b', 'i'
|
94
|
+
par << 'bits.'
|
95
|
+
c2.add_paragraph par
|
96
|
+
@doc.add_chapter c2
|
97
|
+
ids = []
|
98
|
+
html, uid = Oebps.document_to_html @doc, ids, @var
|
99
|
+
uid.should == "id0b9be560c4916f41bec698920ce05edb"
|
100
|
+
doc = REXML::Document.new html
|
101
|
+
doc.should be_instance_of(REXML::Document)
|
102
|
+
html.should == <<-EOS
|
103
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
104
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
105
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
106
|
+
<head>
|
107
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
108
|
+
<title>My Title</title>
|
109
|
+
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
|
110
|
+
</head>
|
111
|
+
<body>
|
112
|
+
<h1 id="id0b9be560c4916f41bec698920ce05edb">My Title</h1>
|
113
|
+
<h2 id="toc-id0b9be560c4916f41bec698920ce05edb">Content</h2>
|
114
|
+
<p class="ebps">
|
115
|
+
<a href="#chapter-1-id0b9be560c4916f41bec698920ce05edb">1. Introduction</a>
|
116
|
+
<br/>
|
117
|
+
<a href="#chapter-2-id0b9be560c4916f41bec698920ce05edb">2. Abstract</a>
|
118
|
+
<br/>
|
119
|
+
</p>
|
120
|
+
<h3 id="chapter-1-id0b9be560c4916f41bec698920ce05edb">1. Introduction</h3>
|
121
|
+
<p class="ebps">
|
122
|
+
Some text
|
123
|
+
</p>
|
124
|
+
<h3 id="chapter-2-id0b9be560c4916f41bec698920ce05edb">2. Abstract</h3>
|
125
|
+
<h4 id="section-2.1-id0b9be560c4916f41bec698920ce05edb">
|
126
|
+
2.1 Current Status
|
127
|
+
</h4>
|
128
|
+
<p class="ebps">
|
129
|
+
Some more text
|
130
|
+
</p>
|
131
|
+
<p class="ebps">
|
132
|
+
Some
|
133
|
+
<i>
|
134
|
+
formatted
|
135
|
+
</i>
|
136
|
+
<b>
|
137
|
+
text
|
138
|
+
</b>
|
139
|
+
<b>
|
140
|
+
<i>
|
141
|
+
bits.
|
142
|
+
</i>
|
143
|
+
</b>
|
144
|
+
</p>
|
145
|
+
</body>
|
146
|
+
</html>
|
147
|
+
EOS
|
148
|
+
ids.should == [
|
149
|
+
["toc-id0b9be560c4916f41bec698920ce05edb", "Content"],
|
150
|
+
["chapter-1-id0b9be560c4916f41bec698920ce05edb", "1. Introduction", []],
|
151
|
+
["chapter-2-id0b9be560c4916f41bec698920ce05edb", "2. Abstract", [
|
152
|
+
["section-2.1-id0b9be560c4916f41bec698920ce05edb", "2.1 Current Status"]
|
153
|
+
]]
|
154
|
+
]
|
155
|
+
end
|
156
|
+
it "returns valid xhtml for images" do
|
157
|
+
c1 = EBPS::Text::Chapter.new
|
158
|
+
img = EBPS::Text::Picture.new
|
159
|
+
path = File.expand_path 'data/DF_15164_1_3.gif', File.dirname(__FILE__)
|
160
|
+
img << File.read(path)
|
161
|
+
c1.add_paragraph img
|
162
|
+
@doc.add_chapter c1
|
163
|
+
ids = []
|
164
|
+
html, uid = Oebps.document_to_html @doc, ids, @var
|
165
|
+
uid.should == "ideed7da47dbb8450b2f78767219133740"
|
166
|
+
doc = REXML::Document.new html
|
167
|
+
doc.should be_instance_of(REXML::Document)
|
168
|
+
html.should == <<-EOS
|
169
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
170
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
171
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
172
|
+
<head>
|
173
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
174
|
+
<title>My Title</title>
|
175
|
+
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
|
176
|
+
</head>
|
177
|
+
<body>
|
178
|
+
<h1 id="ideed7da47dbb8450b2f78767219133740">My Title</h1>
|
179
|
+
<p class="ebps">
|
180
|
+
<img src="51584f40d923ea229bd8ff3e5c3231fe.gif" alt=""/>
|
181
|
+
</p>
|
182
|
+
</body>
|
183
|
+
</html>
|
184
|
+
EOS
|
185
|
+
img_path = File.join @var, img.filename
|
186
|
+
File.should exist(img_path)
|
187
|
+
imgs = Magick::ImageList.new img_path
|
188
|
+
imgs.size.should == 1
|
189
|
+
img = imgs.first
|
190
|
+
img.should be_a(Magick::Image)
|
191
|
+
end
|
192
|
+
it "returns valid xhtml for tables" do
|
193
|
+
c1 = EBPS::Text::Chapter.new
|
194
|
+
table = EBPS::Text::Table.new
|
195
|
+
table << 'top left'
|
196
|
+
table.next_cell!
|
197
|
+
table << 'top right'
|
198
|
+
table.next_row!
|
199
|
+
table << 'bottom left'
|
200
|
+
table.next_cell!
|
201
|
+
table << 'bottom right'
|
202
|
+
c1.add_paragraph table
|
203
|
+
@doc.add_chapter c1
|
204
|
+
ids = []
|
205
|
+
html, uid = Oebps.document_to_html @doc, ids, @var
|
206
|
+
uid.should == "ide02909534e0d4ef2630973fb286eb2df"
|
207
|
+
doc = REXML::Document.new html
|
208
|
+
doc.should be_instance_of(REXML::Document)
|
209
|
+
html.should == <<-EOS
|
210
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
211
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
212
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
213
|
+
<head>
|
214
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
215
|
+
<title>My Title</title>
|
216
|
+
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
|
217
|
+
</head>
|
218
|
+
<body>
|
219
|
+
<h1 id="ide02909534e0d4ef2630973fb286eb2df">My Title</h1>
|
220
|
+
<table class="ebps">
|
221
|
+
<tbody>
|
222
|
+
<tr>
|
223
|
+
<td>
|
224
|
+
top left
|
225
|
+
</td>
|
226
|
+
<td>
|
227
|
+
top right
|
228
|
+
</td>
|
229
|
+
</tr>
|
230
|
+
<tr>
|
231
|
+
<td>
|
232
|
+
bottom left
|
233
|
+
</td>
|
234
|
+
<td>
|
235
|
+
bottom right
|
236
|
+
</td>
|
237
|
+
</tr>
|
238
|
+
</tbody>
|
239
|
+
</table>
|
240
|
+
</body>
|
241
|
+
</html>
|
242
|
+
EOS
|
243
|
+
end
|
244
|
+
end
|
245
|
+
describe Oebps, ".with_tmpdir" do
|
246
|
+
it "creates a new temporary directory" do
|
247
|
+
Oebps.with_tmpdir do |path|
|
248
|
+
path.should match %r{#{Dir.tmpdir}/.+}
|
249
|
+
File.should exist(path)
|
250
|
+
File.should be_writable(path)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
describe Oebps, ".to_opf" do
|
255
|
+
before :each do
|
256
|
+
@var = File.expand_path 'var', File.dirname(__FILE__)
|
257
|
+
FileUtils.mkdir_p @var
|
258
|
+
@doc1 = EBPS::Text::Document.new
|
259
|
+
@doc1.title = 'First Document\'s Title'
|
260
|
+
@doc2 = EBPS::Text::Document.new
|
261
|
+
EBPS.config.xml_indent = 2
|
262
|
+
EBPS.config.language = 'en'
|
263
|
+
end
|
264
|
+
after :each do
|
265
|
+
FileUtils.rm_r @var
|
266
|
+
EBPS.config.title = nil
|
267
|
+
end
|
268
|
+
it "returns valid xml" do
|
269
|
+
opf = Oebps.to_opf [@doc1, @doc2], [], @var
|
270
|
+
doc = REXML::Document.new opf
|
271
|
+
doc.should be_instance_of(REXML::Document)
|
272
|
+
opf.should == <<-EOS
|
273
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
274
|
+
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid">
|
275
|
+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
276
|
+
<dc:title>First Document's Title</dc:title>
|
277
|
+
<dc:language>en</dc:language>
|
278
|
+
<dc:identifier id="uid">id68b329da9893e34099c7d8ad5cb9c940</dc:identifier>
|
279
|
+
<dc:date>#{Date.today.strftime('%Y-%m-%d')}</dc:date>
|
280
|
+
<meta name="cover" content="cover"/>
|
281
|
+
</metadata>
|
282
|
+
<manifest>
|
283
|
+
</manifest>
|
284
|
+
<spine toc="toc">
|
285
|
+
</spine>
|
286
|
+
<guide>
|
287
|
+
<reference type="toc" title="Index" href="toc.html"/>
|
288
|
+
</guide>
|
289
|
+
</package>
|
290
|
+
EOS
|
291
|
+
end
|
292
|
+
it "uses config.title if set" do
|
293
|
+
EBPS.config.title = 'Configured Title'
|
294
|
+
opf = Oebps.to_opf [@doc1, @doc2], [], @var
|
295
|
+
doc = REXML::Document.new opf
|
296
|
+
doc.should be_instance_of(REXML::Document)
|
297
|
+
opf.should == <<-EOS
|
298
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
299
|
+
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid">
|
300
|
+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
301
|
+
<dc:title>Configured Title</dc:title>
|
302
|
+
<dc:language>en</dc:language>
|
303
|
+
<dc:identifier id="uid">id68b329da9893e34099c7d8ad5cb9c940</dc:identifier>
|
304
|
+
<dc:date>#{Date.today.strftime('%Y-%m-%d')}</dc:date>
|
305
|
+
<meta name="cover" content="cover"/>
|
306
|
+
</metadata>
|
307
|
+
<manifest>
|
308
|
+
</manifest>
|
309
|
+
<spine toc="toc">
|
310
|
+
</spine>
|
311
|
+
<guide>
|
312
|
+
<reference type="toc" title="Index" href="toc.html"/>
|
313
|
+
</guide>
|
314
|
+
</package>
|
315
|
+
EOS
|
316
|
+
end
|
317
|
+
it "creates the manifest directly from the contents of the tmpdir" do
|
318
|
+
EBPS.config.title = 'Configured Title'
|
319
|
+
FileUtils.touch File.join(@var, 'chapter1.html')
|
320
|
+
FileUtils.touch File.join(@var, 'chapter2.htm')
|
321
|
+
FileUtils.touch File.join(@var, 'toc.ncx')
|
322
|
+
FileUtils.touch File.join(@var, 'image1.gif')
|
323
|
+
FileUtils.touch File.join(@var, 'image2.jpeg')
|
324
|
+
opf = Oebps.to_opf [@doc1, @doc2], [
|
325
|
+
['chapter1.html', 'part1'],
|
326
|
+
['chapter2.htm', 'part2'] ], @var
|
327
|
+
doc = REXML::Document.new opf
|
328
|
+
doc.should be_instance_of(REXML::Document)
|
329
|
+
opf.should == <<-EOS
|
330
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
331
|
+
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid">
|
332
|
+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
333
|
+
<dc:title>Configured Title</dc:title>
|
334
|
+
<dc:language>en</dc:language>
|
335
|
+
<dc:identifier id="uid">id68b329da9893e34099c7d8ad5cb9c940</dc:identifier>
|
336
|
+
<dc:date>#{Date.today.strftime('%Y-%m-%d')}</dc:date>
|
337
|
+
<meta name="cover" content="cover"/>
|
338
|
+
</metadata>
|
339
|
+
<manifest>
|
340
|
+
<item id="part1" href="chapter1.html" media-type="application/xhtml+xml"/>
|
341
|
+
<item id="part2" href="chapter2.htm" media-type="application/xhtml+xml"/>
|
342
|
+
<item id="toc" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
343
|
+
<item id="image1" href="image1.gif" media-type="image/gif"/>
|
344
|
+
<item id="image2" href="image2.jpeg" media-type="image/jpeg"/>
|
345
|
+
</manifest>
|
346
|
+
<spine toc="toc">
|
347
|
+
<itemref idref="part1"/>
|
348
|
+
<itemref idref="part2"/>
|
349
|
+
</spine>
|
350
|
+
<guide>
|
351
|
+
<reference type="toc" title="Index" href="toc.html"/>
|
352
|
+
</guide>
|
353
|
+
</package>
|
354
|
+
EOS
|
355
|
+
end
|
356
|
+
it "raises a RuntimeError if there's a Html-File without generated ID" do
|
357
|
+
FileUtils.touch File.join(@var, 'chapter1.html')
|
358
|
+
lambda do
|
359
|
+
Oebps.to_opf [@doc1, @doc2], [], @var
|
360
|
+
end.should raise_error RuntimeError, "Unidentified Html-File 'chapter1.html'"
|
361
|
+
end
|
362
|
+
it "supplied ids for html-files are present in spine" do
|
363
|
+
EBPS.config.title = 'Configured Title'
|
364
|
+
FileUtils.touch File.join(@var, 'chapter1.html')
|
365
|
+
FileUtils.touch File.join(@var, 'chapter2.htm')
|
366
|
+
FileUtils.touch File.join(@var, 'image1.gif')
|
367
|
+
FileUtils.touch File.join(@var, 'image2.jpeg')
|
368
|
+
opf = Oebps.to_opf [@doc1, @doc2], [
|
369
|
+
['chapter1.html', 'first_chapter'],
|
370
|
+
['chapter2.htm', 'second_chapter'] ], @var
|
371
|
+
doc = REXML::Document.new opf
|
372
|
+
doc.should be_instance_of(REXML::Document)
|
373
|
+
opf.should == <<-EOS
|
374
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
375
|
+
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid">
|
376
|
+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
377
|
+
<dc:title>Configured Title</dc:title>
|
378
|
+
<dc:language>en</dc:language>
|
379
|
+
<dc:identifier id="uid">id68b329da9893e34099c7d8ad5cb9c940</dc:identifier>
|
380
|
+
<dc:date>#{Date.today.strftime('%Y-%m-%d')}</dc:date>
|
381
|
+
<meta name="cover" content="cover"/>
|
382
|
+
</metadata>
|
383
|
+
<manifest>
|
384
|
+
<item id="first_chapter" href="chapter1.html" media-type="application/xhtml+xml"/>
|
385
|
+
<item id="second_chapter" href="chapter2.htm" media-type="application/xhtml+xml"/>
|
386
|
+
<item id="image1" href="image1.gif" media-type="image/gif"/>
|
387
|
+
<item id="image2" href="image2.jpeg" media-type="image/jpeg"/>
|
388
|
+
</manifest>
|
389
|
+
<spine toc="toc">
|
390
|
+
<itemref idref="first_chapter"/>
|
391
|
+
<itemref idref="second_chapter"/>
|
392
|
+
</spine>
|
393
|
+
<guide>
|
394
|
+
<reference type="toc" title="Index" href="toc.html"/>
|
395
|
+
</guide>
|
396
|
+
</package>
|
397
|
+
EOS
|
398
|
+
end
|
399
|
+
end
|
400
|
+
describe Oebps, ".filename" do
|
401
|
+
it "replaces empty document titles with 'part'" do
|
402
|
+
doc = EBPS::Text::Document.new
|
403
|
+
Oebps.document_filename(doc, 1).should == '1_part.html'
|
404
|
+
end
|
405
|
+
it "replaces whitespace with '_'" do
|
406
|
+
doc = EBPS::Text::Document.new
|
407
|
+
doc.title << 'Some Document Title'
|
408
|
+
Oebps.document_filename(doc, 2).should == '2_Some_Document_Title.html'
|
409
|
+
end
|
410
|
+
it "removes non-ascii-chars" do
|
411
|
+
doc = EBPS::Text::Document.new
|
412
|
+
doc.title << 'Söme Docüment Titlé'
|
413
|
+
Oebps.document_filename(doc, 3).should == '3_Sme_Docment_Titl.html'
|
414
|
+
end
|
415
|
+
end
|
416
|
+
describe Oebps, ".to_ncx" do
|
417
|
+
before :each do
|
418
|
+
@doc1 = EBPS::Text::Document.new
|
419
|
+
@doc1.title = 'First Document\'s Title'
|
420
|
+
@doc2 = EBPS::Text::Document.new
|
421
|
+
EBPS.config.xml_indent = 2
|
422
|
+
EBPS.config.title = 'Configured Title'
|
423
|
+
EBPS.config.language = 'en'
|
424
|
+
end
|
425
|
+
after :each do
|
426
|
+
EBPS.config.title = nil
|
427
|
+
end
|
428
|
+
it "returns valid xml" do
|
429
|
+
ids = [
|
430
|
+
['part1.html', 'part1', 'First Document\'s Title', [
|
431
|
+
[ 'toc-id', 'Content', [] ],
|
432
|
+
[ 'chapter-id', 'Heading', [
|
433
|
+
[ 'section-id', 'Subheading' ]
|
434
|
+
] ],
|
435
|
+
] ]
|
436
|
+
]
|
437
|
+
ncx = Oebps.to_ncx [@doc1, @doc2], ids, @var
|
438
|
+
doc = REXML::Document.new ncx
|
439
|
+
doc.should be_instance_of(REXML::Document)
|
440
|
+
ncx.should == <<-EOS
|
441
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
442
|
+
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
|
443
|
+
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" xml:lang="en" version="2005-1">
|
444
|
+
<head>
|
445
|
+
<meta name="dtb:uid" content="id68b329da9893e34099c7d8ad5cb9c940"/>
|
446
|
+
<meta name="dtb:depth" content="3"/>
|
447
|
+
<meta name="dtb:generator" content="EBPS::Conversion::Oebps::NcxFactory"/>
|
448
|
+
<meta name="dtb:totalPageCount" content="1"/>
|
449
|
+
<meta name="dtb:maxPageNumber" content="1"/>
|
450
|
+
</head>
|
451
|
+
<docTitle>
|
452
|
+
<text>Configured Title</text>
|
453
|
+
</docTitle>
|
454
|
+
<navMap>
|
455
|
+
<navPoint id="part1" playOrder="1">
|
456
|
+
<navLabel>
|
457
|
+
<text>First Document's Title</text>
|
458
|
+
</navLabel>
|
459
|
+
<content src="part1.html"/>
|
460
|
+
<navPoint id="toc-id" playOrder="2">
|
461
|
+
<navLabel>
|
462
|
+
<text>Content</text>
|
463
|
+
</navLabel>
|
464
|
+
<content src="part1.html#toc-id"/>
|
465
|
+
</navPoint>
|
466
|
+
<navPoint id="chapter-id" playOrder="3">
|
467
|
+
<navLabel>
|
468
|
+
<text>Heading</text>
|
469
|
+
</navLabel>
|
470
|
+
<content src="part1.html#chapter-id"/>
|
471
|
+
<navPoint id="section-id" playOrder="4">
|
472
|
+
<navLabel>
|
473
|
+
<text>Subheading</text>
|
474
|
+
</navLabel>
|
475
|
+
<content src="part1.html#section-id"/>
|
476
|
+
</navPoint>
|
477
|
+
</navPoint>
|
478
|
+
</navPoint>
|
479
|
+
</navMap>
|
480
|
+
</ncx>
|
481
|
+
EOS
|
482
|
+
end
|
483
|
+
end
|
484
|
+
describe Oebps, ".to_index" do
|
485
|
+
before :each do
|
486
|
+
@var = File.expand_path 'var', File.dirname(__FILE__)
|
487
|
+
FileUtils.mkdir_p @var
|
488
|
+
EBPS.config.xml_indent = 2
|
489
|
+
EBPS.config.content_title = 'Content'
|
490
|
+
end
|
491
|
+
after :each do
|
492
|
+
FileUtils.rm_r @var
|
493
|
+
end
|
494
|
+
it "returns valid xhtml for the main index" do
|
495
|
+
keys = [[ 'a.html', 'a', 'A' ], [ 'b.html', 'b', 'B' ] ]
|
496
|
+
html = Oebps.to_index 'index', keys, [], @var
|
497
|
+
doc = REXML::Document.new html
|
498
|
+
doc.should be_instance_of(REXML::Document)
|
499
|
+
html.should == <<-EOS
|
500
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
501
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
502
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
503
|
+
<head>
|
504
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
505
|
+
<title>index</title>
|
506
|
+
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
|
507
|
+
</head>
|
508
|
+
<body id="index">
|
509
|
+
<p class="ebps">
|
510
|
+
<a href="a.html">A</a>
|
511
|
+
<br/>
|
512
|
+
<a href="b.html">B</a>
|
513
|
+
<br/>
|
514
|
+
</p>
|
515
|
+
</body>
|
516
|
+
</html>
|
517
|
+
EOS
|
518
|
+
end
|
519
|
+
it "returns valid xhtml for alphabetical indices" do
|
520
|
+
keys = [
|
521
|
+
[ "1_My_Title.html", "0b9be560c4916f41bec698920ce05edb", "My Title",
|
522
|
+
[ ["toc-0b9be560c4916f41bec698920ce05edb", "Content"],
|
523
|
+
["chapter-1-0b9be560c4916f41bec698920ce05edb", "1. Introduction",
|
524
|
+
[] ],
|
525
|
+
["chapter-2-0b9be560c4916f41bec698920ce05edb", "2. Abstract",
|
526
|
+
[ ["section-2.1-0b9be560c4916f41bec698920ce05edb",
|
527
|
+
"2.1 Current Status"]]]]],
|
528
|
+
["2_Much_Shorter.html", "d41d8cd98f00b204e9800998ecf8427e",
|
529
|
+
"Much Shorter", []]]
|
530
|
+
html = Oebps.to_index 'm', keys, [], @var
|
531
|
+
doc = REXML::Document.new html
|
532
|
+
doc.should be_instance_of(REXML::Document)
|
533
|
+
html.should == <<-EOS
|
534
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
535
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
536
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
537
|
+
<head>
|
538
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
539
|
+
<title>m</title>
|
540
|
+
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
|
541
|
+
</head>
|
542
|
+
<body id="m">
|
543
|
+
<p class="ebps">
|
544
|
+
<a href="1_My_Title.html">My Title</a>
|
545
|
+
<br/>
|
546
|
+
<a href="2_Much_Shorter.html">Much Shorter</a>
|
547
|
+
<br/>
|
548
|
+
</p>
|
549
|
+
</body>
|
550
|
+
</html>
|
551
|
+
EOS
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
555
|
+
end
|