honyomi 1.4.0 → 1.5.0

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
  SHA1:
3
- metadata.gz: 685d64724a342464a595155d65a219387bfb707e
4
- data.tar.gz: baa05b5545b476237f482499d90f8f2fc7334d52
3
+ metadata.gz: 1c366948a12642cc9db95eaeb5c113ad48c5e13c
4
+ data.tar.gz: aa52ce3db3f3d67defa7c0a1ac2777e4043291bc
5
5
  SHA512:
6
- metadata.gz: c469791cfe13da613deafd5eeadc10f4b7855d92c1b95823e58cdd626ba69cab932e27c81bf0a63d3ef819b4328021267cdd928f61e1d307f8029ee95cf7882d
7
- data.tar.gz: 4a7440312e418348b4a36e335252369d63fd4d8fe70c6e39182086a6efd0a9156c8c7daded9aa9588461b9f2029a94f12060261934a90bf540d44358c3b36631
6
+ metadata.gz: 556d3960472a3c09adfea1e639a85bfbbb0bfc660560441d53461df47c282141a0675d7993a8d24946a88c3604cf78b6c19b443f5f7d55cf8c3ce722fe81f362
7
+ data.tar.gz: 61854babf0c1ca43a19f55551f413b6278cb7957a3f82c791f7c2172b40f89b4f3bd1eadc9f11cf5e809479de3994c4b23aab2e877c17a7159412e7c432c5675
data/HISTORY.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # HISTORY - Honyomi
2
2
 
3
+ ## 1.5 - 2015-11-21
4
+
5
+ - Display as thumbnails
6
+ - Bookmark
7
+ - Search Result
8
+ - Manage books from the web app
9
+ - Remove book
10
+ - Add/Delete image
11
+ - Improve honyomi commands
12
+ - Fix page parse bug of 'honyomi add'
13
+ - Add "honyomi add --no-image" option
14
+ - Add 'honyomi image -d' options
15
+ - Delete image with 'honyomi remove'
16
+ - Exit with 1 on error
17
+
3
18
  ## 1.4 - 2015-08-05
4
19
 
5
20
  - Add basic authorization
data/README.md CHANGED
@@ -1,18 +1,23 @@
1
1
  # Honyomi
2
2
 
3
- Honyomi is ebook (pdf) search engine written by Ruby. It have command line interface and web application. It will accelerate the ebook of your life.
3
+ ![honyomi-incon](images/honyomi-icon.png)
4
4
 
5
- Honyomi is "本読み". "Read a book" is meaning.
5
+ Honyomi is pdf search engine written by Ruby. It have command line interface and web application. It will accelerate the ebook of your life.
6
6
 
