epub-maker 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13a8872f5fc2aa702e7a3b345e14bc10ddfe14c4f05715964ed887c7a5e43f1a
4
- data.tar.gz: 9bc0d73cf5aa30d7c78d4aa4afbcee93feb0d32626f2f44a016dd85733c988e8
3
+ metadata.gz: 816986a0e0e3f170275270068e795f5b59dba7b786812bce6596b812f5b9e1ca
4
+ data.tar.gz: e7338e106f3ede913aa2d53fa031f7638b2c1cefba3fa00f5cd17e264927ead2
5
5
  SHA512:
6
- metadata.gz: d5757a93cc5a4a3fbdf8a47661fba858d8c9fd15db9a80527125745d3b0b62b4f02d7b57dcb85097fb106d3b1ee95a44df23e6356517cccb8b93fe394fda1552
7
- data.tar.gz: 883f0dd647d80283867e7e2baedb040bd0831d7d5501c6decafa0ff1ea7961c2359a078b3db800499bc2a6078322044131687e8571f639c137fac3064423ddcf
6
+ metadata.gz: 61b29b15aeb9848bfae40ab97644fa84b18b582e50adea2051b417a29b6e5efcc056dd9da457300e5a7c0364279d91e928d9bf6923986935b6225c7e01e7ae28
7
+ data.tar.gz: eef00806fe74397d78334387b3e81eca6730364630db152c640fbe6a69106476fe99910abd2a7e09a117fde45ec42f88254f74b13540e0600318229c68929c2a
@@ -46,3 +46,13 @@ test:2.6:
46
46
  key: ruby:2.6
47
47
  paths:
48
48
  - deps
49
+
50
+ test:2.7:
51
+ image: ruby:2.7
52
+ script: bundle exec rake test
53
+ except:
54
+ - tags
55
+ cache:
56
+ key: ruby:2.7
57
+ paths:
58
+ - deps
@@ -1,3 +1,9 @@
1
+ 0.1.4
2
+ -----
3
+
4
+ * Add `Pubication::Package::Metadata#modified=` method
5
+ * Rescue Errno::EXDEV on renaming temporary EPUB file
6
+
1
7
  0.1.3
2
8
  -----
3
9
 
@@ -178,6 +178,11 @@ Todo
178
178
  Recent Changes
179
179
  --------------
180
180
 
181
+ ### 0.1.4
182
+
183
+ * Add `Pubication::Package::Metadata#modified=` method
184
+ * Rescue Errno::EXDEV on renaming temporary EPUB file
185
+
181
186
  ### 0.1.3
182
187
 
183
188
  * Add workaround Window file renaming problem
@@ -186,45 +191,6 @@ Recent Changes
186
191
 
187
192
  * Close temp file when archiving EPUB file
188
193
 
189
- ### 0.1.1
190
-
191
- * Update Nokogiri version to < 1.11
192
-
193
- ### 0.1.0
194
-
195
- * [BUG FIX]Fix the case file extension should be wrong
196
- * Add Nokogiri to runtime dependencies explicitly
197
-
198
- ### 0.0.9
199
-
200
- * Remove [ruby-uuid][] gem from dependencies
201
- * [BUG FIX]Convert Set to Array before writing into XML
202
- * Follow change of EPUB Parser v0.3.6
203
-
204
- [ruby-uuid]: https://github.com/shyouhei/ruby-uuid
205
-
206
- ### 0.0.8
207
-
208
- * Use default temporary directory for `EPUB::Maker.archive`
209
-
210
- ### 0.0.7
211
-
212
- * Change temporary directory used by `EPUB::Maker.archive`
213
-
214
- ### 0.0.6
215
-
216
- * Add `epub-archive` command
217
- * Add `EPUB::Maker.archive` method
218
-
219
- ### 0.0.5
220
-
221
- * Fix bug to modify `dc:rights` to `dc:right`
222
-
223
- ### 0.0.4
224
- * API change: #save -> #write for PhysicalContainer classes
225
- * Bump required EPUB Parser version: 0.2.0 -> 0.2.6
226
- * Deprecate `EPUB::OCF::PhysicalContainer.save`
227
-
228
194
  Contributing
