gepub 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0bb0db88bb1fdcce1615f3b40bbb25908f1dd2bfcf64860ca8f265c1a75c18a
4
- data.tar.gz: 77ec307c585b4cfa9ff8c38f6c0ddd789ad73091bf24401197185282abfa892a
3
+ metadata.gz: 8c4bd8231fb2f42f3d42f2909605224d3ac30b9ccc52736fc158d1340810e5b3
4
+ data.tar.gz: f6834698805f386ce33b3eff1cba78de141e1f98ee2a9b5f3ee4ea9d588681c3
5
5
  SHA512:
6
- metadata.gz: 157c5f9ee8540f41ff5e868223f00356843e92516f1dd0385060cd8b8ab5c150ef3174c579d4843bc67abde37796e6d19f6ee354dd82710352f67e84d4fdfb7c
7
- data.tar.gz: bd4731d1d62e99681a60b5517fc8e4e3c947a44be86154e171f3f59baf522071fcb038db6bdf7ecebf298ab7358af4860a929debbd404c82c8cee0af62754325
6
+ metadata.gz: 5650ce85cec97fec3aa6da1031c15c8042a0f44008bdabd3b9f54936de48ddee6066b1e67bc1dc791e7259f13bb4f5120dba61587bdbbe7247e26106cee97fa6
7
+ data.tar.gz: 0d30aafeb4f8cd0d5a1b8f3ca239aa5a18142c7b8c00135dfcba7f1d7034bfad87f072b57cc6ccc6cba0d2601863ae3f691594de468c93acc0f05400efd050a9
data/README.md CHANGED
@@ -22,7 +22,7 @@ a generic EPUB parser/generator library.
22
22
 
23
23
  If you are using GEPUB::Builder from your code and do not like its behaviour(e.g. the block inside is evaluated as inside the Builder instance), please consider using GEPUB::Book directly.
24
24
 
25
- ** GEPUB::Builder will be obsolete in gepub 0.7. GEPUB::Book#new will be enhanced instead of Builder DSL. **
25
+ **GEPUB::Builder will be obsolete in gepub 0.7. GEPUB::Book#new will be enhanced instead of Builder DSL.**
26
26
 
27
27
 
28
28
  ## SYNOPSIS:
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'gepub'
4
4
 
5
5
  book = GEPUB::Book.new
6
- book.set_main_id('http:/example.jp/bookid_in_url', 'BookID', 'URL')
6
+ book.primary_identifier('http://example.jp/bookid_in_url', 'BookID', 'URL')
7
7
  book.language = 'ja'
8
8
 
9
9
  # you can add metadata and its property using block
@@ -18,18 +18,18 @@ book.add_title('GEPUBサンプル文書', nil, GEPUB::TITLE_TYPE::MAIN) {
18
18
  'th' => 'GEPUB ตัวอย่าง (ญี่ปุ่น)')
19
19
  }
20
20
  # you can do the same thing using method chain
21
- book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).set_display_seq(1).add_alternates('en' => 'this book is just a sample.')
21
+ book.add_title('これはあくまでサンプルです',nil, GEPUB::TITLE_TYPE::SUBTITLE).display_seq(1).add_alternates('en' => 'this book is just a sample.')
22
22
  book.add_creator('小嶋智') {
23
23
  |creator|
24
24
  creator.display_seq = 1
25
25
  creator.add_alternates('en' => 'KOJIMA Satoshi')
26
26
  }
27
- book.add_contributor('電書部').set_display_seq(1).add_alternates('en' => 'Denshobu')
28
- book.add_contributor('アサガヤデンショ').set_display_seq(2).add_alternates('en' => 'Asagaya Densho')
29
- book.add_contributor('湘南電書鼎談').set_display_seq(3).add_alternates('en' => 'Shonan Densho Teidan')
30
- book.add_contributor('電子雑誌トルタル').set_display_seq(4).add_alternates('en' => 'eMagazine Torutaru')
27
+ book.add_contributor('電書部').display_seq(1).add_alternates('en' => 'Denshobu')
28
+ book.add_contributor('アサガヤデンショ').display_seq(2).add_alternates('en' => 'Asagaya Densho')
29
+ book.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan')
30
+ book.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru')
31
31
 
32
- imgfile = File.join(File.dirname(__FILE__), 'img', 'image1.jpg')
32
+ imgfile = File.join(File.dirname(__FILE__), 'image1.jpg')
33
33
  File.open(imgfile) do
34
34
  |io|
35
35
  book.add_item('img/image1.jpg',io).cover_image
@@ -1,20 +1,18 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'gepub'
3
3
 
4
- GEPUB::Book.new do |book|
5
- book.set_unique_identifier 'http:/example.jp/bookid_in_url', 'BookID', 'URL'
6
- book.set_title 'GEPUB Sample Book'
7
- book.set_subtitle 'GEPUB Sample Book'
8
- book.set_creator 'KOJIMA Satoshi'
9
- book.set_contributors '電書部', 'アサガヤデンショ', '電子雑誌トルタル'
4
+ gbook = GEPUB::Book.new do |book|
5
+ book.identifier = 'http://example.jp/bookid_in_url'
6
+ book.title = 'GEPUB Sample Book'
7
+ book.creator = 'KOJIMA Satoshi'
8
+ book.contributor = '電書部'
9
+ book.add_contributor 'アサガヤデンショ'
10
+ book.add_contributor '電子雑誌トルタル'
11
+ book.language = 'ja'
10
12
 
