gepub 0.6.3.1 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/gepuber CHANGED
@@ -44,12 +44,45 @@ destbasedir = File.expand_path(destbasedir)
44
44
  srcdir = opt.parse(ARGV)[0]
45
45
  srccheck(srcdir, configfilename)
46
46
 
47
+ epubname_to_generate = 'gepuber_generated.epub'
48
+
47
49
  Dir.chdir(srcdir)
48
50
  begin
49
51
  File.open(configfilename, 'rb') {
50
52
  |io|
51
- gepuber = GEPUB::Gepuber.new(eval("#{io.read}"))
52
- gepuber.create destbasedir
53
+ GEPUB::Builder.new {
54
+ table_of_contents = {}
55
+ (class<< self;self;end).send(
56
+ :define_method,
57
+ :epub_name, Proc.new { |name|
58
+ epubname_to_generate = name
59
+ })
60
+ eval "#{io.read}"
61
+ resources {
62
+ Dir.glob('*.css') {
63
+ |f|
64
+ file f
65
+ }
66
+ Dir.glob('img/*') {
67
+ |f|
68
+ if File.basename(f) == 'cover.jpg'
69
+ cover_image f
70
+ else
71
+ file f
72
+ end
73
+ }
74
+ ordered {
75
+ Dir.glob('[0-9]*.{xhtml,html}') {
76
+ |f|
77
+ file f
78
+ if table_of_contents[f]
79
+ heading table_of_contents[f]
80
+ end
81
+ }
82
+ }
83
+ }
84
+ }.generate_epub(File.join(destbasedir, epubname_to_generate))
53
85
  }
54
86
  end
87
+
55
88
 
data/lib/gepub/gepuber.rb CHANGED
@@ -2,65 +2,40 @@ require 'rubygems'
2
2
 
3
3
  module GEPUB
4
4
  class Gepuber
5
- class FileProvider
6
- include Enumerable
7
- def initialize(pattern)
8
- @list = Dir.glob(pattern)
9
- end
10
-
11
- def each (&block)
12
- @list.each {
13
- |f|
14
- File.open(f, 'rb') {
15
- |fio|
16
- yield f, fio
17
- }
18
- }
19
- end
5
+ def initialize(&block)
6
+ @block = block
20
7
  end
21
8
 
