gepub 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ testepub.epub
23
+
24
+ ## BUNDLER
25
+ Gemfile.lock
26
+ vendor/**
27
+ .bundle/**
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
- source :rubygems
1
+ source "http://rubygems.org"
2
2
 
3
- gem 'bundler', '>= 1.0.7', :require => 'bundle', :group => [:test, :development]
4
- gem 'rspec', '>= 2', :group => [:test, :development]
5
- gem 'epubcheck', '>= 0.1.0', :group => [:test, :development]
6
- gem 'jeweler', '>= 1.5.1', :group => :development
7
- gem 'libxml-ruby', '>= 1.1.4'
8
- gem 'rubyzip', '>= 0.9.4'
3
+ # Specify your gem's dependencies in gepub.gemspec
4
+ gemspec
data/README.rdoc CHANGED
@@ -16,8 +16,7 @@ a good-enough EPUB generator library.
16
16
  * ncx: can't nest navPoint elements
17
17
  * ...and many other restrictions
18
18
 
19
- * note: GEPUB::Generator is now obsolete. use GEPUB::Book.
20
- * GEPUB::Book does not create directory. GEPUB::Book accepts IO object, not File.
19
+ * GEPUB::Generator has been removed. Use GEPUB::Book instead.
21
20
 
22
21
  == SYNOPSIS:
23
22
 
@@ -66,11 +65,6 @@ a good-enough EPUB generator library.
66
65
 
67
66
  epub.generate_epub(epubname)
68
67
 
69
- == REQUIREMENTS:
70
-
71
- * libxml-ruby
72
- * zipruby
73
-
74
68
  == INSTALL:
75
69
 
76
70
  * gem install gepub
data/Rakefile CHANGED
@@ -1,42 +1 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "gepub"
8
- gem.summary = %Q{a good-enough EPUB generator.}
9
- gem.description = %Q{an easy-to-use (and easy-to-implement) EPUB generator.}
10
- gem.email = "skoji@skoji.jp"
11
- gem.homepage = "http://github.com/skoji/gepub"
12
- gem.authors = ["KOJIMA Satoshi"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
- end
19
-
20
- require 'rspec/core/rake_task'
21
- RSpec::Core::RakeTask.new(:spec) do |spec|
22
- spec.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
23
- spec.pattern = 'spec/**/*_spec.rb'
24
- end
25
-
26
- RSpec::Core::RakeTask.new(:rcov) do |spec|
27
- spec.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
28
- spec.pattern = 'spec/**/*_spec.rb'
29
- spec.rcov = true
30
- end
31
-
32
- task :default => :spec
33
-
34
- require 'rake/rdoctask'
35
- Rake::RDocTask.new do |rdoc|
36
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
-
38
- rdoc.rdoc_dir = 'rdoc'
39
- rdoc.title = "gepub #{version}"
40
- rdoc.rdoc_files.include('README*')
41
- rdoc.rdoc_files.include('lib/**/*.rb')
42
- end
1
+ require "bundler/gem_tasks"
data/bin/gepuber CHANGED
File without changes
data/gepub.gemspec CHANGED
@@ -1,77 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gepub/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{gepub}
8
- s.version = "0.4.5"
6
+ s.name = "gepub"
7
+ s.version = GEPUB::VERSION
8
+ s.authors = ["KOJIMA Satoshi"]
9
+ s.email = ["skoji@mac.com"]
10
+ s.homepage = %q{http://github.com/skoji/gepub}
11
+ s.summary = %q{a good-enough EPUB generator.}
12
+ s.description = %q{an easy-to-use EPUB generator.}
9
13
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["KOJIMA Satoshi"]
12
- s.date = %q{2011-06-13}
13
- s.description = %q{an easy-to-use (and easy-to-implement) EPUB generator.}
14
- s.email = %q{skoji@skoji.jp}
15
- s.executables = ["gepuber"]
16
- s.extra_rdoc_files = [
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "bin/gepuber",
26
- "examples/example.rb",
27
- "gepub.gemspec",
28
- "lib/gepub.rb",
29
- "lib/gepub/book.rb",
30
- "lib/gepub/generator.rb",
31
- "lib/gepub/gepuber.rb",
32
- "lib/gepub/item.rb",
33
- "spec/fixtures/testdata/0.html",
34
- "spec/fixtures/testdata/1.html",
35
- "spec/gepub_spec.rb",
36
- "spec/gepuber_spec.rb",
37
- "spec/spec_helper.rb"
38
- ]
39
- s.homepage = %q{http://github.com/skoji/gepub}
40
- s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.7.2}
42
- s.summary = %q{a good-enough EPUB generator.}
43
- s.test_files = [
44
- "examples/example.rb",
45
- "spec/gepub_spec.rb",
46
- "spec/gepuber_spec.rb",
47
- "spec/spec_helper.rb"
48
- ]
14
+ s.rubyforge_project = "gepub"
49
15
 
50
- if s.respond_to? :specification_version then
51
- s.specification_version = 3
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
52
20
 
53
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<libxml-ruby>, [">= 1.1.4"])
55
- s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.4"])
56
- s.add_development_dependency(%q<bundler>, [">= 1.0.7"])
57
- s.add_development_dependency(%q<rspec>, [">= 2"])
58
- s.add_development_dependency(%q<epubcheck>, [">= 0.1.0"])
59
- s.add_development_dependency(%q<jeweler>, [">= 1.5.1"])
60
- else
61
- s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
62
- s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
63
- s.add_dependency(%q<bundler>, [">= 1.0.7"])
64
- s.add_dependency(%q<rspec>, [">= 2"])
65
- s.add_dependency(%q<epubcheck>, [">= 0.1.0"])
66
- s.add_dependency(%q<jeweler>, [">= 1.5.1"])
67
- end
68
- else
69
- s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
70
- s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
71
- s.add_dependency(%q<bundler>, [">= 1.0.7"])
72
- s.add_dependency(%q<rspec>, [">= 2"])
73
- s.add_dependency(%q<epubcheck>, [">= 0.1.0"])
74
- s.add_dependency(%q<jeweler>, [">= 1.5.1"])
75
- end
21
+ s.add_development_dependency "rspec", ">= 2"
22
+ s.add_development_dependency "epubcheck", ">= 0.1.0"
23
+ s.add_runtime_dependency "nokogiri", ">= 1.5.0"
24
+ s.add_runtime_dependency "rubyzip", ">= 0.9.4"
76
25
  end
