gepub 0.6.4.5 → 0.6.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ module GEPUB
23
23
  def initialize(book, attributes = {}, &block)
24
24
  @last_defined_item = nil
25
25
  @book = book
26
+ @dir_prefix = ""
26
27
  @file_postprocess = {}
27
28
  @file_preprocess = {}
28
29
  @files_postprocess = {}
@@ -70,6 +71,19 @@ module GEPUB
70
71
  }
71
72
  end
72
73
 
74
+ def glob(arg)
75
+ files(*Dir.glob(arg))
76
+ end
77
+
78
+ def import(conf, args = {})
79
+ dir_prefix_org = @dir_prefix
80
+ @dir_prefix = args[:dir_prefix] || ""
81
+ Dir.chdir(File.dirname(conf)) {
82
+ instance_eval(File.new(File.basename(conf)).read)
83
+ }
84
+ @dir_prefix = dir_prefix_org
85
+ end
86
+
73
87
  def cover_image(val)
74
88
  file(val)
75
89
  @last_defined_item.cover_image
@@ -140,6 +154,7 @@ module GEPUB
140
154
  name = val[0]
141
155
  io = val[1]
142
156
  end
157
+ name = "#{@dir_prefix}/#{name}" if !@dir_prefix.nil? && @dir_prefix.size > 0
143
158
  @book.add_item(name, io)
144
159
  end
145
160
  end
data/lib/gepub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GEPUB
2
- VERSION = "0.6.4.5"
2
+ VERSION = "0.6.4.6"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -171,6 +171,42 @@ describe GEPUB::Builder do
171
171
  builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }.should_not be_nil
172
172
  end
173
173
 
174
+ it 'should add files to book with glob' do
175
+ workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
176
+ builder = GEPUB::Builder.new {
177
+ resources(:workdir => workdir) {
178
+ glob 'text/*.{txt,xhtml}'
179
+ }
180
+ }
181
+ builder.instance_eval{ @book.item_by_href('text/memo.txt') }.should_not be_nil
182
+ builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }.should == 'just a plain text.'
183
+ builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }.should_not be_nil
184
+ end
185
+
186
+ it 'should add files to book with import with prefix' do
187
+ workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
188
+ builder = GEPUB::Builder.new {
189
+ resources(:workdir => workdir) {
190
+ import 'text/localresource.conf'
191
+ }
192
+ }
193
+ builder.instance_eval{ @book.item_by_href('memo.txt') }.should_not be_nil
194
+ builder.instance_eval{ @book.item_by_href('memo.txt').content.chomp }.should == 'just a plain text.'
195
+ builder.instance_eval{ @book.item_by_href('cover.xhtml') }.should_not be_nil
196
+ end
197
+
198
+ it 'should add files to book with import with prefix' do
199
+ workdir = File.join(File.dirname(__FILE__),'fixtures', 'builder')
200
+ builder = GEPUB::Builder.new {
201
+ resources(:workdir => workdir) {
202
+ import 'text/localresource.conf', :dir_prefix => 'text'
203
+ }
204
+ }
205
+ builder.instance_eval{ @book.item_by_href('text/memo.txt') }.should_not be_nil
206
+ builder.instance_eval{ @book.item_by_href('text/memo.txt').content.chomp }.should == 'just a plain text.'
207
+ builder.instance_eval{ @book.item_by_href('text/cover.xhtml') }.should_not be_nil
208
+ end
209
+
174
210
  it 'should add files to book from IO object' do
175
211
  io = File.new(File.join(File.dirname(__FILE__),'fixtures', 'builder', 'text', 'memo.txt'))
176
212
  builder = GEPUB::Builder.new {
@@ -0,0 +1,2 @@
1
+ file 'memo.txt'
2
+ file 'cover.xhtml'
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.4.5
4
+ version: 0.6.4.6
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-03-03 00:00:00.000000000 Z
12
+ date: 2012-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70217493796500 !ruby/object:Gem::Requirement
16
+ requirement: &70096651811060 !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: *70217493796500
24
+ version_requirements: *70096651811060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70217502273260 !ruby/object:Gem::Requirement
27
+ requirement: &70096651810400 !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: *70217502273260
35
+ version_requirements: *70096651810400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rubyzip
38
- requirement: &70217502271300 !ruby/object:Gem::Requirement
38
+ requirement: &70096651809700 !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: *70217502271300
46
+ version_requirements: *70096651809700
47
47
  description: gepub is a generic EPUB parser/generator. Generates and parse EPUB2 and
48
48
  EPUB3
49
49
  email:
@@ -85,6 +85,7 @@ files:
85
85
  - spec/fixtures/builder/resources/noise.m4
86
86
  - spec/fixtures/builder/resources/noise_2.m4a
87
87
  - spec/fixtures/builder/text/cover.xhtml
88
+ - spec/fixtures/builder/text/localresource.conf
88
89
  - spec/fixtures/builder/text/memo.txt
89
90
  - spec/fixtures/builder/text/nav.xhtml
90
91
  - spec/fixtures/epubcheck-3.0b4/COPYING.txt
@@ -137,6 +138,7 @@ test_files:
137
138
  - spec/fixtures/builder/resources/noise.m4
138
139
  - spec/fixtures/builder/resources/noise_2.m4a
139
140
  - spec/fixtures/builder/text/cover.xhtml
141
+ - spec/fixtures/builder/text/localresource.conf
140
142
  - spec/fixtures/builder/text/memo.txt
141
143
  - spec/fixtures/builder/text/nav.xhtml
142
144
  - spec/fixtures/epubcheck-3.0b4/COPYING.txt