22
- attr_accessor :texts, :resources, :epubname, :coverimg, :table_of_contents, :provider
23
-
24
- def method_missing(name, *args)
25
- @book.send(name, *args)
26
- end
27
-
28
- def initialize(param)
29
- @book = GEPUB::Book.new()
30
- param.each {
31
- |k,v|
32
- self.send "#{k}=", v
33
- }
34
- @texts ||= ['[0-9]*.{xhtml,html}']
35
- @resources ||= ['*.css', 'img/*']
36
- @coverimg ||= 'cover.jpg'
37
- @table_of_contents ||= {}
38
- @epubname ||= 'gepuber_generated'
39
- @provider ||= FileProvider
40
- end
9
+ def create
10
+ table_of_contents = {}
11
+ epub_name = 'gepuber_generated.epub'
12
+ GEPUB::Builder.new {
13
+ block.call
14
+ resources {
15
+ Dir.glob('*.css') {
16
+ |f|
17
+ file f
18
+ }
19
+ Dir.glob('img/*') {
20
+ |f|
21
+ if File.basename(f) == 'cover.jpg'
22
+ cover_image f
23
+ else
24
+ file f
25
+ end
26
+ }
41
27
 
42
- def create(destbasedir = ".")
43
- @provider.new(@texts).each {
44
- |f, fio|
45
- @book.ordered {
46
- item = add_item(f, fio)
47
- if !@table_of_contents[f].nil?
48
- item.toc_text table_of_contents[f]
49
- @table_of_contents.each {
50
- |k,v|
51
- k =~ /^#{f}#(.*)$/
52
- add_nav(item, v, $1) unless $1.nil?
28
+ ordered {
29
+ Dir.glob('[0-9]*.{xhtml,html}') {
30
+ |f|
31
+ file f
32
+ if table_of_contents[f]
33
+ heading table_of_contents[f]
34
+ end
53
35
  }
54
- end
36
+ }
55
37
  }
56
38
  }
57
-
58
- @provider.new(@resources).each {
59
- |f, fio|
60
- item = add_item(f, fio)
61
- item.cover_image if File.basename(f) == @coverimg
62
- }
63
- generate_epub(File.join(destbasedir, @epubname + '.epub'))
64
39
  end
65
40
  end
66
41
  end
data/lib/gepub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GEPUB
2
- VERSION = "0.6.3.1"
2
+ VERSION = "0.6.4"
3
3
  end
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.1
4
+ version: 0.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70317965172840 !ruby/object:Gem::Requirement
16
+ requirement: &70124628533140 !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: *70317965172840
24
+ version_requirements: *70124628533140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70317964165820 !ruby/object:Gem::Requirement
27
+ requirement: &70124628532640 !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: *70317964165820
35
+ version_requirements: *70124628532640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rubyzip
38
- requirement: &70317964163220 !ruby/object:Gem::Requirement
38
+ requirement: &70124628532180 !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: *70317964163220
46
+ version_requirements: *70124628532180
47
47
  description: gepub is a generic EPUB parser/generator. Generates and parse EPUB2 and
48
48
  EPUB3
49
49
  email:
@@ -99,7 +99,6 @@ files:
99
99
  - spec/fixtures/testdata/image1.jpg
100
100
  - spec/fixtures/testdata/test.opf
101
101
  - spec/gepub_spec.rb
102
- - spec/gepuber_spec.rb
103
102
  - spec/manifest_spec.rb
104
103
  - spec/metadata_spec.rb
105
104
  - spec/package_spec.rb
@@ -152,7 +151,6 @@ test_files:
152
151
  - spec/fixtures/testdata/image1.jpg
153
152
  - spec/fixtures/testdata/test.opf
154
153
  - spec/gepub_spec.rb
155
- - spec/gepuber_spec.rb
156
154
  - spec/manifest_spec.rb
157
155
  - spec/metadata_spec.rb
158
156
  - spec/package_spec.rb
data/spec/gepuber_spec.rb DELETED
@@ -1,50 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + '/spec_helper.rb'
4
- require 'rubygems'
5
-
6
- describe GEPUB::Gepuber do
7
- it "should be initialized with empty conf" do
8
- gepuber = GEPUB::Gepuber.new({})
9
- gepuber.texts.should == ['[0-9]*.{xhtml,html}']
10
- gepuber.resources.should == ['*.css', 'img/*']
11
- gepuber.title.to_s.should == ""
12
- gepuber.table_of_contents.should == {}
13
- end
14
-
15
- it "should read config hash" do
16
- conf =
17
- {
18
- :language => 'ja',
19
- :title => 'theTitle',
20
- :creator => '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 => {
26
- '1_.html' => '1st toc',
27
- '3_.html' => '3rd toc',
28
- '3_.html#a1' => '3rd toc 2',
29
- '9_.html' => 'last toc'
30
- },
31
- :coverimg => 'cover.gif',
32
- :texts => [ '*.html' ],
33
- :resources => ['*.css','*.gif']
34
- }
35
-
36
- gepuber = GEPUB::Gepuber.new(conf )
37
- gepuber.title.to_s.should == "theTitle"
38
- gepuber.language.to_s.should == "ja"
39
- gepuber.creator.to_s.should == "theAuthor"
40
- gepuber.publisher.to_s.should == "thePublisher"
41
- gepuber.date.to_s.should == "2011-03-11"
42
- gepuber.identifier.should == 'http://skoji.jp/gepuber/2011-03-11.0.0'
43
- gepuber.epubname.should == 'gepub_00'
44
- gepuber.coverimg.should == 'cover.gif'
45
- gepuber.table_of_contents.should == { '1_.html' => '1st toc', '3_.html' => '3rd toc', '3_.html#a1' => '3rd toc 2','9_.html' => 'last toc'}
46
- gepuber.texts.should == ['*.html']
47
- gepuber.resources.should == ['*.css', '*.gif']
48
-
49
- end
50
- end