gepub 0.6.3 → 0.6.3.1

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/.gitignore CHANGED
@@ -19,8 +19,7 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
- testepub.epub
23
- testepub2.epub
22
+ testepub*.epub
24
23
  example_test*.epub
25
24
 
26
25
  ## BUNDLER
data/README.md CHANGED
@@ -10,7 +10,7 @@ a generic EPUB parser/generator library.
10
10
 
11
11
  * GEPUB::Book provides functionality to create EPUB file, and parsing EPUB file
12
12
  * Handle every metadata in EPUB2/EPUB3.
13
- * Soon, I will provide easy to generate EPUB class, like Nokogiri::XML::Generator.
13
+ * GEPUB::Builder privides easy and powerful way to create EPUB3 files
14
14
 
15
15
  * See [issues](https://github.com/skoji/gepub/issues/) for known problems.
16
16
 
@@ -20,7 +20,6 @@ a generic EPUB parser/generator library.
20
20
 
21
21
  require 'rubygem'
22
22
  require 'gepub'
23
- workdir = 'epub/example/'
24
23
  builder = GEPUB::Builder.new {
25
24
  unique_identifier 'http:/example.jp/bookid_in_url', 'BookID', 'URL'
26
25
  language 'en'
@@ -36,7 +35,7 @@ a generic EPUB parser/generator library.
36
35
 
37
36
  date '2012-02-29T00:00:00Z'
38
37
 
39
- resources(:workdir => workdir) {
38
+ resources(:workdir => '~/epub/sample_book_source/') {
40
39
  cover_image 'img/image1.jpg' => 'image1.jpg'
41
40
  ordered {
42
41
  file 'text/chap1.xhtml'
@@ -50,7 +49,9 @@ a generic EPUB parser/generator library.
50
49
  epubname = File.join(File.dirname(__FILE__), 'example_test_with_builder.epub')
51
50
  builder.generate_epub(epubname)
52
51
 
53
- [examples](https://github.com/skoji/gepub/tree/master/examples/)
52
+ [more builder examples](https://gist.github.com/1878995)
53
+
54
+ [examples in this repository](https://github.com/skoji/gepub/tree/master/examples/)
54
55
 
55
56
  ## INSTALL:
56
57
 
data/lib/gepub/book.rb CHANGED
@@ -83,16 +83,18 @@ module GEPUB
83
83
  def add_item(href, io_or_filename = nil, id = nil, attributes = {})
84
84
  item = @package.add_item(href,io_or_filename,id,attributes)
85
85
  toc = @toc
86
- (class << item;self;end).send(:define_method, :toc_text,
86
+ metaclass = (class << item;self;end)
87
+ metaclass.send(:define_method, :toc_text,
87
88
  Proc.new { |text|
88
89
  toc.push(:item => item, :text => text, :id => nil)
89
90
  item
90
- })
91
- (class << item;self;end).send(:define_method, :toc_text_with_id,
91
+ })
92
+ metaclass.send(:define_method, :toc_text_with_id,
92
93
  Proc.new { |text, id|
93
94
  toc.push(:item => item, :text => text, :id => id)
94
95
  item
95
- })
96
+ })
97
+
96
98
  yield item if block_given?
97
99
  item
98
100
  end
@@ -117,8 +119,7 @@ module GEPUB
117
119
  @package.ordered(&block)
118
120
  end
119
121
 
120
- def generate_epub(path_to_epub)
121
-
122
+ def cleanup
122
123
  if version.to_f < 3.0 || @package.epub_backward_compat
123
124
  if @package.manifest.item_list.select {
124
125
  |x,item|
@@ -133,30 +134,52 @@ module GEPUB
133
134
 
134
135
  if version.to_f >=3.0
135
136
  @package.metadata.set_lastmodified
137
+
136
138
  if @package.manifest.item_list.select {
137
139
  |href, item|
138
140
  (item.properties||[]).member? 'nav'
139
141
  }.size == 0
140
142
  generate_nav_doc
141
143
  end
144
+
145
+ @package.spine.remove_with_idlist @package.manifest.item_list.map {
146
+ |href, item|
147
+ item.fallback
148
+ }.reject(&:nil?)
149
+
142
150
  end
151
+ end
152
+
153
+ def write_to_epub_container(epub)
154
+ epub.put_next_entry('mimetype', '', '', Zip::ZipEntry::STORED)
155
+ epub << "application/epub+zip"
156
+ epub.put_next_entry('META-INF/container.xml')
157
+ epub << container_xml
143
158
 
159
+ epub.put_next_entry(@package.path)
160
+ epub << opf_xml
161
+
162
+ @package.manifest.item_list.each {
163
+ |k, item|
164
+ epub.put_next_entry(@package.contents_prefix + item.href)
165
+ epub << item.content
166
+ }
167
+ end
168
+
169
+ def generate_epub_stream
170
+ cleanup
171
+ Zip::ZipOutputStream::write_buffer {
172
+ |epub|
173
+ write_to_epub_container(epub)
174
+ }
175
+ end
176
+
177
+ def generate_epub(path_to_epub)
178
+ cleanup
144
179
  File.delete(path_to_epub) if File.exist?(path_to_epub)
145
180
  Zip::ZipOutputStream::open(path_to_epub) {
146
181
  |epub|
147
- epub.put_next_entry('mimetype', '', '', Zip::ZipEntry::STORED)
148
- epub << "application/epub+zip"
149
- epub.put_next_entry('META-INF/container.xml')
150
- epub << container_xml
151
-
152
- epub.put_next_entry(@package.path)
153
- epub << opf_xml
154
-
155
- @package.manifest.item_list.each {
156
- |k, item|
157
- epub.put_next_entry(@package.contents_prefix + item.href)
158
- epub << item.content
159
- }
182
+ write_to_epub_container(epub)
160
183
  }
161
184
  end
162
185
 
data/lib/gepub/builder.rb CHANGED
@@ -73,7 +73,7 @@ module GEPUB
73
73
  @last_defined_item = vals.map {
74
74
  |v|
75
75
  name = v
76
- role = ''
76
+ role = 'aut'
77
77
  name,role = v[0], v[1] if Array === name
78
78
  MetaItem.new(@book.add_creator(name, nil, role))
79
79
  }
@@ -121,7 +121,7 @@ module GEPUB
121
121
  end
122
122
 
123
123
  def generate_epub_stream
124
- # TODO should implement
124
+ @book.generate_epub_stream
125
125
  end
126
126
  end
127
127
  end
@@ -153,7 +153,7 @@ module GEPUB
153
153
  meta
154
154
  end
155
155
 
156
- def add_person(name, content, id = nil, role = 'aut')
156
+ def add_person(name, content, id = nil, role = nil)
157
157
  meta = add_metadata(name, content, id).refine('role', role)
158
158
  yield meta if block_given?
159
159
  meta
data/lib/gepub/spine.rb CHANGED
@@ -106,7 +106,13 @@ module GEPUB
106
106
  @item_refs.delete itemref
107
107
  @id_pool[itemref.id] = nil
108
108
  end
109
-
109
+
110
+ def remove_with_idlist(ids)
111
+ @item_refs = @item_refs.select {
112
+ |ref|
113
+ !ids.member? ref.idref
114
+ }
115
+ end
110
116
 
111
117
  end
112
118
  end
data/lib/gepub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GEPUB
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.3.1"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -291,12 +291,11 @@ describe GEPUB::Builder do
291
291
  end
292
292
 
293
293
  it 'should handle fallback chain' do
294
- # in this test, do not supply
295
294
  workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
296
295
  builder = GEPUB::Builder.new {
297
296
  resources(:workdir => workdir) {
298
297
  fallback_group {
299
- file 'chap3_docbook.xhtml' => nil
298
+ file 'chap3_docbook.xml' => nil
300
299
  media_type('application/docbook+xml')
301
300
  file 'chap3.xml' => nil
302
301
  media_type("application/z3986-auth+xml")
@@ -305,7 +304,7 @@ describe GEPUB::Builder do
305
304
  }
306
305
  }
307
306
  builder.instance_eval {
308
- fallbackid = @book.item_by_href('chap3_docbook.xhtml').fallback
307
+ fallbackid = @book.item_by_href('chap3_docbook.xml').fallback
309
308
  @book.items[fallbackid].href.should == 'chap3.xml'
310
309
 
311
310
  fallbackid = @book.items[fallbackid].fallback
@@ -318,11 +317,11 @@ describe GEPUB::Builder do
318
317
  workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
319
318
  builder = GEPUB::Builder.new {
320
319
  resources(:workdir => workdir) {
321
- fallback_chain_files 'chap3_docbook.xhtml' => nil, 'chap3.xml' => nil, 'chap3.xhtml' => nil
320
+ fallback_chain_files({'chap3_docbook.xml' => nil}, {'chap3.xml' => nil}, {'chap3.xhtml' => nil})
322
321
  }
323
322
  }
324
323
  builder.instance_eval {
325
- fallbackid = @book.item_by_href('chap3_docbook.xhtml').fallback
324
+ fallbackid = @book.item_by_href('chap3_docbook.xml').fallback
326
325
  @book.items[fallbackid].href.should == 'chap3.xml'
327
326
 
328
327
  fallbackid = @book.items[fallbackid].fallback
@@ -331,18 +330,17 @@ describe GEPUB::Builder do
331
330
  end
332
331
 
333
332
  it 'should handle fallback chain with fallback_chain_files in with_media_type' do
334
- # in this test, do not supply
335
333
  workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
336
334
  builder = GEPUB::Builder.new {
337
335
  resources(:workdir => workdir) {
338
336
  with_media_type('application/docbook+xml', 'application/z3986-auth+xml', 'application/xhtml+xml') {
339
- fallback_chain_files 'chap3_docbook.xhtml' => nil, 'chap3.xml' => nil, 'chap3.xhtml' => nil
337
+ fallback_chain_files({'chap3_docbook.xml' => nil}, {'chap3.xml' => nil}, {'chap3.xhtml' => nil})
340
338
  }
341
339
  }
342
340
  }
343
341
  builder.instance_eval {
344
- @book.item_by_href('chap3_docbook.xhtml').media_type.should == 'application/docbook+xml'
345
- fallbackid = @book.item_by_href('chap3_docbook.xhtml').fallback
342
+ @book.item_by_href('chap3_docbook.xml').media_type.should == 'application/docbook+xml'
343
+ fallbackid = @book.item_by_href('chap3_docbook.xml').fallback
346
344
  @book.items[fallbackid].href.should == 'chap3.xml'
347
345
  @book.items[fallbackid].media_type.should == 'application/z3986-auth+xml'
348
346
 
@@ -352,5 +350,35 @@ describe GEPUB::Builder do
352
350
  }
353
351
  end
354
352
 
353
+ it 'should handle fallback chain in spine' do
354
+ workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
355
+ builder = GEPUB::Builder.new {
356
+ unique_identifier 'uid'
357
+
358
+ resources(:workdir => workdir) {
359
+ ordered {
360
+ fallback_group {
361
+ file 'chap3_docbook.xml' => nil
362
+ media_type('application/docbook+xml')
363
+ file 'chap3.xml' => nil
364
+ media_type("application/z3986-auth+xml")
365
+ file 'chap3.xhtml' => nil
366
+ }
367
+ }
368
+ }
369
+ }
370
+ builder.instance_eval {
371
+ @book.cleanup
372
+ fallbackid = @book.item_by_href('chap3_docbook.xml').fallback
373
+ @book.items[fallbackid].href.should == 'chap3.xml'
374
+ fallbackid = @book.items[fallbackid].fallback
375
+ @book.items[fallbackid].href.should == 'chap3.xhtml'
376
+
377
+ @book.spine_items.size.should == 1
378
+ @book.spine_items[0].href == 'chap3_docbook.xhtml'
379
+
380
+ }
381
+ end
382
+
355
383
  end
356
384
  end
data/spec/example_spec.rb CHANGED
@@ -7,6 +7,38 @@ describe 'GEPUB usage' do
7
7
  end
8
8
 
9
9
  context 'On generating EPUB' do
10
+ it 'should generate simple EPUB3 with Builder and buffer' do
11
+ workdir = File.join(File.dirname(__FILE__), 'fixtures', 'testdata')
12
+ builder = GEPUB::Builder.new {
13
+ unique_identifier 'http:/example.jp/bookid_in_url', 'BookID', 'URL'
14
+ language 'ja'
15
+ title 'GEPUBサンプル文書'
16
+ file_as 'GEPUB Sample Book'
17
+ alt 'en' => 'GEPUB Sample Book (Japanese)',
18
+ 'el' => 'GEPUB δείγμα (Ιαπωνικά)',
19
+ 'th' => 'GEPUB ตัวอย่าง (ญี่ปุ่น)'
20
+
21
+ subtitle 'これはあくまでサンプルです'
22
+ alt 'en' => 'This book is just a sample'
23
+ creator '小嶋智'
24
+ contributors 'Denshobu', 'Asagaya Densho', 'Shonan Densho Teidan', 'eMagazine Torutaru'
25
+ resources(:workdir => workdir) {
26
+ cover_image 'img/image1.jpg' => 'image1.jpg'
27
+ ordered {
28
+ file 'text/chap1.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>')
29
+ heading 'Chapter 1'
30
+ file 'text/chap1-1.xhtml' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>the second page</p></body></html>')
31
+ file 'text/chap2.html' => StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c3</title></head><body><p>the third page</p></body></html>')
32
+ heading 'Chapter 2'
33
+ }
34
+ }
35
+ }
36
+ epubname = File.join(File.dirname(__FILE__), 'example_test_with_builder_buffer.epub')
37
+ File.open(epubname, 'wb') { |io| io.write builder.generate_epub_stream.string }
38
+ jar = File.join(File.dirname(__FILE__), 'fixtures/epubcheck-3.0b4/epubcheck-3.0b4.jar')
39
+ system 'java' '-jar', jar, epubname
40
+ end
41
+
10
42
  it 'should generate simple EPUB3 with Builder' do
11
43
  workdir = File.join(File.dirname(__FILE__), 'fixtures', 'testdata')
12
44
  builder = GEPUB::Builder.new {
data/spec/gepub_spec.rb CHANGED
@@ -158,6 +158,16 @@ EOF
158
158
  system 'java', '-jar', jar, epubname
159
159
  end
160
160
 
161
+ it "should generate correct epub with buffer" do
162
+ epubname = File.join(File.dirname(__FILE__), 'testepub_buf.epub')
163
+ File.open(epubname, 'wb') {
164
+ |io|
165
+ io.write @book.generate_epub_stream.string
166
+ }
167
+ jar = File.join(File.dirname(__FILE__), 'fixtures/epubcheck-3.0b4/epubcheck-3.0b4.jar')
168
+ system 'java', '-jar', jar, epubname
169
+ end
170
+
161
171
  it "should generate correct epub2.0" do
162
172
  epubname = File.join(File.dirname(__FILE__), 'testepub2.epub')
163
173
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gepub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-24 00:00:00.000000000 Z
12
+ date: 2012-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70335408467760 !ruby/object:Gem::Requirement
16
+ requirement: &70317965172840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70335408467760
24
+ version_requirements: *70317965172840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70335408467260 !ruby/object:Gem::Requirement
27
+ requirement: &70317964165820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70335408467260
35
+ version_requirements: *70317964165820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rubyzip
38
- requirement: &70335408466800 !ruby/object:Gem::Requirement
38
+ requirement: &70317964163220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.9.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70335408466800
46
+ version_requirements: *70317964163220
47
47
  description: gepub is a generic EPUB parser/generator. Generates and parse EPUB2 and
48
48
  EPUB3
49
49
  email:
@@ -53,7 +53,6 @@ executables:
53
53
  extensions: []
54
54
  extra_rdoc_files: []
55
55
  files:
56
- - .document
57
56
  - .gitignore
58
57
  - .travis.yml
59
58
  - Gemfile
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
-