77
-
data/lib/gepub/book.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'rubygems'
3
- require 'xml/libxml'
3
+ require 'nokogiri'
4
4
  require 'zip/zip'
5
5
  require 'fileutils'
6
6
 
7
7
 
8
8
  module GEPUB
9
9
  class Book
10
- attr_accessor :spine, :locale
10
+ attr_accessor :spine, :locale, :epub_version, :epub_backword_compat
11
11
 
12
12
  def self.def_meta(name, key = nil)
13
13
  key ||= name
@@ -32,6 +32,8 @@ module GEPUB
32
32
  @contents_prefix = @contents_prefix + "/" if contents_prefix != ""
33
33
  @itemcount = 0
34
34
  @locale = 'en'
35
+ @epub_version = 2.1
36
+ @epub_backword_compat = false
35
37
  end
36
38
 
37
39
  def_meta :title
@@ -125,104 +127,101 @@ EOF
125
127
  end
126
128
 
127
129
  def opf_xml
128
- result = XML::Document.new
129
- result.root = XML::Node.new('package')
130
- package = result.root
131
- XML::Namespace.new(package, nil, 'http://www.idpf.org/2007/opf')
130
+ opf = Nokogiri::XML::Document.new
131
+ opf.root = package = Nokogiri::XML::Node.new('package', opf)
132
+ package.add_namespace(nil, 'http://www.idpf.org/2007/opf')
132
133
  package['version'] = '2.0'
133
134
  package['unique-identifier'] = 'BookID'