7
- [Milkode](https://github.com/ongaeshi/milkode) are brothers.
7
+ You can [search](http://library.honyomi.nagoya/?query=global-set-key) and [browse](http://library.honyomi.nagoya/v/2) the pdf document only in the browser.
8
8
 
9
- ![honyomi-01.png](images/honyomi-01.png)
9
+ Honyomi is "本読み". "Read a book" is meaning. [Milkode](https://github.com/ongaeshi/milkode) are brothers.
10
+
11
+ - [English](#installation)
12
+ - [日本語](http://honyomi.nagoya/ja/)
13
+
14
+ ![honyomi-03.gif](images/honyomi-03.gif)
10
15
 
11
16
  ## Installation
12
17
 
13
- You can use the Docker container.
18
+ You can use the Docker container. With [Kitematic](https://kitematic.com/) it is very easy! For more information and a look at the video above.
14
19
 
15
- - [ongaeshi/honyomi Repository | Docker Hub Registry](https://registry.hub.docker.com/u/ongaeshi/honyomi/)
20
+ - [ongaeshi/docker-honyomi](https://github.com/ongaeshi/docker-honyomi)
16
21
 
17
22
  or
18
23
 
@@ -108,7 +113,7 @@ aaa <<bbb>> ccc
108
113
  $ honyomi web
109
114
  ```
110
115
 
111
- ![honyomi-03.gif](images/honyomi-03.gif)
116
+ ![honyomi-01.png](images/honyomi-01.png)
112
117
 
113
118
  ### Basic authorization
114
119
 
@@ -125,5 +130,14 @@ a6a27374ec8f49426e8ee6249125369e8c529f361ffa20ace73de0b92514bb0f
125
130
  $ HONYOMI_AUTH_USERNAME=ongaeshi HONYOMI_AUTH_PASSWORD=a6a27374ec8f49426e8ee6249125369e8c529f361ffa20ace73de0b92514bb0f honyomi web
126
131
  ```
127
132
 
133
+ ## Demo
134
+
135
+ - [library of honyomi](http://library.honyomi.nagoya/)
136
+
137
+ ## Credit
138
+
139
+ - Beyond Interaction http://www.bnn.co.jp/books/3746/ CC-BY-NC-SA
140
+
141
+
128
142
 
129
143
 
@@ -3,6 +3,10 @@ require 'thor'
3
3
 
4
4
  module Honyomi
5
5
  class CLI < Thor
6
+ def self.exit_on_failure?
7
+ true
8
+ end
9
+
6
10
  class_option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message'
7
11
 
8
12
  desc "init", "Create database in ENV['HONYOMI_DATABASE_DIR'] or '~/.honyomi'"
@@ -19,6 +23,7 @@ module Honyomi
19
23
  desc "add file1 [file2 ...]", "Add pdf files"
20
24
  option :title, :aliases => '-t', :type => :string, :desc => 'Specify title'
21
25
  option :strip, :type => :boolean, :desc => 'Remove spaces'
26
+ option :image, :type => :boolean, :desc => "Generate image (Default true)"
22
27
  def add(*args)
23
28
  core = Core.new
24
29
  core.load_database
@@ -131,12 +136,13 @@ module Honyomi
131
136
  end
132
137
 
133
138
  desc "image book_id1 [book_id2 ...]", "Generate page images (Need pdftoppm)"
139
+ option :delete, :type => :boolean, :aliases => '-d', :desc => 'Delete image'
134
140
  def image(*args)
135
141
  core = Core.new
136
142
  core.load_database
137
143
 
138
144
  args.each do |id|
139
- core.image(id.to_i, { verbose: true })
145
+ core.image(id.to_i, { verbose: true, delete: options[:delete] })
140
146
  end
141
147
  end
142
148
 
@@ -14,16 +14,16 @@ module Honyomi
14
14
  def init_database
15
15
  FileUtils.mkdir_p(db_dir)
16
16
  Groonga::Database.create(path: db_path)
17
- @database = Database.new
17
+ @database = Database.new(home_dir)
18
18
  end
19
19
 
20
20
  def load_database
21
21
  Groonga::Database.open(db_path)
22
- @database = Database.new
22
+ @database = Database.new(home_dir)
23
23
  end
24
24
 
25
25
  def add(filename, options = {})
26
- book, status = @database.add_from_pdf(filename, home_dir, options)
26
+ book, status = @database.add_from_pdf(filename, options)
27
27
 
28
28
  return book, status
29
29
  end
@@ -123,8 +123,29 @@ EOF
123
123
  end
124
124
 
125
125
  def image(id, options = {})
126
- output_dir = @database.add_image(id, home_dir)
127
- puts "Generated images to '#{output_dir}'" if options[:verbose]
126
+ output_dir = @database.image_dir(id)
127
+
128
+ unless options[:delete]
129
+ if options[:verbose]
130
+ unless File.exist?(output_dir)
131
+ puts "Generate images to '#{output_dir}'"
132
+ else
133
+ puts "Regenerate images to '#{output_dir}'"
134
+ end
135
+ end
136
+
137
+ @database.add_image(id)
138
+ else
139
+ if options[:verbose]
140
+ if File.exist?(output_dir)
141
+ puts "Delete images from '#{output_dir}'"
142
+ else
143
+ puts "Already deleted '#{output_dir}'"
144
+ end
145
+ end
146
+
147
+ @database.delete_image(id)
148
+ end
128
149
  end
129
150
 
130
151
  def move(old_path, new_path)
@@ -6,11 +6,14 @@ module Honyomi
6
6
  class HonyomiError < Exception ; end
7
7
 
8
8
  class Database
9
+ attr_reader :home_dir
9
10
  attr_reader :books
10
11
  attr_reader :pages
11
12
  attr_reader :bookmarks
12
13
 
13
- def initialize
14
+ def initialize(home_dir)
15
+ @home_dir = home_dir
16
+
14
17
  @books = GrnMini::Array.new("Books")
15
18
  @pages = GrnMini::Hash.new("Pages")
16
19
  @bookmarks = GrnMini::Hash.new("Bookmarks")
@@ -33,7 +36,7 @@ module Honyomi
33
36
  )
34
37
  end
35
38
 
36
- def add_from_pdf(filename, home_dir, options = {})
39
+ def add_from_pdf(filename, options = {})
37
40
  if File.exist?(filename)
38
41
  filename = File.expand_path(filename)
39
42
  options = options.dup
@@ -42,7 +45,8 @@ module Honyomi
42
45
  options[:timestamp] = File.stat(filename).mtime
43
46
  book, status = add_book(filename, pages, options)
44
47
 
45
- add_image(book.id, home_dir) if Util.exist_command?('pdftoppm')
48
+ options[:image] = true if options[:image].nil? # Default true
49
+ add_image(book.id) if Util.exist_command?('pdftoppm') && options[:image]
46
50
 
47
51
  return book, status
48
52
  else
@@ -50,13 +54,17 @@ module Honyomi
50
54
  end
51
55
  end
52
56
 
53
- def add_image(id, home_dir)
54
- output_dir = File.join(home_dir, "image", id.to_s)
57
+ def image_dir(id)
58
+ File.join(home_dir, "image", id.to_s)
59
+ end
55
60
 
61
+ def add_image(id)
56
62
  pdf = Pdf.new(books[id].path)
57
- pdf.generate_images(output_dir)
63
+ pdf.generate_images(image_dir(id))
64
+ end
58
65
 
59
- output_dir
66
+ def delete_image(id)
67
+ FileUtils.remove_entry_secure(image_dir(id), true)
60
68
  end
61
69
 
62
70
  def add_book(path, pages, options = {})
@@ -116,6 +124,9 @@ module Honyomi
116
124
  end
117
125
 
118
126
  def delete_book(book_id)
127
+ # path = @books[book_id].path
128
+
129
+ # Delete book
119
130
  book = @books[book_id]
120
131
 
121
132
  @pages.delete do |page|
@@ -123,6 +134,12 @@ module Honyomi
123
134
  end
124
135
 
125
136
  book.delete
137
+
138
+ # Delete iamges
139
+ delete_image(book_id)
140
+
141
+ # Delete file (if ~/.honyomi/book)
142
+ # FileUtils.rm(path) if path.index(home_dir) == 0
126
143
  end
127
144
 
128
145
  def search(query, options = {})
@@ -151,6 +168,10 @@ module Honyomi
151
168
  @pages.select("book._id:\"#{book_id}\"").sort(["page_no"])
152
169
  end
153
170
 
171
+ def book_page(book, page_no)
172
+ @pages["#{book.id}:#{page_no}"]
173
+ end
174
+
154
175
  def book_from_path(path)
155
176
  r = @books.select("path:\"#{path}\"").first
156
177
 
@@ -2,6 +2,8 @@
2
2
  require 'honyomi'
3
3
  require 'tmpdir'
4
4
  require 'fileutils'
5
+ require "open3"
6
+ require "shellwords"
5
7
 
6
8
  module Honyomi
7
9
  class Pdf
@@ -10,16 +12,28 @@ module Honyomi
10
12
  end
11
13
 
12
14
  def pages
15
+ result = []
16
+
13
17
  Dir.mktmpdir do |dir|
14
18
  outfile = File.join(dir, "pdf.txt")
15
- system("pdftotext", @filename, outfile) # Need pdftotext (poppler, xpdf)
16
- @text = File.read(outfile, encoding: Encoding::UTF_8)
17
- if String.method_defined? :scrub
18
- @text = @text.scrub('?')
19
+
20
+ loop do
21
+ page_no = (result.count + 1).to_s
22
+
23
+ o, e, s = Open3.capture3("pdftotext -f #{page_no} -l #{page_no} #{Shellwords.escape(@filename)} #{Shellwords.escape(outfile)}") # Need pdftotext (poppler, xpdf)
24
+ break if s.exitstatus != 0
25
+
26
+ text = File.read(outfile, encoding: Encoding::UTF_8)
27
+
28
+ if String.method_defined? :scrub
29
+ text = text.scrub('?')
30
+ end
31
+
32
+ result << text
19
33
  end
20
34
  end
21
35
 
22
- @text.split("\f")
36
+ result
23
37
  end
24
38
 
25
39
  def generate_images(output_dir)
@@ -1,3 +1,3 @@
1
1
  module Honyomi
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -26,7 +26,7 @@ configure do
26
26
  end
27
27
  end
28
28
 
29
- $database = Database.new
29
+ $database = Database.new(Util.home_dir)
30
30
  end
31
31
 
32
32
  get '/' do
@@ -64,7 +64,7 @@ post '/upload' do
64
64
  f.write file[:tempfile].read
65
65
  end
66
66
 
67
- @database.add_from_pdf(save_path, Util.home_dir)
67
+ @database.add_from_pdf(save_path)
68
68
  end
69
69
 
70
70
  @message = "Upload Success"
@@ -148,6 +148,12 @@ post '/command' do
148
148
  url: params[:url],
149
149
  })
150
150
  ""
151
+ when 'add-image'
152
+ @database.add_image(params[:id].to_i)
153
+ when 'delete-image'
154
+ @database.delete_image(params[:id].to_i)
155
+ when 'remove-book'
156
+ @database.delete_book(params[:id].to_i)
151
157
  end
152
158
  end
153
159
 
@@ -304,7 +310,7 @@ EOF
304
310
  image_path = Util.image_path(page)
305
311
 
306
312
  if File.exist? image_path
307
- main_contents += %|<div><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="100%"/></div>|
313
+ main_contents += %|<div><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="250px"/></div>|
308
314
  end
309
315
 
310
316
  <<EOF
@@ -375,7 +381,7 @@ EOF
375
381
  content = r.map { |e| "<p>#{escape_html(e)}</p>" }.join("\n")
376
382
 
377
383
  if has_image
378
- content += %|<p><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="100%"/></p>|
384
+ content += %|<p><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="250px"/></p>|
379
385
  end
380
386
 
381
387
  <<EOF
@@ -414,10 +420,12 @@ EOF
414
420
 
415
421
  def header_title_book(book, query)
416
422
  query = query ? "?query=#{query}" : ""
423
+ first_page = @database.book_page(book, 1)
424
+ has_image = File.exist?(Util.image_path(first_page))
417
425
 
418
426
  <<EOF
419
427
  <div class="title">
420
- <a href='/#{query}'>HOME</a> &gt; <a href='/v/#{book.id}#{query}' id="book-title" honyomi-book-id="#{book.id}">#{escape_html(book.title)}</a> <span class='edit-link'>- <a href="#">Edit</a></span>
428
+ <a href='/#{query}'>HOME</a> &gt; <a href='/v/#{book.id}#{query}' id="book-title" honyomi-book-id="#{book.id}" honyomi-book-image="#{has_image ? "1" : "0"}">#{escape_html(book.title)}</a> <span class='edit-link'>- <a href="#">Edit</a></span>
421
429
  </div>
422
430
  <div class="etc">
423
431
  <span id="book-author">#{escape_html(book.author)}</span>
@@ -23,6 +23,14 @@
23
23
  margin: 10px 0px 0px 5px;
24
24
  }
25
25
 
26
+ .header .operation-button {
27
+ margin: 0px 0px 40px 0px;
28
+ }
29
+
30
+ .remove-button {
31
+ margin: 0px 0px 0px 15px;
32
+ }
33
+
26
34
  /* content */
27
35
  .content {
28
36
  margin: 10px 0px 0px 5px;
@@ -165,6 +165,44 @@ $(document).ready(function() {
165
165
  hideTitleForm();
166
166
  });
167
167
 
168
+ $(".operation-button .image-button").click(function (e) {
169
+ var id = $("#book-title").attr('honyomi-book-id');
170
+ var title = $("#title-form-title").val();
171
+ var isExist = $("#book-title").attr('honyomi-book-image') == '1';
172
+ var msg = !isExist ? "Generate" : "Delete";
173
+ var kind = !isExist ? "add-image" : "delete-image";
174
+
175
+ if (confirm(msg + " '" + title + "'" + " of page images?")) {
176
+ $.post(
177
+ '/command',
178
+ {
179
+ kind: kind,
180
+ id: id
181
+ }
182
+ );
183
+
184
+ hideTitleForm();
185
+ }
186
+ });
187
+
188
+ $(".operation-button .remove-button").click(function (e) {
189
+ var id = $("#book-title").attr('honyomi-book-id');
190
+ var title = $("#title-form-title").val();
191
+
192
+ if (confirm("Remove '" + title + "'" + "?") &&
193
+ confirm("Are you sure?")) {
194
+ $.post(
195
+ '/command',
196
+ {
197
+ kind: "remove-book",
198
+ id: id
199
+ }
200
+ );
201
+
202
+ document.location = "/";
203
+ }
204
+ });
205
+
168
206
  $(function() {
169
207
  document.addEventListener("dragover", function(e) {
170
208
  e.preventDefault();
@@ -8,6 +8,14 @@
8
8
  = @header_title
9
9
 
10
10
  .title-form.hide
11
+ %div.operation-button
12
+ %span.image-button
13
+ %a(class="btn btn-warning" href="#" role="button")
14
+ Image
15
+ %span.remove-button
16
+ .pull-right
17
+ %a(class="btn btn-danger" href="#" role="button")
18
+ Remove
11
19
  %form.form-horizontal(role="form")
12
20
  .form-group
13
21
  %label.col-sm-1.control-label(for="title-form-title")
@@ -77,12 +77,12 @@ module Honyomi
77
77
  core.init_database
78
78
 
79
79
  core.add(datafile("test2.pdf"))
80
- assert_equal "aaa bbb ccc", core.database.pages["1:1"].text.sub(/\n+\Z/, "")
81
- assert_equal "dd ee", core.database.pages["1:2"].text.sub(/\n+\Z/, "")
80
+ assert_equal "aaa bbb ccc", core.database.pages["1:1"].text.sub(/\n*\f*\Z/, "")
81
+ assert_equal "dd ee", core.database.pages["1:2"].text.sub(/\n*\f*\Z/, "")
82
82
 
83
83
  core.add(datafile("test2.pdf"), strip: true)
84
- assert_equal "aaabbbccc", core.database.pages["1:1"].text.sub(/\n+\Z/, "")
85
- assert_equal "ddee", core.database.pages["1:2"].text.sub(/\n+\Z/, "")
84
+ assert_equal "aaabbbccc", core.database.pages["1:1"].text.sub(/\n*\f*\Z/, "")
85
+ assert_equal "ddee", core.database.pages["1:2"].text.sub(/\n*\f*\Z/, "")
86
86
  end
87
87
  end
88
88
 
@@ -110,7 +110,7 @@ module Honyomi
110
110
  assert_equal "ttt", core.database.books[1].title
111
111
 
112
112
  core.edit(1, strip: true)
113
- assert_equal "aaabbbccc", core.database.pages["1:1"].text.sub(/\n+\Z/, "")
113
+ assert_equal "aaabbbccc", core.database.pages["1:1"].text.sub(/\n*\f*\Z/, "")
114
114
 
115
115
  assert_equal datafile("test2.pdf"), core.database.books[1].path
116
116
  core.edit(1, path: datafile("test.pdf"))
@@ -170,6 +170,30 @@ module Honyomi
170
170
  end
171
171
  end
172
172
 
173
+ def test_image
174
+ Dir.mktmpdir do |dir|
175
+ core = Core.new({home_dir: dir})
176
+ core.init_database
177
+
178
+ book, _ = core.add(datafile("test.pdf"), title: "TEST PDF")
179
+
180
+ image_dir = File.join(dir, "image", book.id.to_s)
181
+ assert File.exist?(File.join(image_dir, "book-1.jpg"))
182
+ assert File.exist?(File.join(image_dir, "book-2.jpg"))
183
+ assert File.exist?(File.join(image_dir, "book-3.jpg"))
184
+
185
+ core.image(book.id, {delete: true})
186
+ assert !File.exist?(File.join(image_dir, "book-1.jpg"))
187
+ assert !File.exist?(File.join(image_dir, "book-2.jpg"))
188
+ assert !File.exist?(File.join(image_dir, "book-3.jpg"))
189
+
190
+ core.image(book.id)
191
+ assert File.exist?(File.join(image_dir, "book-1.jpg"))
192
+ assert File.exist?(File.join(image_dir, "book-2.jpg"))
193
+ assert File.exist?(File.join(image_dir, "book-3.jpg"))
194
+ end
195
+ end
196
+
173
197
  private
174
198
 
175
199
  def datafile(path)
@@ -3,13 +3,13 @@ require 'minitest_helper'
3
3
  class TestDatabase < MiniTest::Test
4
4
  def test_open
5
5
  GrnMini::tmpdb do
6
- db = Honyomi::Database.new
6
+ db = Honyomi::Database.new(nil)
7
7
  end
8
8
  end
9
9
 
10
10
  def test_add_book
11
11
  GrnMini::tmpdb do
12
- db = Honyomi::Database.new
12
+ db = Honyomi::Database.new(nil)
13
13
 
14
14
  db.add_book("/path/to/book1.pdf", ["1aa"], title: "Book1")
15
15
  db.add_book("/path/to/book2.pdf", ["2aa", "2bb"], title: "Book2")
@@ -45,7 +45,7 @@ class TestDatabase < MiniTest::Test
45
45
 
46
46
  def test_add_book_title_default
47
47
  GrnMini::tmpdb do
48
- db = Honyomi::Database.new
48
+ db = Honyomi::Database.new(nil)
49
49
 
50
50
  db.add_book("/path/to/book1.pdf", ["1aa"])
51
51
  assert_equal "book1", db.books[1].title
@@ -54,7 +54,7 @@ class TestDatabase < MiniTest::Test
54
54
 
55
55
  def test_add_book_same_path
56
56
  GrnMini::tmpdb do
57
- db = Honyomi::Database.new
57
+ db = Honyomi::Database.new(nil)
58
58
 
59
59
  db.add_book("/path/to/book1.pdf", ["1aa"], title: "Book1")
60
60
  db.add_book("/path/to/book2.pdf", ["2aa", "2bb"], title: "Book2")
@@ -70,7 +70,7 @@ class TestDatabase < MiniTest::Test
70
70
 
71
71
  def test_change_book
72
72
  GrnMini::tmpdb do
73
- db = Honyomi::Database.new
73
+ db = Honyomi::Database.new(nil)
74
74
 
75
75
  db.add_book("/path/to/book1.pdf", ["1aa"], title: "Book1")
76
76
  db.add_book("/path/to/book2.pdf", ["2aa", "2bb"], title: "Book2")
@@ -92,8 +92,11 @@ class TestDatabase < MiniTest::Test
92
92
  end
93
93
 
94
94
  def test_delete_book
95
- GrnMini::tmpdb do
96
- db = Honyomi::Database.new
95
+ Dir.mktmpdir do |dir|
96
+ core = Honyomi::Core.new({home_dir: dir})
97
+ core.init_database
98
+
99
+ db = core.database
97
100
 
98
101
  db.add_book("/path/to/book1.pdf", ["1aa"], title: "Book1")
99
102
  db.add_book("/path/to/book2.pdf", ["2aa", "2bb"], title: "Book2")
@@ -108,7 +111,7 @@ class TestDatabase < MiniTest::Test
108
111
 
109
112
  def test_search
110
113
  GrnMini::tmpdb do
111
- db = Honyomi::Database.new
114
+ db = Honyomi::Database.new(nil)
112
115
  db.add_book("/path/to/book1.pdf", ["1aa"])
113
116
  db.add_book("/path/to/book2.pdf", ["2aa", "2bb"])
114
117
  db.add_book("/path/to/book3.pdf", ["3aa", "3bb", "3cc"])
@@ -126,7 +129,7 @@ class TestDatabase < MiniTest::Test
126
129
 
127
130
  def test_book_pages
128
131
  GrnMini::tmpdb do
129
- db = Honyomi::Database.new
132
+ db = Honyomi::Database.new(nil)
130
133
  db.add_book("/path/to/book1.pdf", ["1aa"])
131
134
  db.add_book("/path/to/book2.pdf", ["2aa", "2bb"])
132
135
  db.add_book("/path/to/book3.pdf", ["3aa", "3bb", "3cc"])
@@ -137,4 +140,20 @@ class TestDatabase < MiniTest::Test
137
140
  assert_equal 0, db.book_pages(4).size # Not found
138
141
  end
139
142
  end
143
+
144
+
145
+ def test_book_page
146
+ GrnMini::tmpdb do
147
+ db = Honyomi::Database.new(nil)
148
+ db.add_book("/path/to/book1.pdf", ["1aa"])
149
+ db.add_book("/path/to/book2.pdf", ["2aa", "2bb"])
150
+ db.add_book("/path/to/book3.pdf", ["3aa", "3bb", "3cc"])
151
+
152
+ book = db.books[2]
153
+ assert_equal 1, db.book_page(book, 1).page_no
154
+ assert_equal "2aa", db.book_page(book, 1).text
155
+ assert_equal 2, db.book_page(book, 2).page_no
156
+ assert_equal nil, db.book_page(book, 3)
157
+ end
158
+ end
140
159
  end
@@ -9,9 +9,9 @@ class TestPdf < MiniTest::Test
9
9
  pdf = Honyomi::Pdf.new(test_pdf)
10
10
 
11
11
  assert_equal 3, pdf.pages.size
12
- assert_equal "aaa\n\n", pdf.pages[0]
13
- assert_equal "bbb\n\n", pdf.pages[1]
14
- assert_equal "ccc\n\n", pdf.pages[2]
12
+ assert_equal "aaa\n\n\f", pdf.pages[0]
13
+ assert_equal "bbb\n\n\f", pdf.pages[1]
14
+ assert_equal "ccc\n\n\f", pdf.pages[2]
15
15
  end
16
16
 
17
17
  def test_file_name_includes_special_characters
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honyomi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ongaeshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2015-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grn_mini