gepub 1.0.0beta1 → 1.0.0rc1

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: b309e48823e6ba81b9ec3d9082cb3be3e0f0198352ad439ba422234a0ab905f2
4
- data.tar.gz: 2558196c081bd7cd71d70c912213820879b1f5d6df3ad96b6b39899d23213a14
3
+ metadata.gz: 6ea54f631081444844a163f58cb499a6dd92e32a310f80fa957a2fd8344126e0
4
+ data.tar.gz: 677cf3da9d50aea36764d24f55e3ba3d30ff4caef08b7f722807b181d839dbcd
5
5
  SHA512:
6
- metadata.gz: 3ac54805a6b2582cbefa12655fd0c7d27801f16608c70b9355b81b6d6e623ffe0b94ed3f95a4bc4acc58b69d09476551a43d9f3926c42f0d59c1fc80cdea3ec9
7
- data.tar.gz: d05593c50c03ae43a6a644b7a7ac2c2a9239025f35cfc09adb2dbb61729633ec5456d426cf1bd4e83624dd14d04e9b5a3cfb2d93d7eac43ce16a7acddd7d5e45
6
+ metadata.gz: 2c9858b1ce776c22fabe0dec16f44bd5c5c228cec894c876439c4a66abd617ef718731f5ff960820c634f8e48d8185cf2fa26b309a8f7d637fe18be3190992ac
7
+ data.tar.gz: ee051d198cfe11f1a824b3a8aefb03cf7046fae837429d6820fe633eb178aa54a43172532840c3c87a14ede39b2e0315191976c12bed3d358d4ca25422c82fb0
data/lib/gepub/book.rb CHANGED
@@ -124,6 +124,7 @@ module GEPUB
124
124
  end
125
125
  @package = Package.new(path, attributes)
126
126
  @toc = []
127
+ @landmarks = []
127
128
  if block
128
129
  block.arity < 1 ? instance_eval(&block) : block[self]
129
130
  end
@@ -148,22 +149,17 @@ module GEPUB
148
149
  def set_singleton_methods_to_item(item)
149
150
  toc = @toc
150
151
  metaclass = (class << item;self;end)
151
- metaclass.send(:define_method, :toc_text,
152
- Proc.new { |text|
153
- toc.push(:item => item, :text => text, :id => nil)
154
- item
155
- })
156
- metaclass.send(:define_method, :toc_text_with_id,
157
- Proc.new { |text, id|
158
- toc.push(:item => item, :text => text, :id => id)
159
- item
160
- })
152
+ metaclass.send(:define_method, :toc, Proc.new {
153
+ toc
154
+ })
155
+ landmarks = @landmarks
156
+ metaclass.send(:define_method, :landmarks, Proc.new {
157
+ landmarks
158
+ })
161
159
  bindings = @package.bindings
162
- metaclass.send(:define_method, :is_handler_of,
163
- Proc.new { |media_type|
164
- bindings.add(item.id, media_type)
165
- item
166
- })
160
+ metaclass.send(:define_method, :bindings, Proc.new {
161
+ bindings
162
+ })
167
163
 
168
164
  end
169
165
 
@@ -301,6 +297,19 @@ EOF
301
297
  }
302
298
  }
303
299
  end
300
+ def write_landmarks xml_doc, landmarks
301
+ xml_doc.ol {
302
+ landmarks.each {
303
+ |landmark|
304
+ id = landmark[:id].nil? ? "" : "##{x[:id]}"
305
+ landmark_title = landmark[:title]
306
+ type = landmark[:type]
307
+ xml_doc.li {
308
+ xml_doc.a({'href' => landmark[:item].href + id, 'epub:type' => landmark[:type]}, landmark_title)
309
+ }
310
+ }
311
+ }
312
+ end
304
313
  # build nav
305
314
  builder = Nokogiri::XML::Builder.new {
306
315
  |doc|
@@ -311,6 +320,9 @@ EOF
311
320
  doc.h1 "#{title}"
312
321
  write_toc(doc, stacked_toc[:tocs])
313
322
  }
323
+ doc.nav('epub:type' => 'landmarks', 'id' => 'landmarks') {
324
+ write_landmarks(doc, @landmarks)
325
+ }
314
326
  }
315
327
  }
316
328
  }
data/lib/gepub/item.rb CHANGED
@@ -71,6 +71,29 @@ module GEPUB
71
71
  add_property('nav')
72
72
  end
73
73
 
74
+ # set toc text to the item
75
+ def toc_text text
76
+ toc.push(:item => self, :text => text, :id => nil)
77
+ self
78
+ end
79
+
80
+ # set toc text with id to the item
81
+ def toc_text_with_id text, toc_id
82
+ toc.push(:item => self, :text => text, :id => toc_id)
83
+ self
84
+ end
85
+
86
+ # set bindings: item is a handler for media_type
87
+ def is_handler_of media_type
88
+ bindings.add(self.id, media_type)
89
+ self
90
+ end
91
+
92
+ def landmark(type:, title:, id: nil)
93
+ landmarks.push(:type => type, :title => title, :item => self, :id => id)
94
+ self
95
+ end
96
+
74
97
  # guess and set content property from contents.