229
195
  ------------
230
196
 
@@ -33,7 +33,7 @@ module EPUB
33
33
  begin
34
34
  ::File.chmod 0666 & ~::File.umask, tmp_archive_path
35
35
  ::File.rename tmp_archive_path, @container_path
36
- rescue Errno::EACCES
36
+ rescue Errno::EACCES, Errno::EXDEV
37
37
  # In some cases on Windows, we fail to rename the file
38
38
  # but succeed to copy although I don't know why.
39
39
  # Race condition? I don't know. But no time to dig deeper.
@@ -1,6 +1,7 @@
1
1
  require 'securerandom'
2
2
  require 'epub/publication/package'
3
3
  require "nokogiri"
4
+ require "mimemagic"
4
5
 
5
6
  module EPUB
6
7
  module Publication
@@ -183,6 +184,21 @@ module EPUB
183
184
  name
184
185
  end
185
186
 
187
+ # Shortcut to set modified date time
188
+ # @param datetime [String, #to_time]
189
+ def modified=(datetime)
190
+ modified = self.modified
191
+ unless modified
192
+ modified = Meta.new
193
+ modified.property = "dcterms:modified"
194
+ self.metas << modified
195
+ end
196
+ modified.content = datetime.respond_to?(:to_time) ?
197
+ datetime.to_time.utc.xmlschema :
198
+ datetime
199
+ modified
200
+ end
201
+
186
202
  class Meta
187
203
  def valid?
188
204
  property
@@ -235,6 +251,15 @@ module EPUB
235
251
  end
236
252
  item.manifest = self
237
253
  yield item if block_given?
254
+ unless item.media_type
255
+ path = item.href.to_s
256
+ item.media_type =
257
+ if path.end_with? ".html"
258
+ "application/xhtml+xml"
259
+ else
260
+ MimeMagic.by_path(item.href.to_s).type
261
+ end
262
+ end
238
263
  self << item
239
264
  item
240
265
  end
@@ -1,5 +1,5 @@
1
1
  module EPUB
2
2
  module Maker
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@
2
2
  require_relative 'helper'
3
3
  require 'epub/parser'
4
4
  require 'epub/maker/publication'
5
+ require "date"
5
6
 
6
7
  class TestMakerPublication < Test::Unit::TestCase
7
8
  def setup
@@ -37,4 +38,25 @@ class TestMakerPublication < Test::Unit::TestCase
37
38
  media_type = doc.xpath('/opf:package/opf:bindings/opf:mediaType', EPUB::NAMESPACES).first
38
39
  assert_equal 'application/x-demo-slideshow', media_type['media-type']
39
40
  end
41
+
42
+ def test_modified=
43
+ metadata = EPUB::Publication::Package::Metadata.new
44
+ metadata.modified = "2011-01-01T12:00:00Z"
45
+
46
+ assert_equal 1, metadata.metas.length
47
+ assert_equal "2011-01-01T12:00:00Z", metadata.modified.content
48
+
49
+ metadata.modified = Time.new(2020, 2, 1, 0, 0, 0, "+09:00")
50
+ assert_equal 1, metadata.metas.length
51
+ assert_equal "2020-01-31T15:00:00Z", metadata.modified.content
52
+
53
+ metadata.modified = Date.new(1993, 2, 24)
54
+ assert_equal 1, metadata.metas.length
55
+ expected = Time.new(1993, 2, 24, 0, 0, 0, Time.now.utc_offset)
56
+ assert_equal expected.utc.xmlschema, metadata.modified.content
57
+
58
+ metadata.modified = DateTime.new(1993, 2, 24, 0, 0, 0, "+00:00")
59
+ assert_equal 1, metadata.metas.length
60
+ assert_equal "1993-02-24T00:00:00Z", metadata.modified.content
61
+ end
40
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub-maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: epub-parser