gepub 0.7.0beta1 → 0.7.0beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/gepub/book.rb +51 -11
- data/lib/gepub/builder.rb +3 -1
- data/lib/gepub/metadata.rb +9 -1
- data/lib/gepub/package.rb +1 -0
- data/lib/gepub/version.rb +1 -1
- data/spec/book_spec.rb +5 -0
- data/spec/builder_spec.rb +22 -17
- data/spec/gepub_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2afcf92b07b1b44821ac597b73dcc8294fb185c
|
4
|
+
data.tar.gz: f6019eace6b777af7b2339df1921aaaa3b29cdde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0737564831bfb33d14959ead4304e2c1b43bbe5aabca34700da7d47357c1c0f606d81fc6added90846c16b203833570e7de00f791f92e6fde0b00017fbdedcf
|
7
|
+
data.tar.gz: f213252ad81213d2680d653a4254951a979ea91893e1bfc625490398525401a3bf9d6240e7fa25ccaa11a8f90e88ebcec33f62d92641cf11c655b7abcf8b29d1
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# gepub
|
2
|
+
|
3
|
+
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/skoji/gepub?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
2
4
|
[<img src="https://secure.travis-ci.org/skoji/gepub.png" />](http://travis-ci.org/skoji/gepub)
|
3
5
|
[![Coverage Status](https://coveralls.io/repos/skoji/gepub/badge.png?branch=master)](https://coveralls.io/r/skoji/gepub?branch=master)
|
4
6
|
[![Dependency Status](https://gemnasium.com/skoji/gepub.png)](https://gemnasium.com/skoji/gepub)
|
@@ -18,7 +20,10 @@ a generic EPUB parser/generator library.
|
|
18
20
|
|
19
21
|
* See [issues](https://github.com/skoji/gepub/issues/) for known problems.
|
20
22
|
|
21
|
-
|
23
|
+
If you are using GEPUB::Builder from your code and do not like its behaviour(e.g. the block inside is evaluated as inside the Builder instance), please consider using GEPUB::Book directly.
|
24
|
+
|
25
|
+
** GEPUB::Builder will be obsolete in gepub 0.7. GEPUB::Book#new will be enhanced instead of Builder DSL. **
|
26
|
+
|
22
27
|
|
23
28
|
## SYNOPSIS:
|
24
29
|
|
data/lib/gepub/book.rb
CHANGED
@@ -264,11 +264,59 @@ module GEPUB
|
|
264
264
|
EOF
|
265
265
|
end
|
266
266
|
|
267
|
+
|
268
|
+
# add tocdata like this : [ {link: chapter1.xhtml, text: 'Capter 1', level: 1} ] .
|
269
|
+
# if item corresponding to the link does not exists, error will be thrown.
|
270
|
+
def add_tocdata(toc_yaml)
|
271
|
+
newtoc = []
|
272
|
+
toc_yaml.each do |toc_entry|
|
273
|
+
href, id = toc_entry[:link].split('#')
|
274
|
+
item = @package.manifest.item_by_href(href)
|
275
|
+
throw "#{href} does not exist." if item.nil?
|
276
|
+
newtoc.push({item: item, id: id, text: toc_entry[:text], level: toc_entry[:level] })
|
277
|
+
end
|
278
|
+
@toc = @toc + newtoc
|
279
|
+
end
|
280
|
+
|
267
281
|
def generate_nav_doc(title = 'Table of Contents')
|
268
282
|
add_item('nav.html', StringIO.new(nav_doc(title)), 'nav').add_property('nav')
|
269
283
|
end
|
270
|
-
|
284
|
+
|
271
285
|
def nav_doc(title = 'Table of Contents')
|
286
|
+
# handle cascaded toc
|
287
|
+
start_level = @toc && @toc[0][:level] || 1
|
288
|
+
stacked_toc = {level: start_level, tocs: [] }
|
289
|
+
@toc.inject(stacked_toc) do |current_stack, toc_entry|
|
290
|
+
toc_entry_level = toc_entry[:level] || 1
|
291
|
+
if current_stack[:level] < toc_entry_level
|
292
|
+
new_stack = { level: toc_entry_level, tocs: [], parent: current_stack}
|
293
|
+
current_stack[:tocs].last[:child_stack] = new_stack
|
294
|
+
current_stack = new_stack
|
295
|
+
else
|
296
|
+
while current_stack[:level] > toc_entry_level and
|
297
|
+
!current_stack[:parent].nil?
|
298
|
+
current_stack = current_stack[:parent]
|
299
|
+
end
|
300
|
+
end
|
301
|
+
current_stack[:tocs].push toc_entry
|
302
|
+
current_stack
|
303
|
+
end
|
304
|
+
# write toc
|
305
|
+
def write_toc xml_doc, tocs
|
306
|
+
xml_doc.ol {
|
307
|
+
tocs.each {
|
308
|
+
|x|
|
309
|
+
id = x[:id].nil? ? "" : "##{x[:id]}"
|
310
|
+
xml_doc.li {
|
311
|
+
xml_doc.a({'href' => x[:item].href + id} ,x[:text])
|
312
|
+
if x[:child_stack] && x[:child_stack][:tocs].size > 0
|
313
|
+
write_toc(xml_doc, x[:child_stack][:tocs])
|
314
|
+
end
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
end
|
319
|
+
# build nav
|
272
320
|
builder = Nokogiri::XML::Builder.new {
|
273
321
|
|doc|
|
274
322
|
doc.html('xmlns' => "http://www.w3.org/1999/xhtml",'xmlns:epub' => "http://www.idpf.org/2007/ops") {
|
@@ -276,15 +324,7 @@ EOF
|
|
276
324
|
doc.body {
|
277
325
|
doc.nav('epub:type' => 'toc', 'id' => 'toc') {
|
278
326
|
doc.h1 "#{title}"
|
279
|
-
doc
|
280
|
-
@toc.each {
|
281
|
-
|x|
|
282
|
-
id = x[:id].nil? ? "" : "##{x[:id]}"
|
283
|
-
doc.li {
|
284
|
-
doc.a({'href' => x[:item].href + id} ,x[:text])
|
285
|
-
}
|
286
|
-
}
|
287
|
-
}
|
327
|
+
write_toc(doc, stacked_toc[:tocs])
|
288
328
|
}
|
289
329
|
}
|
290
330
|
}
|
@@ -309,7 +349,7 @@ EOF
|
|
309
349
|
xml.navMap {
|
310
350
|
@toc.each {
|
311
351
|
|x|
|
312
|
-
xml.navPoint('id' => "#{x[:item].itemid}", 'playOrder' => "#{count}") {
|
352
|
+
xml.navPoint('id' => "#{x[:item].itemid}##{x[:id]}", 'playOrder' => "#{count}") {
|
313
353
|
xml.navLabel {
|
314
354
|
xml.text_ "#{x[:text]}"
|
315
355
|
}
|
data/lib/gepub/builder.rb
CHANGED
data/lib/gepub/metadata.rb
CHANGED
@@ -158,6 +158,10 @@ module GEPUB
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
+
def title=(content)
|
162
|
+
title(content)
|
163
|
+
end
|
164
|
+
|
161
165
|
def title(content=UNASSIGNED, id = nil, title_type = nil)
|
162
166
|
if unassigned?(content)
|
163
167
|
if !@content_nodes['title'].nil?
|
@@ -216,7 +220,7 @@ module GEPUB
|
|
216
220
|
end
|
217
221
|
|
218
222
|
def set_title(content, id = nil, title_type = nil)
|
219
|
-
warn "obsolete : set_title. use title instead."
|
223
|
+
warn "obsolete : set_title. use title or title= instead."
|
220
224
|
title_clear
|
221
225
|
meta = add_title(content, id, title_type)
|
222
226
|
yield meta if block_given?
|
@@ -264,6 +268,10 @@ module GEPUB
|
|
264
268
|
lastmodified Time.now
|
265
269
|
end
|
266
270
|
|
271
|
+
def lastmodified=(date)
|
272
|
+
lastmodified(date)
|
273
|
+
end
|
274
|
+
|
267
275
|
def set_lastmodified(date=nil)
|
268
276
|
warn "obsolete : set_lastmodified. use lastmodified instead."
|
269
277
|
date ||= Time.now
|
data/lib/gepub/package.rb
CHANGED
@@ -15,6 +15,7 @@ module GEPUB
|
|
15
15
|
}.flatten
|
16
16
|
def_delegators :@metadata, :set_lastmodified
|
17
17
|
def_delegators :@metadata, :lastmodified
|
18
|
+
def_delegators :@metadata, :lastmodified=
|
18
19
|
def_delegators :@metadata, :modified_now
|
19
20
|
def_delegators :@metadata, :rendition_layout
|
20
21
|
def_delegators :@metadata, :rendition_layout=
|
data/lib/gepub/version.rb
CHANGED
data/spec/book_spec.rb
CHANGED
@@ -239,6 +239,11 @@ describe GEPUB::Book do
|
|
239
239
|
book.lastmodified(Time.parse('2012-9-12 00:00:00Z'))
|
240
240
|
expect(book.lastmodified.content).to eq(Time.parse('2012-9-12 00:00:00 UTC'))
|
241
241
|
end
|
242
|
+
it 'set time in string : using assign method' do
|
243
|
+
book = GEPUB::Book.new
|
244
|
+
book.lastmodified = Time.parse('2012-9-12 00:00:00Z')
|
245
|
+
expect(book.lastmodified.content).to eq(Time.parse('2012-9-12 00:00:00 UTC'))
|
246
|
+
end
|
242
247
|
end
|
243
248
|
describe 'page_progression_direction=' do
|
244
249
|
it 'set page_progression_direction' do
|
data/spec/builder_spec.rb
CHANGED
@@ -385,10 +385,10 @@ describe GEPUB::Builder do
|
|
385
385
|
expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[0] }).to eq('rendition:layout-pre-paginated')
|
386
386
|
expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[1] }).to eq('rendition:orientation-landscape')
|
387
387
|
expect(builder.instance_eval{ @book.spine.itemref_list[1].properties[2] }).to eq('rendition:spread-both')
|
388
|
-
builder.instance_eval{
|
389
|
-
|
390
|
-
xml.root['prefix'].should == 'rendition: http://www.idpf.org/vocab/rendition/#'
|
388
|
+
xml = builder.instance_eval{
|
389
|
+
Nokogiri::XML::Document.parse @book.opf_xml
|
391
390
|
}
|
391
|
+
expect(xml.root['prefix']).to eq 'rendition: http://www.idpf.org/vocab/rendition/#'
|
392
392
|
end
|
393
393
|
|
394
394
|
it 'whould handle ibooks version' do
|
@@ -519,9 +519,10 @@ describe GEPUB::Builder do
|
|
519
519
|
file 'with_remote.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p><video src="http://foo.bar">no video</video></p></div></body></html>')
|
520
520
|
}
|
521
521
|
}
|
522
|
-
builder.instance_eval {
|
523
|
-
@book.item_by_href('with_remote.xhtml').properties[0]
|
522
|
+
prop = builder.instance_eval {
|
523
|
+
@book.item_by_href('with_remote.xhtml').properties[0]
|
524
524
|
}
|
525
|
+
expect(prop).to eq 'remote-resources'
|
525
526
|
end
|
526
527
|
|
527
528
|
it 'should handle remote resource URL' do
|
@@ -541,9 +542,10 @@ describe GEPUB::Builder do
|
|
541
542
|
file 'mathml.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p><math xmlns="http://www.w3.org/1998/Math/MathML"></math></p></div></body></html>')
|
542
543
|
}
|
543
544
|
}
|
544
|
-
builder.instance_eval {
|
545
|
-
@book.item_by_href('mathml.xhtml').properties[0]
|
545
|
+
prop = builder.instance_eval {
|
546
|
+
@book.item_by_href('mathml.xhtml').properties[0]
|
546
547
|
}
|
548
|
+
expect(prop).to eq 'mathml'
|
547
549
|
end
|
548
550
|
|
549
551
|
it 'should handle svg' do
|
@@ -553,9 +555,10 @@ describe GEPUB::Builder do
|
|
553
555
|
file 'svg.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head></head><body><div><p><svg xmlns="http://www.w3.org/2000/svg"></svg></p></div></body></html>')
|
554
556
|
}
|
555
557
|
}
|
556
|
-
builder.instance_eval {
|
557
|
-
@book.item_by_href('svg.xhtml').properties[0]
|
558
|
+
prop = builder.instance_eval {
|
559
|
+
@book.item_by_href('svg.xhtml').properties[0]
|
558
560
|
}
|
561
|
+
expect(prop).to eq 'svg'
|
559
562
|
end
|
560
563
|
|
561
564
|
it 'should handle epub:switch' do
|
@@ -577,9 +580,10 @@ describe GEPUB::Builder do
|
|
577
580
|
</epub:switch></p></div></body></html>')
|
578
581
|
}
|
579
582
|
}
|
580
|
-
builder.instance_eval {
|
581
|
-
@book.item_by_href('switch.xhtml').properties[0]
|
583
|
+
prop = builder.instance_eval {
|
584
|
+
@book.item_by_href('switch.xhtml').properties[0]
|
582
585
|
}
|
586
|
+
expect(prop).to eq 'switch'
|
583
587
|
end
|
584
588
|
|
585
589
|
it 'should handle scripted property' do
|
@@ -589,18 +593,19 @@ describe GEPUB::Builder do
|
|
589
593
|
file 'scripted.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"><head><script>alert("scripted");</script></head><body><div><p>text comes here</p></div></body></html>')
|
590
594
|
}
|
591
595
|
}
|
592
|
-
builder.instance_eval {
|
593
|
-
@book.item_by_href('scripted.xhtml').properties[0]
|
594
|
-
}
|
596
|
+
expect(builder.instance_eval {
|
597
|
+
@book.item_by_href('scripted.xhtml').properties[0]
|
598
|
+
}).to eq 'scripted'
|
595
599
|
end
|
596
600
|
|
597
601
|
it 'should handle optional file' do
|
598
602
|
builder = GEPUB::Builder.new {
|
599
603
|
optional_file 'META-INF/test.xml' => StringIO.new('<test></test>')
|
600
604
|
}
|
601
|
-
builder.instance_eval {
|
602
|
-
@book.optional_files.size
|
603
|
-
}
|
605
|
+
expect(builder.instance_eval {
|
606
|
+
@book.optional_files.size
|
607
|
+
}).to eq 1
|
608
|
+
|
604
609
|
expect(builder.instance_eval {
|
605
610
|
@book.optional_files['META-INF/test.xml']
|
606
611
|
}).not_to be_nil
|
data/spec/gepub_spec.rb
CHANGED
@@ -113,7 +113,7 @@ EOF
|
|
113
113
|
|
114
114
|
expect(ncx.xpath('xmlns:navMap').size).to be > 0
|
115
115
|
nav_point = ncx.at_xpath('xmlns:navMap/xmlns:navPoint')
|
116
|
-
expect(nav_point['id']).to eq('c2')
|
116
|
+
expect(nav_point['id']).to eq('c2#')
|
117
117
|
expect(nav_point['playOrder']).to eq('1')
|
118
118
|
|
119
119
|
expect(nav_point.at_xpath('xmlns:navLabel/xmlns:text').content).to eq('test chapter')
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gepub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.0beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KOJIMA Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: 1.3.1
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project: gepub
|
170
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.4.5
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: a generic EPUB library for Ruby.
|