134
-
135
-
136
- package << metadataelem = XML::Node.new('metadata')
137
- XML::Namespace.new(metadataelem, 'opf', 'http://www.idpf.org/2007/opf')
138
- XML::Namespace.new(metadataelem, 'dc', "http://purl.org/dc/elements/1.1/")
139
-
140
- metadataelem << XML::Node.new('dc:language', @locale)
141
-
142
- @metadata.each { | k, v |
135
+ package << metadataelem = Nokogiri::XML::Node.new('metadata', opf)
136
+ metadataelem.add_namespace('opf', 'http://www.idpf.org/2007/opf')
137
+ metadataelem.add_namespace('dc', "http://purl.org/dc/elements/1.1/")
138
+ metadataelem << lang = Nokogiri::XML::Node.new('dc:language', opf)
139
+ lang.content = @locale
140
+ @metadata.each { |k,v|
143
141
  if (k == :cover)
144
- metadataelem << node = XML::Node.new("meta")
142
+ metadataelem << node = Nokogiri::XML::Node.new("meta", opf)
145
143
  node['name'] = 'cover'
146
144
  node['content'] = v
147
145
  elsif (k == :identifier)
148
146
  v.each {
149
147
  |id|
150
- metadataelem << node = XML::Node.new("dc:#{k}",id[:identifier])
148
+ metadataelem << node = Nokogiri::XML::Node.new("dc:#{k}", opf)
149
+ node.content = id[:identifier]
151
150
  if (id[:main_id])
152
151
  node['id'] = 'BookID'
153
152
  end
154
153
  node['opf:scheme'] = id[:scheme]
155
154
  }
156
155
  elsif (k == :gepub_version)
157
- metadataelem << node = XML::Node.new("meta")
156
+ metadataelem << node = Nokogiri::XML::Node.new("meta", opf)
158
157
  node['name'] = 'gepub version'
159
158
  node['content'] = v
160
159
  else
161
- metadataelem << node = XML::Node.new("dc:#{k}",v)
160
+ metadataelem << node = Nokogiri::XML::Node.new("dc:#{k}",opf)
161
+ node.content = v
162
162
  end
163
163
  }
164
164
 
165
- package << manifestelem = XML::Node.new('manifest')
165
+ package << manifestelem = Nokogiri::XML::Node.new('manifest', opf)
166
166
  @manifest.each {
167
167
  |item|
168
- manifestelem << node = XML::Node.new("item")
168
+ manifestelem << node = Nokogiri::XML::Node.new("item", opf)
169
169
  node['id'] = "#{item.itemid}"
170
170
  node['href'] = "#{item.href}"
171
171
  node['media-type'] = "#{item.mediatype}"
172
172
  }
173
-
174
- package << spineelem = XML::Node.new('spine')
173
+
174
+ package << spineelem = Nokogiri::XML::Node.new('spine', opf)
175
175
  spineelem['toc'] = 'ncx'
176
176
 
177
177
  @spine.each {
178
178
  |v|
179
- spineelem << node = XML::Node.new('itemref')
179
+ spineelem << node = Nokogiri::XML::Node.new('itemref', opf)
180
180
  node['idref'] = "#{v.itemid}"
181
181
  }
182
-
183
- result.to_s
184
-
182
+ opf.to_s
185
183
  end
184
+
186
185
 
187
186
  def ncx_xml
188
- result = XML::Document.new
189
- result.root = XML::Node.new('ncx')
190
- root = result.root
191
- XML::Namespace.new(root, nil, "http://www.daisy.org/z3986/2005/ncx/")
187
+ ncx = Nokogiri::XML::Document.new
188
+ ncx.root = root = Nokogiri::XML::Node.new('ncx', ncx)
189
+ root.add_namespace(nil, "http://www.daisy.org/z3986/2005/ncx/")
192
190
  root['version'] = "2005-1"
193
- root << head = XML::Node.new('head')
194
- head << uid = XML::Node.new('meta')
191
+ root << head = Nokogiri::XML::Node.new('head', ncx)
192
+ head << uid = Nokogiri::XML::Node.new('meta', ncx)
195
193
  uid['name'] = 'dtb:uid'
196
194
  uid['content'] = "#{@main_identifier}"
197
195
 
198
- head << depth = XML::Node.new('meta')
196
+ head << depth = Nokogiri::XML::Node.new('meta', ncx)
199
197
  depth['name'] = 'dtb:depth'
200
198
  depth['content'] = '1'
201
199
 
202
- head << totalPageCount = XML::Node.new('meta')
200
+ head << totalPageCount = Nokogiri::XML::Node.new('meta', ncx)
203
201
  totalPageCount['name'] = 'dtb:totalPageCount'
204
202
  totalPageCount['content'] = '0'
205
203
 
206
- head << maxPageNumber = XML::Node.new('meta')
204
+ head << maxPageNumber = Nokogiri::XML::Node.new('meta', ncx)
207
205
  maxPageNumber['name'] = 'dtb:maxPageNumber'
208
206
  maxPageNumber['content'] = '0'
209
207
 
208
+ root << docTitle = Nokogiri::XML::Node.new('docTitle', ncx)
209
+ docTitle << docTitleText = Nokogiri::XML::Node.new('text', ncx)
210
+ docTitleText.content = "#{@metadata[:title]}"
210
211
 
211
- root << docTitle = XML::Node.new('docTitle')
212
- docTitle << XML::Node.new('text', "#{@metadata[:title]}")
213
-
214
- root << nav_map = XML::Node.new('navMap')
212
+ root << nav_map = Nokogiri::XML::Node.new('navMap', ncx)
215
213
  count = 1
216
214
  @toc.each {
217
215
  |x|
218
- nav_point = XML::Node.new('navPoint')
216
+ nav_point = Nokogiri::XML::Node.new('navPoint', ncx)
219
217
  nav_point['id'] = "#{x[:item].itemid}"
220
218
  nav_point['playOrder'] = "#{count}"
221
219
 
222
- nav_label = XML::Node.new('navLabel')
223
- nav_label << XML::Node.new('text', "#{x[:text]}")
220
+ nav_label = Nokogiri::XML::Node.new('navLabel', ncx)
221
+ nav_label << navtxt = Nokogiri::XML::Node.new('text', ncx)
222
+ navtxt.content = "#{x[:text]}"
224
223
 
225
- nav_content = XML::Node.new('content')
224
+ nav_content = Nokogiri::XML::Node.new('content', ncx)
226
225
  if x[:id].nil?
227
226
  nav_content['src'] = "#{x[:item].href}"
228
227
  else
@@ -230,12 +229,11 @@ EOF
230
229
  end
231
230
 
232
231
  count = count + 1
233
-
234
232
  nav_map << nav_point
235
233
  nav_point << nav_label
236
234
  nav_point << nav_content
237
235
  }
238
- result.to_s
236
+ ncx.to_s
239
237
  end
240
238
  end
241
239
  end
data/lib/gepub/gepuber.rb CHANGED
@@ -27,7 +27,7 @@ module GEPUB
27
27
  |k,v|
28
28
  self.send "#{k}=", v
29
29
  }
30
- @texts ||= ['[0-9]*.html']
30
+ @texts ||= ['[0-9]*.{xhtml,html}']
31
31
  @resources ||= ['*.css', 'img/*']
32
32
  @coverimg ||= 'cover.jpg'
33
33
  @table_of_contents ||= {}
data/lib/gepub/item.rb CHANGED
@@ -20,6 +20,8 @@ module GEPUB
20
20
  'application/xhtml+xml'
21
21
  when /.css/i