75
98
  def guess_content_property
76
99
  if File.extname(self.href) =~ /.x?html/ && @attributes['media-type'] === 'application/xhtml+xml'
data/lib/gepub/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module GEPUB
2
2
  # GEPUB gem version
3
- VERSION = "1.0.0beta1"
3
+ VERSION = "1.0.0rc1"
4
4
  end
data/spec/example_spec.rb CHANGED
@@ -128,5 +128,65 @@ describe 'GEPUB usage' do
128
128
  book.generate_epub(epubname)
129
129
  epubcheck(epubname)
130
130
  end
131
+
132
+ it 'should generate simple EPUB3 with landmarks' do
133
+ book = GEPUB::Book.new
134
+ book.primary_identifier('http:/example.jp/bookid_in_url', 'BookID', 'URL')
135
+ book.language = 'ja'
136
+
137
+ # you can add metadata and its property using block
138
+ book.add_title('GEPUBサンプル文書', title_type: GEPUB::TITLE_TYPE::MAIN) {
139
+ |title|
140
+ title.lang = 'ja'
141
+ title.file_as = 'GEPUB Sample Book'
142
+ title.display_seq = 1
143
+ title.add_alternates(
144
+ 'en' => 'GEPUB Sample Book (Japanese)',
145
+ 'el' => 'GEPUB δείγμα (Ιαπωνικά)',
146
+ 'th' => 'GEPUB ตัวอย่าง (ญี่ปุ่น)')
147
+ }
148
+ # you can do the same thing using method chain
149
+ book.add_title('これはあくまでサンプルです',title_type: GEPUB::TITLE_TYPE::SUBTITLE).display_seq(2).add_alternates('en' => 'this book is just a sample.')
150
+ book.add_creator('小嶋智') {
151
+ |creator|
152
+ creator.display_seq = 1
153
+ creator.add_alternates('en' => 'KOJIMA Satoshi')
154
+ }
155
+ book.add_contributor('電書部', display_seq: 1, alternates: {'en' => 'Denshobu'})
156
+ book.add_contributor('アサガヤデンショ', display_seq: 2, alternates: { 'en' => 'Asagaya Densho' })
157
+ book.add_contributor('湘南電書鼎談').display_seq(3).add_alternates('en' => 'Shonan Densho Teidan')
158
+ book.add_contributor('電子雑誌トルタル').display_seq(4).add_alternates('en' => 'eMagazine Torutaru')
159
+
160
+ imgfile = File.join(File.dirname(__FILE__), 'fixtures', 'testdata', 'image1.jpg')
161
+ book.add_item('img/image1.jpg',content: imgfile).cover_image
162
+
163
+ # within ordered block, add_item will be added to spine.
164
+ book.ordered {
165
+ book.add_item('text/cover.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>cover</title></head><body><h1>the book title</h1><img src="../img/image1.jpg" /></body></html>')).landmark(type: 'cover', title: '表紙')
166
+ book.add_item('text/chap1.xhtml').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>')).toc_text('Chapter 1').landmark(type: 'bodymatter', title: '本文')
167
+ book.add_item('text/chap1-1.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>the second page</p></body></html>')) # do not appear on table of contents
168
+ book.add_item('text/chap2.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c3</title></head><body><p>the third page</p></body></html>')).toc_text('Chapter 2')
169
+ }
170
+ epubname = File.join(File.dirname(__FILE__), 'example_test.epub')
171
+
172
+ # check nav doc
173
+ xml = Nokogiri::XML::Document.parse book.nav_doc
174
+
175
+ # check toc
176
+ tocs = xml.xpath("//xmlns:nav[@epub:type='toc']/xmlns:ol/xmlns:li")
177
+ expect(tocs.size).to eq 2
178
+ expect(tocs[0].content.strip).to eq 'Chapter 1'
179
+ expect(tocs[1].content.strip).to eq 'Chapter 2'
180
+
181
+ # check landmarks
182
+ landmarks = xml.xpath("//xmlns:nav[@epub:type='landmarks']/xmlns:ol/xmlns:li/xmlns:a")
183
+ expect(landmarks.size).to eq 2
184
+ expect(landmarks[0]['epub:type']).to eq 'cover'
185
+ expect(landmarks[0]['href']).to eq 'text/cover.xhtml'
186
+ expect(landmarks[1]['epub:type']).to eq 'bodymatter'
187
+ expect(landmarks[1]['href']).to eq 'text/chap1.xhtml'
188
+ book.generate_epub(epubname)
189
+ epubcheck(epubname)
190
+ end
131
191
  end
132
192
  end
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: 1.0.0beta1
4
+ version: 1.0.0rc1
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-10-24 00:00:00.000000000 Z
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri