eeepub 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,5 +3,6 @@
3
3
  coverage
4
4
  doc
5
5
  pkg
6
- *.gemspec
7
6
  *.epub
7
+ .rvmrc
8
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in eeepub.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -61,7 +61,6 @@ Install
61
61
  Requirements
62
62
  -------
63
63
 
64
- * ruby 1.8.7
65
64
  * builder
66
65
  * eBook Reader :)
67
66
 
data/Rakefile CHANGED
@@ -1,39 +1,15 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "eeepub"
8
- gem.summary = %Q{ePub generator}
9
- gem.description = %Q{EeePub is a Ruby ePub generator.}
10
- gem.email = "jugyo.org@gmail.com"
11
- gem.homepage = "http://github.com/jugyo/eeepub"
12
- gem.authors = ["jugyo"]
13
- gem.add_dependency "builder"
14
- gem.add_development_dependency "rspec"
15
- gem.add_development_dependency "rr"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.rspec_opts = ['--color']
17
8
  end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
- end
22
-
23
- require 'spec/rake/spectask'
24
- Spec::Rake::SpecTask.new(:spec) do |spec|
25
- spec.libs << 'lib' << 'spec'
26
- spec.spec_files = FileList['spec/**/*_spec.rb']
9
+ rescue LoadError => e
10
+ puts "RSpec not installed"
27
11
  end
28
12
 
29
- Spec::Rake::SpecTask.new(:rcov) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
34
-
35
- task :spec => :check_dependencies
36
-
37
13
  task :default => :spec
38
14
 
39
15
  begin
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "eeepub"
5
+ s.version = "0.7.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["jugyo"]
8
+ s.email = ["jugyo.org@gmail.com"]
9
+ s.homepage = "http://github.com/jugyo/eeepub"
10
+ s.summary = %q{ePub generator}
11
+ s.description = %q{EeePub is a Ruby ePub generator.}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_runtime_dependency(%q<zipruby>, ["~> 0.3"])
19
+ s.add_runtime_dependency(%q<builder>, ["~> 3.0"])
20
+ s.add_development_dependency(%q<rspec>, ["~> 2.0"])
21
+ s.add_development_dependency(%q<rr>, ["~> 1.0"])
22
+ s.add_development_dependency(%q<simplecov>, ["~> 0.4"])
23
+ s.add_development_dependency(%q<nokogiri>, ["~> 1.4"])
24
+ end
@@ -73,53 +73,66 @@ module EeePub
73
73
  #
74
74
  # @param [String] filename the ePub file name to save
75
75
  def save(filename)
76
- Dir.mktmpdir do |dir|
77
- @files.each do |file|
76
+ create_epub.save(filename)
77
+ end
78
+
79
+ # instead of saving to file, output the file contents.
80
+ # important for serving on-the-fly doc creation from
81
+ # web interface where we don't want to allow file system
82
+ # writes (Heroku, et al.)
83
+ def render
84
+ create_epub.render
85
+ end
86
+
87
+ private
88
+
89
+ def create_epub
90
+ dir = Dir.mktmpdir
91
+ @files.each do |file|
92
+ case file
93
+ when String
94
+ FileUtils.cp(file, dir)
95
+ when Hash
96
+ file_path, dir_path = *file.first
97
+ dest_dir = File.join(dir, dir_path)
98
+ FileUtils.mkdir_p(dest_dir)
99
+ FileUtils.cp(file_path, dest_dir)
100
+ end
101
+ end
102
+
103
+ NCX.new(
104
+ :uid => @uid,
105
+ :title => @titles[0],
106
+ :nav => @nav
107
+ ).save(File.join(dir, @ncx_file))
108
+
109
+ OPF.new(
110
+ :title => @titles,
111
+ :identifier => @identifiers,
112
+ :creator => @creators,
113
+ :publisher => @publishers,
114
+ :date => @dates,
115
+ :language => @languages,
116
+ :subject => @subjects,
117
+ :description => @descriptions,
118
+ :rights => @rightss,
119
+ :relation => @relations,
120
+ :manifest => @files.map{|file|
78
121
  case file
79
122
  when String
80
- FileUtils.cp(file, dir)
123
+ File.basename(file)
81
124
  when Hash
82
125
  file_path, dir_path = *file.first
83
- dest_dir = File.join(dir, dir_path)
84
- FileUtils.mkdir_p(dest_dir)
85
- FileUtils.cp(file_path, dest_dir)
126
+ File.join(dir_path, File.basename(file_path))
86
127
  end
87
- end
128
+ },
129
+ :ncx => @ncx_file
130
+ ).save(File.join(dir, @opf_file))
88
131
 
89
- NCX.new(
90
- :uid => @uid,
91
- :title => @titles[0],
92
- :nav => @nav
93
- ).save(File.join(dir, @ncx_file))
94
-
95
- OPF.new(
96
- :title => @titles,
97
- :identifier => @identifiers,
98
- :creator => @creators,
99
- :publisher => @publishers,
100
- :date => @dates,
101
- :language => @languages,
102
- :subject => @subjects,
103
- :description => @descriptions,
104
- :rights => @rightss,
105
- :relation => @relations,
106
- :manifest => @files.map{|file|
107
- case file
108
- when String
109
- File.basename(file)
110
- when Hash
111
- file_path, dir_path = *file.first
112
- File.join(dir_path, File.basename(file_path))
113
- end
114
- },
115
- :ncx => @ncx_file
116
- ).save(File.join(dir, @opf_file))
117
-
118
- OCF.new(
119
- :dir => dir,
120
- :container => @opf_file
121
- ).save(filename)
122
- end
132
+ OCF.new(
133
+ :dir => dir,
134
+ :container => @opf_file
135
+ )
123
136
  end
124
137
  end
125
138
  end
@@ -1,3 +1,5 @@
1
+ require 'zipruby'
2
+
1
3
  module EeePub
2
4
  # Class to create OCF
3
5
  class OCF
@@ -89,6 +91,36 @@ module EeePub
89
91
  def save(output_path)
90
92
  output_path = File.expand_path(output_path)
91
93
 
94
+ create_epub do
95
+ Zip::Archive.open(output_path, Zip::CREATE | Zip::TRUNC) do |zip|
96
+ Dir.glob('**/*').each do |path|
97
+ if File.directory?(path)
98
+ zip.add_dir(path)
99
+ else
100
+ zip.add_file(path)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ # Stream OCF
108
+ #
109
+ # @return [String] streaming output of the zip/epub file.
110
+ def render
111
+ create_epub do
112
+ buffer = Zip::Archive.open_buffer(Zip::CREATE) do |zip|
113
+ Dir.glob('**/*').each do |path|
114
+ zip.add_buffer(path, path)
115
+ end
116
+ end
117
+
118
+ return buffer
119
+ end
120
+ end
121
+
122
+ private
123
+ def create_epub
92
124
  FileUtils.chdir(dir) do
93
125
  File.open('mimetype', 'w') do |f|
94
126
  f << 'application/epub+zip'
@@ -98,10 +130,9 @@ module EeePub
98
130
  FileUtils.mkdir_p(meta_inf)
99
131
 
100
132
  container.save(File.join(meta_inf, 'container.xml'))
101
-
102
- %x(zip -X9 \"#{output_path}\" mimetype)
103
- %x(zip -Xr9D \"#{output_path}\" * -xi mimetype)
133
+ yield
104
134
  end
135
+
105
136
  end
106
137
  end
107
138
  end
@@ -42,7 +42,7 @@ describe "EeePub::Maker" do
42
42
 
43
43
  it 'should save' do
44
44
  stub(FileUtils).cp.with_any_args
45
- mock(Dir).mktmpdir {|i| i.call('/tmp')}
45
+ mock(Dir).mktmpdir { '/tmp' }
46
46
  mock(EeePub::NCX).new(
47
47
  :title => "sample",
48
48
  :nav => [
@@ -100,7 +100,7 @@ describe "EeePub::Maker" do
100
100
  it 'should save' do
101
101
  stub(FileUtils).cp.with_any_args
102
102
  stub(FileUtils).mkdir_p.with_any_args
103
- mock(Dir).mktmpdir {|i| i.call('/tmp')}
103
+ mock(Dir).mktmpdir { '/tmp' }
104
104
  mock(EeePub::NCX).new.with_any_args { stub!.save }
105
105
  mock(EeePub::OPF).new(
106
106
  :title => ["sample"],
@@ -40,4 +40,10 @@ describe "EeePub::OCF" do
40
40
  @ocf.save(output_path)
41
41
  File.exists?(output_path)
42
42
  end
43
+
44
+ it 'should stream epub' do
45
+ output = @ocf.render
46
+ output.size.should == 370
47
+ output.is_binary_data?.should be_true
48
+ end
43
49
  end
@@ -1,12 +1,14 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rubygems'
4
3
  require 'eeepub'
5
- require 'spec'
6
- require 'spec/autorun'
4
+ require 'rspec'
7
5
  require 'nokogiri'
8
6
  require 'rr'
7
+ require 'simplecov'
9
8
 
10
- Spec::Runner.configure do |config|
9
+ RSpec.configure do |config|
11
10
  config.mock_with :rr
12
11
  end
12
+
13
+ SimpleCov.start
14
+
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eeepub
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
4
+ prerelease:
5
+ version: 0.7.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - jugyo
@@ -14,63 +10,91 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-10-24 00:00:00 +09:00
13
+ date: 2011-05-07 00:00:00 +09:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
- name: builder
17
+ name: zipruby
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
24
20
  none: false
25
21
  requirements:
26
- - - ">="
22
+ - - ~>
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
24
+ version: "0.3"
31
25
  type: :runtime
32
26
  version_requirements: *id001
33
27
  - !ruby/object:Gem::Dependency
34
- name: rspec
28
+ name: builder
35
29
  prerelease: false
36
30
  requirement: &id002 !ruby/object:Gem::Requirement
37
31
  none: false
38
32
  requirements:
39
- - - ">="
33
+ - - ~>
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
44
- type: :development
35
+ version: "3.0"
36
+ type: :runtime
45
37
  version_requirements: *id002
46
38
  - !ruby/object:Gem::Dependency
47
- name: rr
39
+ name: rspec
48
40
  prerelease: false
49
41
  requirement: &id003 !ruby/object:Gem::Requirement
50
42
  none: false
51
43
  requirements:
52
- - - ">="
44
+ - - ~>
53
45
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- version: "0"
46
+ version: "2.0"
57
47
  type: :development
58
48
  version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rr
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: "1.0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: simplecov
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: "0.4"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: nokogiri
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: "1.4"
80
+ type: :development
81
+ version_requirements: *id006
59
82
  description: EeePub is a Ruby ePub generator.
60
- email: jugyo.org@gmail.com
83
+ email:
84
+ - jugyo.org@gmail.com
61
85
  executables: []
62
86
 
63
87
  extensions: []
64
88
 
65
- extra_rdoc_files:
66
- - LICENSE
67
- - README.md
89
+ extra_rdoc_files: []
90
+
68
91
  files:
69
92
  - .gitignore
93
+ - Gemfile
70
94
  - LICENSE
71
95
  - README.md
72
96
  - Rakefile
73
- - VERSION
97
+ - eeepub.gemspec
74
98
  - examples/files/bar.html
75
99
  - examples/files/foo.html
76
100
  - examples/simple_epub.rb
@@ -93,8 +117,8 @@ homepage: http://github.com/jugyo/eeepub
93
117
  licenses: []
94
118
 
95
119
  post_install_message:
96
- rdoc_options:
97
- - --charset=UTF-8
120
+ rdoc_options: []
121
+
98
122
  require_paths:
99
123
  - lib
100
124
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -102,21 +126,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
126
  requirements:
103
127
  - - ">="
104
128
  - !ruby/object:Gem::Version
105
- segments:
106
- - 0
107
129
  version: "0"
108
130
  required_rubygems_version: !ruby/object:Gem::Requirement
109
131
  none: false
110
132
  requirements:
111
133
  - - ">="
112
134
  - !ruby/object:Gem::Version
113
- segments:
114
- - 0
115
135
  version: "0"
116
136
  requirements: []
117
137
 
118
138
  rubyforge_project:
119
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.6.0
120
140
  signing_key:
121
141
  specification_version: 3
122
142
  summary: ePub generator
@@ -128,4 +148,3 @@ test_files:
128
148
  - spec/eeepub/opf_spec.rb
129
149
  - spec/eeepub_spec.rb
130
150
  - spec/spec_helper.rb
131
- - examples/simple_epub.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.6.1