22
22
  'text/css'
23
+ when /.js/i
24
+ 'text/javascript'
23
25
  when /.(jpg|jpeg)/i
24
26
  'image/jpeg'
25
27
  when /.png/i
@@ -0,0 +1,3 @@
1
+ module GEPUB
2
+ VERSION = "0.5.0"
3
+ end
data/lib/gepub.rb CHANGED
@@ -1,5 +1,6 @@
1
+ require 'gepub/version'
1
2
  require 'gepub/item'
2
3
  require 'gepub/book'
3
4
  require 'gepub/gepuber'
4
- require 'gepub/generator'
5
+
5
6
 
data/spec/gepub_spec.rb CHANGED
@@ -1,9 +1,6 @@
1
- # need to install 'epubcheck'.
2
-
3
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
4
2
  require 'rubygems'
5
- require 'xml/libxml'
6
-
3
+ require 'nokogiri'
7
4
 
8
5
  describe GEPUB::Item do
9
6
  it "should return atttributes" do
@@ -28,133 +25,119 @@ describe GEPUB::Item do
28
25
  item.mediatype.should == 'image/jpeg'
29
26
  end
30
27
 
28
+ it "should handle css" do
29
+ item = GEPUB::Item.new('id', 'img/foo.css')
30
+ item.mediatype.should == 'text/css'
31
+ end
32
+
33
+ it "should handle javascript" do
34
+ item = GEPUB::Item.new('id', 'js/jQuery.js')
35
+ item.mediatype.should == 'text/javascript'
36
+ end
37
+
31
38
  end
32
39
 
33
40
  describe GEPUB::Book do
34
41
  before do
35
- @generator = GEPUB::Book.new('thetitle')
36
- @generator.author = "theauthor"
37
- @generator.contributor = "contributors contributors!"
38
- @generator.publisher = "thepublisher"
39
- @generator.date = "2010-05-05"
40
- @generator.identifier = "http://example.jp/foobar/"
41
- @generator.locale = 'ja'
42
- item1 = @generator.add_ref_to_item('text/foobar.html','c1')
42
+ @book = GEPUB::Book.new('thetitle')
43
+ @book.author = "theauthor"
44
+ @book.contributor = "contributors contributors!"
45
+ @book.publisher = "thepublisher"
46
+ @book.date = "2010-05-05"
47
+ @book.identifier = "http://example.jp/foobar/"
48
+ @book.locale = 'ja'
49
+ item1 = @book.add_ref_to_item('text/foobar.html','c1')
43
50
  item1.add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>'))
44
- @generator.spine.push(item1)
51
+ @book.spine.push(item1)
45
52
 