11
- book.ordered {
12
- book.add_item('name') do
13
- |item|
14
- item.content = StringIO.new()
15
- end
16
- }
13
+ book.ordered do
14
+ item = book.add_item('name.xhtml')
15
+ item.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>')end
17
16
  end
18
17
 
19
-
20
-
18
+ gbook.generate_epub("test.epub")
data/lib/gepub/builder.rb CHANGED
@@ -190,7 +190,9 @@ module GEPUB
190
190
  # define base methods.
191
191
  GEPUB::Metadata::CONTENT_NODE_LIST.each {
192
192
  |name|
193
- define_method(name) { |val| @last_defined_item = MetaItem.new(@book.send("add_#{name}".to_sym, val, nil)) }
193
+ if !["title", "creator", "contributor"].include?(name)
194
+ define_method(name) { |val| @last_defined_item = MetaItem.new(@book.send("add_#{name}".to_sym, val, nil)) }
195
+ end
194
196
  }
195
197
 
196
198
  GEPUB::TITLE_TYPE::TYPES.each {
@@ -205,7 +207,9 @@ module GEPUB
205
207
  else
206
208
  methodname = type
207
209
  end
208
- define_method(methodname) { |val| @last_defined_item = MetaItem.new(@book.add_title(val, nil, type)) }
210
+ if methodname != "collection"
211
+ define_method(methodname) { |val| @last_defined_item = MetaItem.new(@book.add_title(val, nil, type)) }
212
+ end
209
213
  }
210
214
 
211
215
  def collection(val, count = 1)
data/lib/gepub/meta.rb CHANGED
@@ -143,7 +143,7 @@ module GEPUB
143
143
  }.reverse
144
144
  localized = candidates[0].content if candidates.size > 0
145
145
  end
146
- (localized || self.content || super).to_s
146
+ (localized || self.content || super()).to_s
147
147
  end
148
148
  end
149
149
  end
@@ -119,6 +119,8 @@ module GEPUB
119
119
  end
120
120
  }
121
121
 
122
+ next if node == 'title'
123
+
122
124
  define_method(node, ->(content=UNASSIGNED, id=nil) {
123
125
  if unassigned?(content)
124
126
  get_first_node(node)
@@ -128,11 +130,6 @@ module GEPUB
128
130
  end
129
131
  })
130
132
 
131
- define_method('add_' + node) {
132
- |content, id|
133
- add_metadata(node, content, id)
134
- }
135
-
136
133
  define_method('set_' + node) {
137
134
  |content, id|
138
135
  warn "obsolete : set_#{node}. use #{node} instead."
@@ -143,7 +140,18 @@ module GEPUB
143
140
  define_method(node+'=') {
144
141
  |content|
145
142
  send(node + "_clear")
146
- add_metadata(node, content, nil)
143
+ if node == 'date'
144
+ add_date(content, nil)
145
+ else
146
+ add_metadata(node, content, nil)
147
+ end
148
+ }
149
+
150
+ next if ["identifier", "date", "creator", "contributor"].include?(node)
151
+
152
+ define_method('add_' + node) {
153
+ |content, id|
154
+ add_metadata(node, content, id)
147
155
  }
148
156
  }
149
157
 
data/lib/gepub/package.rb CHANGED
@@ -11,7 +11,11 @@ module GEPUB
11
11
  def_delegators :@manifest, :item_by_href
12
12
  def_delegators :@metadata, *Metadata::CONTENT_NODE_LIST.map {
13
13
  |x|
14
- ["#{x}", "#{x}_list", "set_#{x}", "#{x}=", "add_#{x}"]
14
+ if x == "identifier"
15
+ ["#{x}_list", "set_#{x}", "add_#{x}"]
16
+ else
17
+ ["#{x}", "#{x}_list", "set_#{x}", "#{x}=", "add_#{x}"]
18
+ end
15
19
  }.flatten
16
20
  def_delegators :@metadata, :set_lastmodified
17
21
  def_delegators :@metadata, :lastmodified
data/lib/gepub/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module GEPUB
2
2
  # GEPUB gem version
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.1"
4
4
  end
@@ -153,6 +153,13 @@ describe GEPUB::Metadata do
153
153
  expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
154
154
  end
155
155
 
156
+ it 'should handle date with `date=` method and Time object' do
157
+ metadata = GEPUB::Metadata.new
158
+ a = Time.parse '2012-02-27 20:00:00 UTC'
159
+ metadata.date = a
160
+ expect(metadata.date.to_s).to eq('2012-02-27T20:00:00Z')
161
+ end
162
+
156
163
  it 'should handle date with Time object by content = ' do
157
164
  metadata = GEPUB::Metadata.new
158
165
  a = Time.parse '2012-02-27 20:00:00 UTC'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gepub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - KOJIMA Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-14 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri