gepub 0.7.1 → 1.0.0beta1

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: 8c4bd8231fb2f42f3d42f2909605224d3ac30b9ccc52736fc158d1340810e5b3
4
- data.tar.gz: f6834698805f386ce33b3eff1cba78de141e1f98ee2a9b5f3ee4ea9d588681c3
3
+ metadata.gz: b309e48823e6ba81b9ec3d9082cb3be3e0f0198352ad439ba422234a0ab905f2
4
+ data.tar.gz: 2558196c081bd7cd71d70c912213820879b1f5d6df3ad96b6b39899d23213a14
5
5
  SHA512:
6
- metadata.gz: 5650ce85cec97fec3aa6da1031c15c8042a0f44008bdabd3b9f54936de48ddee6066b1e67bc1dc791e7259f13bb4f5120dba61587bdbbe7247e26106cee97fa6
7
- data.tar.gz: 0d30aafeb4f8cd0d5a1b8f3ca239aa5a18142c7b8c00135dfcba7f1d7034bfad87f072b57cc6ccc6cba0d2601863ae3f691594de468c93acc0f05400efd050a9
6
+ metadata.gz: 3ac54805a6b2582cbefa12655fd0c7d27801f16608c70b9355b81b6d6e623ffe0b94ed3f95a4bc4acc58b69d09476551a43d9f3926c42f0d59c1fc80cdea3ec9
7
+ data.tar.gz: d05593c50c03ae43a6a644b7a7ac2c2a9239025f35cfc09adb2dbb61729633ec5456d426cf1bd4e83624dd14d04e9b5a3cfb2d93d7eac43ce16a7acddd7d5e45
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.4
4
- - 2.5.1
3
+ - 2.4.5
4
+ - 2.5.3
5
5
  script: bundle exec rake spec
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
  require 'rdoc/task'
4
4
 
5
- RSpec::Core::RakeTask.new(:spec)
5
+ RSpec::Core::RakeTask.new(:spec => :generate_code)
6
6
 
7
7
  task :default => :spec
8
8
 
@@ -11,3 +11,11 @@ RDoc::Task.new(:rdoc) do |rdoc|
11
11
  rdoc.rdoc_dir = "rdoc"
12
12
  rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
13
13
  end
14
+
15
+ # also generates 'lib/gepub/book_add_item.rb'
16
+ file 'lib/gepub/metadata_add.rb' => 'tools/generate_function.rb' do
17
+ sh %Q(ruby tools/generate_function.rb)
18
+ end
19
+
20
+ desc 'auto generate code'
21
+ task :generate_code => ['lib/gepub/metadata_add.rb']
@@ -7,7 +7,7 @@ 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
10
- book.add_title('GEPUBサンプル文書', nil, GEPUB::TITLE_TYPE::MAIN) {
10
+ book.add_title('GEPUBサンプル文書', title_type: GEPUB::TITLE_TYPE::MAIN) {
11
11
  |title|
12
12
  title.lang = 'ja'
13
13
  title.file_as = 'GEPUB Sample Book'
@@ -18,7 +18,7 @@ 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).display_seq(1).add_alternates('en' => 'this book is just a sample.')
21
+ book.add_title('これはあくまでサンプルです', title_type: 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
data/lib/gepub/book.rb CHANGED
@@ -42,9 +42,9 @@ module GEPUB
42
42
  # same as identifier=, but can specify id (in the opf xml) and identifier type(i.e. URL, uuid, ISBN, etc)
43
43
  # === Book#add_identifier(string, id, type=nil) (delegated to Metadata#add_identifier)
44
44
  # Set an identifier metadata. It it not unique-identifier in opf. Many EPUB files do not set identifier other than unique-identifier.
45
- # === Book#add_title(content, id = nil, title_type = nil) (delegated to Metadata#add_title)
45
+ # === Book#add_title(content, id: nil, title_type: nil) (delegated to Metadata#add_title)
46
46
  # add title metadata. title_type candidates is defined in TITLE_TYPES.
47
- # === Book#set_title(content, id = nil, title_type = nil) (delegated to Metadata#set_title)
47
+ # === Book#title(content, id = nil, title_type = nil) (delegated to Metadata#title)
48
48
  # clear all titles and then add title.
49
49
  # === Book#title (delegated to Metadata)
50
50
  # returns 'main' title Meta object. 'main' title is determined by this order:
@@ -79,7 +79,7 @@ module GEPUB
79
79
  # === Book#lastmodified (delegated to Metadata#lastmodified)
80
80
  # returns Meta object contains last modified time.
81
81
  # === setting and reading other metadata: publisher, language, coverage, date, description, format, relation, rights, source, subject, type (delegated to Metadata)
82
- # they all have methods like: publisher(which returns 'main' publisher), add_publisher(content, id) (which add publisher), set_publisher or publisher= (clears and set publisher), and publisher_list(returns publisher Meta object in display-seq order).
82
+ # they all have methods like: publisher(which returns 'main' publisher), add_publisher(content, id) (which add publisher), publisher= (clears and set publisher), and publisher_list(returns publisher Meta object in display-seq order).
83
83
  # === Book#page_progression_direction= (delegated to Spine#page_progression_direction=)
84
84
  # set page-proression-direction attribute to spine.
85
85
 
@@ -167,23 +167,6 @@ module GEPUB
167
167
 
168
168
  end
169
169
 
170
- # add an item(i.e. html, images, audios, etc) to Book.
171
- # the added item will be referenced by the first argument in the EPUB container.
172
- def add_item(href, io_or_filename = nil, id = nil, attributes = {})
173
- item = @package.add_item(href,nil,id,attributes)
174
- set_singleton_methods_to_item(item)
175
- item.add_content io_or_filename unless io_or_filename.nil?
176
- item
177
- end
178
-
179
- # same as add_item, but the item will be added to spine of the EPUB.
180
- def add_ordered_item(href, io_or_filename = nil, id = nil, attributes = {})
181
- item = @package.add_ordered_item(href,io_or_filename,id,attributes)
182
- set_singleton_methods_to_item(item)
183
- yield item if block_given?
184
- item
185
- end
186
-
187
170
 
188
171
  # get handler item which defined in bindings for media type,
189
172
  def get_handler_of(media_type)
@@ -279,7 +262,7 @@ EOF
279
262
  end
280
263
 
281
264
  def generate_nav_doc(title = 'Table of Contents')
282
- add_item('nav.xhtml', StringIO.new(nav_doc(title)), 'nav').add_property('nav')
265
+ add_item('nav.xhtml', id: 'nav', content: StringIO.new(nav_doc(title))).add_property('nav')
283
266
  end
284
267
 
285
268
  def nav_doc(title = 'Table of Contents')
@@ -422,7 +405,7 @@ EOF
422
405
  if (@toc.size == 0)
423
406
  @toc << { :item => @package.manifest.item_list[@package.spine.itemref_list[0].idref] }
424
407
  end
425
- add_item('toc.ncx', StringIO.new(ncx_xml), 'ncx')
408
+ add_item('toc.ncx', id: 'ncx', content: StringIO.new(ncx_xml))
426
409
  end
427
410
  end
428
411
  end
@@ -443,5 +426,51 @@ EOF
443
426
  }.reject(&:nil?)
444
427
  end
445
428
  end
429
+
430
+ private
431
+
432
+ def add_item_internal(href, content: nil, item_attributes: , attributes: {}, ordered: )
433
+ id = item_attributes.delete(:id)
434
+ item =
435
+ if ordered
436
+ @package.add_ordered_item(href,attributes: attributes, id:id, content: content)
437
+ else
438
+ @package.add_item(href, attributes: attributes, id: id, content: content)
439
+ end
440
+ set_singleton_methods_to_item(item)
441
+ item_attributes.each do |attr, val|
442
+ next if val.nil?
443
+ method_name = if attr == :toc_text
444
+ attr.to_s
445
+ else
446
+ "add_" + attr.to_s
447
+ end
448
+ item.send(method_name, val)
449
+ end
450
+ item
451
+ end
452
+
453
+ def handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
454
+ if deprecated_content
455
+ msg = 'deprecated argument; use content keyword argument instead of 2nd argument'
456
+ fail msg if content
457
+ warn msg
458
+ content = deprecated_content
459
+ end
460
+ if deprecated_id
461
+ msg = 'deprecated argument; use id keyword argument instead of 3rd argument'
462
+ fail msg if id
463
+ warn msg
464
+ id = deprecated_id
465
+ end
466
+ if deprecated_attributes
467
+ msg = 'deprecated argument; use argument keyword attributes instead of 4th argument'
468
+ fail msg if attributes.size > 0
469
+ warn msg
470
+ attributes = deprecated_attributes
471
+ end
472
+ return content, id, attributes
473
+ end
474
+
446
475
  end
447
476
  end
@@ -0,0 +1,20 @@
1
+ module GEPUB
2
+ class Book
3
+ # add an item(i.e. html, images, audios, etc) to Book.
4
+ # the added item will be referenced by the first argument in the EPUB container.
5
+ def add_item(href, deprecated_content = nil, deprecated_id = nil, deprecated_attributes = nil, content: nil,
6
+ id: nil,media_type: nil,fallback: nil,properties: nil,media_overlay: nil,toc_text: nil,
7
+ attributes: {})
8
+ content, id, attributes = handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
9
+ add_item_internal(href, content: content, item_attributes: { id: id,media_type: media_type,fallback: fallback,properties: properties,media_overlay: media_overlay,toc_text: toc_text }, attributes: attributes, ordered: false)
10
+ end
11
+
12
+ # same as add_item, but the item will be added to spine of the EPUB.
13
+ def add_ordered_item(href, deprecated_content = nil, deprecated_id = nil, deprecated_attributes = nil, content:nil,
14
+ id: nil,media_type: nil,fallback: nil,properties: nil,media_overlay: nil,toc_text: nil,
15
+ attributes: {})
16
+ content, id, attributes = handle_deprecated_add_item_arguments(deprecated_content, deprecated_id, deprecated_attributes, content, id, attributes)
17
+ add_item_internal(href, content: content, item_attributes: { id: id,media_type: media_type,fallback: fallback,properties: properties,media_overlay: media_overlay,toc_text: toc_text }, attributes: attributes, ordered: true)
18
+ end
19
+ end
20
+ end
data/lib/gepub/builder.rb CHANGED
@@ -208,17 +208,17 @@ module GEPUB
208
208
  methodname = type
209
209
  end
210
210
  if methodname != "collection"
211
- define_method(methodname) { |val| @last_defined_item = MetaItem.new(@book.add_title(val, nil, type)) }
211
+ define_method(methodname) { |val| @last_defined_item = MetaItem.new(@book.add_title(val, title_type: type)) }
212
212
  end
213
213
  }
214
214
 
215
215
  def collection(val, count = 1)
216
216
  @last_defined_item =
217
- MetaItem.new(@book.add_title(val, nil, GEPUB::TITLE_TYPE::COLLECTION).group_position(count.to_s))
217
+ MetaItem.new(@book.add_title(val, title_type: GEPUB::TITLE_TYPE::COLLECTION).group_position(count.to_s))
218
218
  end
219
219
 
220
220
  def creator(val, role = 'aut')
221
- MetaItem.new(@book.add_creator(val, nil, role))
221
+ MetaItem.new(@book.add_creator(val, role: role))
222
222
  end
223
223
 
224
224
  def creators(*vals)
@@ -227,7 +227,7 @@ module GEPUB
227
227
  name = v
228
228
  role = 'aut'
229
229
  name,role = v[0], v[1] if Array === name
230
- MetaItem.new(@book.add_creator(name, nil, role))
230
+ MetaItem.new(@book.add_creator(name, role: role))
231
231
  }
232
232
  end
233
233
 
@@ -237,14 +237,14 @@ module GEPUB
237
237
  name = v
238
238
  role = nil
239
239
  name,role = v[0], v[1] if Array === name
240
- MetaItem.new(@book.add_contributor(name, nil, role))
240
+ MetaItem.new(@book.add_contributor(name, role: role))
241
241
  }
242
242
  end
243
243
 
244
244
  def publishers(*vals)
245
245
  @last_defined_item = vals.map {
246
246
  |v|
247
- MetaItem.new(@book.add_publisher(v, nil))
247
+ MetaItem.new(@book.add_publisher(v))
248
248
  }
249
249
  end
250
250
 
@@ -261,7 +261,7 @@ module GEPUB
261
261
  end
262
262
 
263
263
  def contributor(val, role = nil)
264
- MetaItem.new(@book.add_contributor(val, nil, role))
264
+ MetaItem.new(@book.add_contributor(val, role: role))
265
265
  end
266
266
 
267
267
  # set page progression direction.
data/lib/gepub/item.rb CHANGED
@@ -29,10 +29,10 @@ module GEPUB
29
29
  self
30
30
  end
31
31
 
32
- ['id', 'href', 'media-type', 'fallback', 'properties', 'media-overlay'].each { |name|
32
+ ATTRIBUTES = ['id', 'href', 'media-type', 'fallback', 'properties', 'media-overlay'].each { |name|
33
33
  methodbase = name.sub('-','_')
34
34
  define_method(methodbase + '=') { |val| @attributes[name] = val }
35
- define_method('set_' + methodbase) { |val| @attributes[name] = val }
35
+ define_method('set_' + methodbase) { |val| @attributes[name] = val; self }
36
36
  define_method(methodbase) { @attributes[name] }
37
37
  }
38
38
 
@@ -110,6 +110,7 @@ module GEPUB
110
110
  def add_raw_content(data)
111
111
  @content = data
112
112
  guess_content_property
113
+ self
113
114
  end
114
115
 
115
116
  # add content form io or file to the item
data/lib/gepub/meta.rb CHANGED
@@ -62,7 +62,7 @@ module GEPUB
62
62
  self
63
63
  end
64
64
 
65
- ['title-type', 'identifier-type', 'display-seq', 'file-as', 'group-position', 'role'].each {
65
+ REFINERS = ['title-type', 'identifier-type', 'display-seq', 'file-as', 'group-position', 'role'].each {
66
66
  |name|
67
67
  methodbase = name.sub('-','_')
68
68
  define_method(methodbase + '=') { |val| refine(name, val) }
@@ -114,8 +114,14 @@ module GEPUB
114
114
  @attributes['id'] = id_pool.generate_key(:prefix => name) if @attributes['id'].nil?
115
115
  end
116
116
 
117
- # using eval to parametarize Namespace and content.
118
- eval "builder#{ ns.nil? || @name == 'meta' ? '' : '[ns]'}.#{@name}(@attributes.reject{|k,v| v.nil?}.merge(additional_attr)#{@content.nil? ? '' : ', self.to_s'})"
117
+ # using __send__ to parametarize Namespace and content.
118
+ target = ns.nil? || @name == 'meta' ? builder : builder[ns]
119
+ attr = @attributes.reject{|k,v| v.nil?}.merge(additional_attr)
120
+ if @content.nil?
121
+ target.__send__(@name, attr)
122
+ else
123
+ target.__send__(@name, attr, self.to_s)
124
+ end
119
125
 
120
126
  if @refiners.size > 0 && opf_version.to_f >= 3.0
121
127
  additional_attr['refines'] = "##{@attributes['id']}"
@@ -109,52 +109,6 @@ module GEPUB
109
109
  @oldstyle_meta = []
110
110
  end
111
111
 
112
- CONTENT_NODE_LIST = ['identifier', 'title', 'language', 'contributor', 'creator', 'coverage', 'date','description','format','publisher','relation','rights','source','subject','type'].each {
113
- |node|
114
- define_method(node + '_list') { @content_nodes[node].dup.sort_as_meta }
115
- define_method(node + '_clear') {
116
- if !@content_nodes[node].nil?
117
- @content_nodes[node].each { |x| unregister_meta(x) };
118
- @content_nodes[node] = []
119
- end
120
- }
121
-
122
- next if node == 'title'
123
-
124
- define_method(node, ->(content=UNASSIGNED, id=nil) {
125
- if unassigned?(content)
126
- get_first_node(node)
127
- else
128
- send(node + "_clear")
129
- add_metadata(node, content, id)
130
- end
131
- })
132
-
133
- define_method('set_' + node) {
134
- |content, id|
135
- warn "obsolete : set_#{node}. use #{node} instead."
136
- send(node + "_clear")
137
- add_metadata(node, content, id)
138
- }
139
-
140
- define_method(node+'=') {
141
- |content|
142
- send(node + "_clear")
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)
155
- }
156
- }
157
-
158
112
  def meta_list
159
113
  (@content_nodes['meta'] || []).sort_as_meta.dup
160
114
  end
@@ -170,7 +124,7 @@ module GEPUB
170
124
  title(content)
171
125
  end
172
126
 
173
- def title(content=UNASSIGNED, id = nil, title_type = nil)
127
+ def title(content=UNASSIGNED, id: nil, title_type: nil)
174
128
  if unassigned?(content)
175
129
  if !@content_nodes['title'].nil?
176
130
  @content_nodes['title'].each do
@@ -181,7 +135,7 @@ module GEPUB
181
135
  get_first_node('title')
182
136
  else
183
137
  title_clear
184
- meta = add_title(content, id, title_type)
138
+ meta = add_title(content, id: id, title_type: title_type)
185
139
  yield meta if block_given?
186
140
  meta
187
141
  end
@@ -197,13 +151,17 @@ module GEPUB
197
151
  def add_identifier(string, id=nil, type=nil)
198
152
  id = @id_pool.generate_key(:prefix => 'BookId') if id.nil?
199
153
  raise "id #{id} is already in use" if @id_pool[id]
200
- identifier = add_metadata('identifier', string, id)
154
+ identifier = add_metadata('identifier', string, id: id)
201
155
  identifier.refine('identifier-type', type) unless type.nil?
202
156
  identifier
203
157
  end
204
158
 
205
- def add_date(date, id)
206
- add_metadata('date', date, id, DateMeta)
159
+ def add_date(date, deprecated_id = nil, id: nil)
160
+ if deprecated_id
161
+ warn "secound argument is deprecated. use id: keyword argument"
162
+ id = deprecated_id
163
+ end
164
+ add_metadata('date', date, id: id, itemclass: DateMeta)
207
165
  end
208
166
 
209
167
  def identifier_by_id(id)
@@ -214,42 +172,9 @@ module GEPUB
214
172
  return nil
215
173
  end
216
174
 
217
- def add_metadata(name, content, id = nil, itemclass = Meta)
175
+ def add_metadata_internal(name, content, id: nil, itemclass: Meta)
218
176
  meta = itemclass.new(name, content, self, { 'id' => id })
219
177
  (@content_nodes[name] ||= []) << meta
220
- yield meta if block_given?
221
- meta
222
- end
223
-
224
- def add_title(content, id = nil, title_type = nil)
225
- meta = add_metadata('title', content, id).refine('title-type', title_type)
226
- yield meta if block_given?
227
- meta
228
- end
229
-
230
- def set_title(content, id = nil, title_type = nil)
231
- warn "obsolete : set_title. use title or title= instead."
232
- title_clear
233
- meta = add_title(content, id, title_type)
234
- yield meta if block_given?
235
- meta
236
- end
237
-
238
- def add_person(name, content, id = nil, role = nil)
239
- meta = add_metadata(name, content, id).refine('role', role)
240
- yield meta if block_given?
241
- meta
242
- end
243
-
244
- def add_creator(content, id = nil, role = 'aut')
245
- meta = add_person('creator', content, id, role)
246
- yield meta if block_given?
247
- meta
248
- end
249
-
250
- def add_contributor(content, id=nil, role=nil)
251
- meta = add_person('contributor', content, id, role)
252
- yield meta if block_given?
253
178
  meta
254
179
  end
255
180
 
@@ -268,7 +193,7 @@ module GEPUB
268
193
  @content_nodes['meta'].delete meta
269
194
  end
270
195
  }
271
- add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), nil, DateMeta)['property'] = 'dcterms:modified'
196
+ add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
272
197
  end
273
198
  end
274
199
 
@@ -289,7 +214,7 @@ module GEPUB
289
214
  @content_nodes['meta'].delete meta
290
215
  end
291
216
  }
292
- add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), nil, DateMeta)['property'] = 'dcterms:modified'
217
+ add_metadata('meta', date.utc.strftime('%Y-%m-%dT%H:%M:%SZ'), itemclass: DateMeta)['property'] = 'dcterms:modified'
293
218
  end
294
219
 
295
220
  def add_oldstyle_meta(content, attributes = {})
@@ -0,0 +1,142 @@
1
+ module GEPUB
2
+ class Metadata
3
+ CONTENT_NODE_LIST = ['identifier', 'title', 'language', 'contributor', 'creator', 'coverage', 'date','description','format','publisher','relation','rights','source','subject','type'].each {
4
+ |node|
5
+ define_method(node + '_list') { @content_nodes[node].dup.sort_as_meta }
6
+ define_method(node + '_clear') {
7
+ if !@content_nodes[node].nil?
8
+ @content_nodes[node].each { |x| unregister_meta(x) };
9
+ @content_nodes[node] = []
10
+ end
11
+ }
12
+
13
+ next if node == 'title'
14
+
15
+ define_method(node, ->(content=UNASSIGNED, deprecated_id=nil, id:nil,
16
+ title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
17
+ lang: nil, alternates: {}) {
18
+ if unassigned?(content)
19
+ get_first_node(node)
20
+ else
21
+ if deprecated_id
22
+ warn "secound argument is deprecated. use id: keyword argument"
23
+ id = deprecated_id
24
+ end
25
+ send(node + "_clear")
26
+ add_metadata(node, content, id: id, title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role, lang: lang, alternates: alternates)
27
+ end
28
+ })
29
+
30
+ define_method(node+'=') {
31
+ |content|
32
+ send(node + "_clear")
33
+ return if content.nil?
34
+ if node == 'date'
35
+ add_date(content)
36
+ else
37
+ add_metadata(node, content)
38
+ end
39
+ }
40
+
41
+ next if ["identifier", "date", "creator", "contributor"].include?(node)
42
+
43
+ define_method('add_' + node) {
44
+ |content, id|
45
+ add_metadata(node, content, id: id)
46
+ }
47
+ }
48
+
49
+ def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil,
50
+ title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
51
+ lang: nil, alternates: {})
52
+ if deprecated_id
53
+ warn 'second argument for add_title is deprecated. use id: instead'
54
+ id = deprecated_id
55
+ end
56
+ if deprecated_title_type
57
+ warn 'third argument for add_title is deprecated. use title_type: instead'
58
+ title_type = deprecated_title_type
59
+ end
60
+ meta = add_metadata('title', content, id: id,
61
+ title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
62
+ lang: lang, alternates: alternates)
63
+ yield meta if block_given?
64
+ meta
65
+ end
66
+
67
+ def add_person(name, content, deprecated_id = nil, deprecated_role = nil, id: nil,
68
+ title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
69
+ lang: nil, alternates: {})
70
+ if deprecated_id
71
+ warn 'second argument for add_person is deprecated. use id: instead'
72
+ id = deprecated_id
73
+ end
74
+ if deprecated_role
75
+ warn 'third argument for add_person is deprecated. use role: instead'
76
+ role = deprecated_role
77
+ end
78
+ meta = add_metadata(name, content, id: id,
79
+ title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
80
+ lang: lang, alternates: alternates)
81
+ yield meta if block_given?
82
+ meta
83
+ end
84
+
85
+ def add_creator(content, deprecated_id = nil, deprecated_role = nil, id: nil,
86
+ title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
87
+ lang: nil, alternates: {})
88
+ if deprecated_id
89
+ warn 'second argument for add_creator is deprecated. use id: instead'
90
+ id = deprecated_id
91
+ end
92
+ if deprecated_role
93
+ warn 'third argument for add_creator is deprecated. use role: instead'
94
+ role = deprecated_role
95
+ end
96
+ role = 'aut' if role.nil?
97
+ meta = add_person('creator', content, id: id,
98
+ title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
99
+ lang: lang, alternates: alternates)
100
+ yield meta if block_given?
101
+ meta
102
+ end
103
+
104
+ def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil,
105
+ title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
106
+ lang: nil, alternates: {})
107
+ if deprecated_id
108
+ warn 'second argument for add_contributor is deprecated. use id: instead'
109
+ id = deprecated_id
110
+ end
111
+ if deprecated_role
112
+ warn 'third argument for add_contributor is deprecated. use role: instead'
113
+ role = deprecated_role
114
+ end
115
+ meta = add_person('contributor', content, id: id,
116
+ title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
117
+ lang: lang, alternates: alternates)
118
+ yield meta if block_given?
119
+ meta
120
+ end
121
+
122
+ def add_metadata(name, content, id: nil, itemclass: Meta,
123
+ title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
124
+ lang: nil, alternates: {}
125
+ )
126
+ meta = add_metadata_internal(name, content, id: id, itemclass: itemclass)
127
+ [{ value: title_type, name: 'title-type'},{ value: identifier_type, name: 'identifier-type'},{ value: display_seq, name: 'display-seq'},{ value: file_as, name: 'file-as'},{ value: group_position, name: 'group-position'},{ value: role, name: 'role'}].each do |refiner|
128
+ if refiner[:value]
129
+ meta.refine(refiner[:name], refiner[:value])
130
+ end
131
+ end
132
+ if lang
133
+ meta.lang = lang
134
+ end
135
+ if alternates
136
+ meta.add_alternates alternates
137
+ end
138
+ yield meta if block_given?
139
+ meta
140
+ end
141
+ end
142
+ end
data/lib/gepub/package.rb CHANGED
@@ -168,9 +168,9 @@ module GEPUB
168
168
  @metadata.add_identifier identifier, unique_identifier, type
169
169
  end
170
170
 
171
- def add_item(href, io_or_filename = nil, id = nil, attributes = {})
171
+ def add_item(href, content:nil, id: nil, attributes: {})
172
172
  item = @manifest.add_item(id, href, nil, attributes)
173
- item.add_content(io_or_filename) unless io_or_filename.nil?
173
+ item.add_content(content) unless content.nil?
174
174
  @spine.push(item) if @ordered
175
175
  yield item if block_given?
176
176
  item
@@ -183,11 +183,10 @@ module GEPUB
183
183
  @ordered = nil
184
184
  end
185
185
 
186
- def add_ordered_item(href, io_or_filename = nil, id = nil, attributes = {})
186
+ def add_ordered_item(href, content:nil, id: nil, attributes: {})
187
187
  raise 'do not call add_ordered_item within ordered block.' if @ordered
188
- item = add_item(href, io_or_filename, id, attributes)
188
+ item = add_item(href, attributes: attributes, id:id, content: content)
189
189
  @spine.push(item)
190
-
191
190
  item
192
191
  end
193
192
 
@@ -208,7 +208,7 @@ module GEPUB
208
208
  io = val[1]
209
209
  end
210
210
  name = "#{@dir_prefix}/#{name}" if !@dir_prefix.nil? && @dir_prefix.size > 0 && !name.start_with?('http')
211
- @book.add_item(name, io)
211
+ @book.add_item(name, content: io)
212
212
  end
213
213
  end
214
214
 
data/lib/gepub/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module GEPUB
2
2
  # GEPUB gem version
3
- VERSION = "0.7.1"
3
+ VERSION = "1.0.0beta1"
4
4
  end
data/lib/gepub.rb CHANGED
@@ -5,6 +5,7 @@ require 'gepub/meta'
5
5
  require 'gepub/datemeta'
6
6
  require 'gepub/meta_array'
7
7
  require 'gepub/metadata'
8
+ require 'gepub/metadata_add'
8
9
  require 'gepub/manifest'
9
10
  require 'gepub/spine'
10
11
  require 'gepub/bindings'
@@ -12,6 +13,7 @@ require 'gepub/package'
12
13
  require 'gepub/mime'
13
14
  require 'gepub/item'
14
15
  require 'gepub/book'
16
+ require 'gepub/book_add_item'
15
17
  require 'gepub/builder_mixin'
16
18
  require 'gepub/resource_builder'
17
19
  require 'gepub/builder'