46
- item2 = @generator.add_ordered_item('text/barbar.html',
53
+ item2 = @book.add_ordered_item('text/barbar.html',
47
54
  StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>second page, whith is test chapter.</p></body></html>'),
48
55
  'c2')
49
- @generator.add_nav(item2, 'test chapter')
56
+ @book.add_nav(item2, 'test chapter')
50
57
  end
51
58
 
52
59
  it "should have titile" do
53
- @generator.title.should == 'thetitle'
60
+ @book.title.should == 'thetitle'
54
61
  end
55
62
 
56
63
  it "should generate correct ncx" do
57
- ncx = LibXML::XML::Parser.string(@generator.ncx_xml).parse
58
- ncx.root.name.should == 'ncx'
59
- ncx.root.attributes['version'].should == '2005-1'
60
- ncx.root.namespaces.namespace.href.should == 'http://www.daisy.org/z3986/2005/ncx/'
64
+ ncx = Nokogiri::XML.parse(@book.ncx_xml).root
65
+ ncx.name.should == 'ncx'
66
+ ncx.attributes['version'].value.should == '2005-1'
67
+ ncx.namespaces['xmlns'] == 'http://www.daisy.org/z3986/2005/ncx/'
61
68
  end
62
69
 
63
70
  it "should have correct head in ncx" do
64
- ncx = LibXML::XML::Parser.string(@generator.ncx_xml).parse
65
- ncx.root.namespaces.default_prefix='a'
66
-
67
- ncx.find_first('a:head').should_not be_nil
68
-
69
- ncx.find_first("a:head/a:meta[@name='dtb:uid']")['content'].should == "http://example.jp/foobar/"
70
- ncx.find_first("a:head/a:meta[@name='dtb:depth']").should_not be_nil
71
- ncx.find_first("a:head/a:meta[@name='dtb:totalPageCount']").should_not be_nil
72
- ncx.find_first("a:head/a:meta[@name='dtb:maxPageNumber']").should_not be_nil
71
+ head = Nokogiri::XML.parse(@book.ncx_xml).at_xpath('/xmlns:ncx/xmlns:head')
72
+ head.should_not be_nil
73
+ head.at_xpath("xmlns:meta[@name='dtb:uid']")['content'].should == "http://example.jp/foobar/"
74
+ head.xpath("xmlns:meta[@name='dtb:depth']").size.should > 0
75
+ head.xpath("xmlns:meta[@name='dtb:totalPageCount']").size.should > 0
76
+ head.xpath("xmlns:meta[@name='dtb:maxPageNumber']").size.should > 0
73
77
  end
74
78
 
75
79
  it "should have correct ncx doctitle" do
76
- ncx = LibXML::XML::Parser.string(@generator.ncx_xml).parse
77
- ncx.root.namespaces.default_prefix='a'
80
+ doctitle = Nokogiri::XML.parse(@book.ncx_xml).root
78
81
 
79
- ncx.root.find_first('a:docTitle').should_not be_nil
80
- ncx.root.find_first('a:docTitle/a:text').content.should == 'thetitle'
82
+ doctitle.xpath('xmlns:docTitle').size.should > 0
83
+ doctitle.at_xpath('xmlns:docTitle/xmlns:text').text.should == 'thetitle'
81
84
  end
82
85
 
83
86
  it "should correct ncx navmap" do
84
- ncx = LibXML::XML::Parser.string(@generator.ncx_xml).parse
85
- ncx.root.namespaces.default_prefix='a'
87
+ ncx = Nokogiri::XML::parse(@book.ncx_xml).root
86
88
 
87
- ncx.root.find_first('a:navMap').should_not be_nil
88
- nav_point = ncx.root.find_first('a:navMap/a:navPoint')
89
+ ncx.xpath('xmlns:navMap').size.should > 0
90
+ nav_point = ncx.at_xpath('xmlns:navMap/xmlns:navPoint')
89
91
  nav_point['id'].should == 'c2'
90
92
  nav_point['playOrder'].should == '1'
91
93
 
92
- nav_point.find_first('a:navLabel/a:text').content.should == 'test chapter'
93
- nav_point.find_first('a:content')['src'] == 'foobar2.html'
94
+ nav_point.at_xpath('xmlns:navLabel/xmlns:text').content.should == 'test chapter'
95
+ nav_point.at_xpath('xmlns:content')['src'] == 'foobar2.html'
94
96
 
95
97
  end
96
98
 
97
99
  it "should create correct opf" do
98
- opf = LibXML::XML::Parser.string(@generator.opf_xml).parse
99
- opf.root.namespaces.default_prefix='a'
100
-
101
- opf.root.name.should == 'package'
102
- opf.root.namespaces.namespace.href.should == 'http://www.idpf.org/2007/opf'
103
- opf.root['version'] == '2.0'
104
- opf.root['unique-identifier'] == 'http://example.jp/foobar/'
100
+ opf = Nokogiri::XML.parse(@book.opf_xml).root
101
+ opf.name.should == 'package'
102
+ opf.namespaces['xmlns'] == 'http://www.idpf.org/2007/opf'
103
+ opf['version'] == '2.0'
104
+ opf['unique-identifier'] == 'http://example.jp/foobar/'
105
105
  end
106
-
107
106
 
108
107
  it "should have correct metadata in opf" do
109
- opf = LibXML::XML::Parser.string(@generator.opf_xml).parse
110
- opf.root.namespaces.default_prefix='a'
111
-
112
- metadata = opf.find_first('a:metadata')
113
- metadata.find_first('dc:language').content.should == 'ja'
114
- # TODO checking metadatas...
108
+ opf = Nokogiri::XML.parse(@book.opf_xml).root
109
+ metadata = opf.xpath('xmlns:metadata').first
110
+ metadata.at_xpath('dc:language', metadata.namespaces).content.should == 'ja'
111
+ #TODO: check metadata
115
112
  end
116
113
 
117
114
  it "should have correct manifest and spine in opf" do
118
- opf = LibXML::XML::Parser.string(@generator.opf_xml).parse
119
- opf.root.namespaces.default_prefix='a'
115
+ opf = Nokogiri::XML.parse(@book.opf_xml).root
120
116
 
121
- manifest = opf.find_first('a:manifest')
122
- manifest.find_first('a:item')['id'].should == 'c1'
123
- manifest.find_first('a:item')['href'].should == 'text/foobar.html'
124
- manifest.find_first('a:item')['media-type'].should == 'application/xhtml+xml'
117
+ manifest = opf.at_xpath('xmlns:manifest')
118
+ manifest.at_xpath('xmlns:item')['id'].should == 'c1'
119
+ manifest.at_xpath('xmlns:item')['href'].should == 'text/foobar.html'
120
+ manifest.at_xpath('xmlns:item')['media-type'].should == 'application/xhtml+xml'
125
121
 
126
- spine = opf.find_first('a:spine')
122
+ spine = opf.at_xpath('xmlns:spine')
127
123
  spine['toc'].should == 'ncx'
128
- spine.find_first('a:itemref')['idref'].should == 'c1'
129
- end
130
-
131
- it "should have correct metadata in opf" do
132
- opf = LibXML::XML::Parser.string(@generator.opf_xml).parse
133
- opf.root.namespaces.default_prefix='a'
134
-
135
- metadata = opf.find_first('a:metadata')
136
- metadata.find_first('dc:language').content.should == 'ja'
137
- # TODO checking metadatas...
124
+ spine.at_xpath('xmlns:itemref')['idref'].should == 'c1'
138
125
  end
139
126
 
140
127
  it "should have correct cover image id" do
141
- item = @generator.add_ref_to_item("img/img.jpg")
142
- @generator.specify_cover_image(item)
128
+ item = @book.add_ref_to_item("img/img.jpg")
129
+ @book.specify_cover_image(item)
143
130
 
144
- opf = LibXML::XML::Parser.string(@generator.opf_xml).parse
145
- opf.root.namespaces.default_prefix='a'
131
+ opf = Nokogiri::XML.parse(@book.opf_xml).root
146
132
 
147
- metadata = opf.find_first('a:metadata')
148
- metas = metadata.find('a:meta').select {
149
- |m| m['name'] == 'cover'
150
- }
151
- metas.length.should == 1
152
- metas[0]['content'].should == item.itemid
133
+ metadata = opf.at_xpath('xmlns:metadata')
134
+ meta = metadata.at_xpath("xmlns:meta[@name='cover']")
135
+ meta['content'].should == item.itemid
153
136
  end
154
137
 
155
138
  it "should generate correct epub" do
156
139
  epubname = File.join(File.dirname(__FILE__), 'testepub.epub')
157
- @generator.generate_epub(epubname)
140
+ @book.generate_epub(epubname)
158
141
  %x( epubcheck #{epubname} )
159
142
  end
160
143
 
data/spec/gepuber_spec.rb CHANGED
@@ -1,15 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
- # need to install 'epubcheck'.
3
2
 
4
3
  require File.dirname(__FILE__) + '/spec_helper.rb'
5
4
  require 'rubygems'
6
- require 'xml/libxml'
7
-
8
5
 
9
6
  describe GEPUB::Gepuber do
10
7
  it "should be initialized with empty conf" do
11
8
  gepuber = GEPUB::Gepuber.new({})
12
- gepuber.texts.should == ['[0-9]*.html']
9
+ gepuber.texts.should == ['[0-9]*.{xhtml,html}']
13
10
  gepuber.resources.should == ['*.css', 'img/*']
14
11
  gepuber.title.should == ""
15
12
  gepuber.table_of_contents.should == {}
@@ -18,22 +15,22 @@ describe GEPUB::Gepuber do
18
15
  it "should read config hash" do
19
16
  conf =
20
17
  {
21
- locale: 'ja',
22
- title: 'theTitle',
23
- author: 'theAuthor',
24
- publisher: 'thePublisher',
25
- date: '2011-03-11',
26
- identifier: 'http://skoji.jp/gepuber/2011-03-11.0.0',
27
- epubname: 'gepub_00',
28
- table_of_contents: {
18
+ :locale => 'ja',
19
+ :title => 'theTitle',
20
+ :author => 'theAuthor',
21
+ :publisher => 'thePublisher',
22
+ :date => '2011-03-11',
23
+ :identifier => 'http://skoji.jp/gepuber/2011-03-11.0.0',
24
+ :epubname => 'gepub_00',
25
+ :table_of_contents => {
29
26
  '1_.html' => '1st toc',
30
27
  '3_.html' => '3rd toc',
31
28
  '3_.html#a1' => '3rd toc 2',
32
29
  '9_.html' => 'last toc'
33
30
  },
34
- coverimg: 'cover.gif',
35
- texts: [ '*.html' ],
36
- resources: ['*.css','*.gif']
31
+ :coverimg => 'cover.gif',
32
+ :texts => [ '*.html' ],
33
+ :resources => ['*.css','*.gif']
37
34
  }
38
35
 
39
36
  gepuber = GEPUB::Gepuber.new(conf )
metadata CHANGED
@@ -1,105 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gepub
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
4
5
  prerelease:
5
- version: 0.4.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - KOJIMA Satoshi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-13 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: libxml-ruby
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.1.4
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rubyzip
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.9.4
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: bundler
39
- requirement: &id003 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: 1.0.7
45
- type: :development
46
- prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
49
15
  name: rspec
50
- requirement: &id004 !ruby/object:Gem::Requirement
16
+ requirement: &70335555213040 !ruby/object:Gem::Requirement
51
17
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "2"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
56
22
  type: :development
57
23
  prerelease: false
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *70335555213040
25
+ - !ruby/object:Gem::Dependency
60
26
  name: epubcheck
61
- requirement: &id005 !ruby/object:Gem::Requirement
27
+ requirement: &70335555212540 !ruby/object:Gem::Requirement
62
28
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
66
32
  version: 0.1.0
67
33
  type: :development
68
34
  prerelease: false
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: jeweler
72
- requirement: &id006 !ruby/object:Gem::Requirement
35
+ version_requirements: *70335555212540
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ requirement: &70335555212080 !ruby/object:Gem::Requirement
73
39
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: 1.5.1
78
- type: :development
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.0
44
+ type: :runtime
79
45
  prerelease: false
80
- version_requirements: *id006
81
- description: an easy-to-use (and easy-to-implement) EPUB generator.
82
- email: skoji@skoji.jp
83
- executables:
46
+ version_requirements: *70335555212080
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubyzip
49
+ requirement: &70335555211620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.4
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70335555211620
58
+ description: an easy-to-use EPUB generator.
59
+ email:
60
+ - skoji@mac.com
61
+ executables:
84
62
  - gepuber
85
63
  extensions: []
86
-
87
- extra_rdoc_files:
88
- - README.rdoc
89
- files:
64
+ extra_rdoc_files: []
65
+ files:
90
66
  - .document
67
+ - .gitignore
91
68
  - Gemfile
92
69
  - README.rdoc
93
70
  - Rakefile
94
- - VERSION
95
71
  - bin/gepuber
96
72
  - examples/example.rb
97
73
  - gepub.gemspec
98
74
  - lib/gepub.rb
99
75
  - lib/gepub/book.rb
100
- - lib/gepub/generator.rb
101
76
  - lib/gepub/gepuber.rb
102
77
  - lib/gepub/item.rb
78
+ - lib/gepub/version.rb
103
79
  - spec/fixtures/testdata/0.html
104
80
  - spec/fixtures/testdata/1.html
105
81
  - spec/gepub_spec.rb
@@ -107,33 +83,31 @@ files:
107
83
  - spec/spec_helper.rb
108
84
  homepage: http://github.com/skoji/gepub
109
85
  licenses: []
110
-
111
86
  post_install_message:
112
87
  rdoc_options: []
113
-
114
- require_paths:
88
+ require_paths:
115
89
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
90
+ required_ruby_version: !ruby/object:Gem::Requirement
117
91
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- version: "0"
122
- required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
97
  none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
128
102
  requirements: []
129
-
130
- rubyforge_project:
131
- rubygems_version: 1.7.2
103
+ rubyforge_project: gepub
104
+ rubygems_version: 1.8.11
132
105
  signing_key:
133
106
  specification_version: 3
134
107
  summary: a good-enough EPUB generator.
135
- test_files:
136
- - examples/example.rb
108
+ test_files:
109
+ - spec/fixtures/testdata/0.html
110
+ - spec/fixtures/testdata/1.html
137
111
  - spec/gepub_spec.rb
138
112
  - spec/gepuber_spec.rb
139
113
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.5
@@ -1,275 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rubygems'
3
- require 'xml/libxml'
4
- require 'zip/zip'
5
- require 'fileutils'
6
-
7
-
8
- module GEPUB
9
- class Generator
10
-
11
- attr_accessor :spine
12
-
13
- def initialize(title)
14
- warn('GEPUB::Generator is obsolete. use GEPUB::Book instead.')
15
- @metadata = Hash.new
16
- @manifest = Hash.new
17
- @spine = Array.new
18
- @toc = Array.new
19
- @metadata[:title] = title
20
- @manifest['ncx'] = { :href => 'toc.ncx', :mediatype => 'application/x-dtbncx+xml' }
21
- @contents_prefix = "" # may insert "OEBPS/"
22
- @locale = 'en'
23
- end
24
-
25
- def contents_prefix=(prefix)
26
- @contents_prefix = prefix + "/"
27
- end
28
-
29
- def title
30
- @metadata[:title]
31
- end
32
-
33
- def title=(title)
34
- @metadata[:title] = title
35
- end
36
-
37
- def author
38
- @metadata[:creator]
39
- end
40
-
41
- def author=(author)
42
- @metadata[:creator] = author
43
- end
44
-
45
- def contributor
46
- @metadata[:contributor]
47
- end
48
-
49
- def contributor=(contributor)
50
- @metadata[:contributor] = contributor
51
- end
52
-
53
- def publisher
54
- @metadata[:publisher]
55
- end
56
-
57
- def publisher=(publisher)
58
- @metadata[:publisher] = publisher
59
- end
60
-
61
- def date
62
- @metadata[:date]
63
- end
64
-
65
- def date=(date)
66
- @metadata[:date] = date
67
- end
68
-
69
- def identifier
70
- @metadata[:itentifier]
71
- end
72
-
73
- def identifier=(id)
74
- @metadata[:identifier] = id
75
- end
76
-
77
- def locale
78
- @locale
79
- end
80
-
81
- def locale=(locale)
82
- @locale = locale
83
- end
84
-
85
- def addManifest(id, href, mediatype)
86
- @manifest[id] = { :href => href, :mediatype => mediatype }
87
- end
88
-
89
- def addNav(id, text, ref)
90
- @toc.push({ :id => id, :text => text, :ref => ref})
91
- end
92
-
93
- def specifyCoverImage(id)
94
- @metadata[:cover] = id
95
- end
96
-
97
- def create(destdir)
98
- create_mimetype(destdir)
99
- create_container(destdir)
100
- create_toc(destdir)
101
- create_opf(destdir)
102
- end
103
-
104
- def create_epub(destdir, targetdir, epubname = @metadata[:title])
105
- realtarget = File::expand_path(targetdir)
106
-
107
- FileUtils.cd("#{destdir}") do
108
- |dir|
109
- epubname = "#{realtarget}/#{epubname}.epub"
110
- File.delete(epubname) if File.exist?(epubname)
111
-
112
- Zip::ZipOutputStream::open(epubname) {
113
- |epub|
114
- epub.put_next_entry('mimetype', '', '', Zip::ZipEntry::STORED)
115
- epub << 'application/epub+zip'
116
-
117
- Dir["**/*"].each do
118
- |f|
119
- if File.basename(f) != 'mimetype' && !File.directory?(f)
120
- File.open(f,'rb') do
121
- |file|
122
- epub.put_next_entry(f)
123
- epub << file.read
124
- end
125
- end
126
- end
127
- }
128
- end
129
- end
130
-
131
- def mimetype_contents
132
- <<EOF
133
- application/epub+zip
134
- EOF
135
- end
136
- def create_mimetype(destdir)
137
- File.open(destdir + '/mimetype', 'w') {
138
- | file |
139
- file << mimetype_contents
140
- }
141
- end
142
-
143
- def container_xml
144
- <<EOF
145
- <?xml version="1.0" encoding="UTF-8"?>
146
- <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
147
- <rootfiles>
148
- <rootfile full-path="#{@contents_prefix}content.opf" media-type="application/oebps-package+xml"/>
149
- </rootfiles>
150
- </container>
151
- EOF
152
- end
153
-
154
- def create_container(destdir)
155
- infdir = destdir + "/META-INF"
156
- Dir.mkdir(infdir) if !File.exist?(infdir)
157
-
158
- File.open(infdir + "/container.xml", 'w') {
159
- |file|
160
- file << container_xml
161
- }
162
- end
163
-
164
- def opf_xml
165
- result = XML::Document.new
166
- result.root = XML::Node.new('package')
167
- package = result.root
168
- XML::Namespace.new(package, nil, 'http://www.idpf.org/2007/opf')
169
- package['version'] = '2.0'
170
- package['unique-identifier'] = 'BookID'
171
-
172
-
173
- package << metadataelem = XML::Node.new('metadata')
174
- XML::Namespace.new(metadataelem, 'opf', 'http://www.idpf.org/2007/opf')
175
- XML::Namespace.new(metadataelem, 'dc', "http://purl.org/dc/elements/1.1/")
176
-
177
- metadataelem << XML::Node.new('dc:language', @locale)
178
-
179
- @metadata.each { | k, v |
180
- if (k == :cover)
181
- metadataelem << node = XML::Node.new("meta")
182
- node['name'] = 'cover'
183
- node['content'] = v
184
- else
185
- metadataelem << node = XML::Node.new("dc:#{k}",v)
186
- if (k == :identifier)
187
- node['id'] = 'BookID'
188
- node['opf:scheme'] = 'URL'
189
- end
190
- end
191
- }
192
-
193
- package << manifestelem = XML::Node.new('manifest')
194
- @manifest.each {|k,v|
195
- manifestelem << node = XML::Node.new("item")
196
- node['id'] = "#{k}"
197
- node['href'] = "#{v[:href]}"
198
- node['media-type'] = "#{v[:mediatype]}"
199
- }
200
-
201
- package << spineelem = XML::Node.new('spine')
202
- spineelem['toc'] = 'ncx'
203
-
204
- @spine.each {
205
- |v|
206
- spineelem << node = XML::Node.new('itemref')
207
- node['idref'] = "#{v}"
208
- }
209
-
210
- result.to_s
211
-
212
- end
213
-
214
- def create_opf(destdir)
215
- File.open(destdir + "/" + @contents_prefix + "content.opf", 'w') { | file | file << opf_xml }
216
- end
217
-
218
- def ncx_xml
219
- result = XML::Document.new
220
- result.root = XML::Node.new('ncx')
221
- root = result.root
222
- XML::Namespace.new(root, nil, "http://www.daisy.org/z3986/2005/ncx/")
223
- root['version'] = "2005-1"
224
- root << head = XML::Node.new('head')
225
- head << uid = XML::Node.new('meta')
226
- uid['name'] = 'dtb:uid'
227
- uid['content'] = "#{@metadata[:identifier]}"
228
-
229
- head << depth = XML::Node.new('meta')
230
- depth['name'] = 'dtb:depth'
231
- depth['content'] = '1'
232
-
233
- head << totalPageCount = XML::Node.new('meta')
234
- totalPageCount['name'] = 'dtb:totalPageCount'
235
- totalPageCount['content'] = '0'
236
-
237
- head << maxPageNumber = XML::Node.new('meta')
238
- maxPageNumber['name'] = 'dtb:maxPageNumber'
239
- maxPageNumber['content'] = '0'
240
-
241
-
242
- root << docTitle = XML::Node.new('docTitle')
243
- docTitle << XML::Node.new('text', "#{@metadata[:title]}")
244
-
245
- root << nav_map = XML::Node.new('navMap')
246
- count = 1
247
- @toc.each {
248
- |x|
249
- nav_point = XML::Node.new('navPoint')
250
- nav_point['id'] = "#{x[:id]}"
251
- nav_point['playOrder'] = "#{count}"
252
-
253
- nav_label = XML::Node.new('navLabel')
254
- nav_label << XML::Node.new('text', "#{x[:text]}")
255
-
256
- nav_content = XML::Node.new('content')
257
- nav_content['src'] = "#{x[:ref]}"
258
- count = count + 1
259
-
260
- nav_map << nav_point
261
- nav_point << nav_label
262
- nav_point << nav_content
263
- }
264
- result.to_s
265
- end
266
-
267
- def create_toc(destdir)
268
- File.open(destdir + "/" + @contents_prefix + "toc.ncx", 'w') {
269
- |file|
270
- file << ncx_xml
271
- }
272
- end
273
-
274
- end
275
- end