honyomi 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +16 -0
- data/lib/honyomi/cli.rb +11 -1
- data/lib/honyomi/core.rb +11 -0
- data/lib/honyomi/pdf.rb +10 -3
- data/lib/honyomi/util.rb +9 -0
- data/lib/honyomi/version.rb +1 -1
- data/lib/honyomi/web/app.rb +49 -12
- data/lib/honyomi/web/public/css/honyomi.css +5 -0
- data/lib/honyomi/web/public/js/honyomi.js +12 -0
- data/test/test_pdf.rb +11 -0
- data/test/test_util.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f785777fac05f71e8de95f2a030a5da69b791a4d
|
4
|
+
data.tar.gz: fbe61872b4dff870f4699de33df9a1278fbaa8e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfbec7c05b178b935ae27189c276382b9f7f67e1f46cf519609cb1b47a73f99dc08b45e1dffc68e734a59b6610fe511a0ef68fc8b7663d9c626f2a7481c121bc
|
7
|
+
data.tar.gz: 11d2d1af46f7515451e04c8bfd90983cca3c11245889423979ca13d9f055eb989bf4c3dad31be50686eb5881a953301738798b1077684cff16b483e241db07d3
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# HISTORY - Honyomi
|
2
2
|
|
3
|
+
## 1.2 - 2015-07-03
|
4
|
+
|
5
|
+
* Add image command
|
6
|
+
* It can be inline display of page on browser
|
7
|
+
* Need 'pdftoppm'
|
8
|
+
* Remove duplicated :type => :boolean
|
9
|
+
|
10
|
+
* Add book on web
|
11
|
+
* Drag & drop OR Dialog
|
12
|
+
* If you want to disable this feature, set ENV["HONYOMI_DISABLE_WEB_ADD"]
|
13
|
+
* $ HONYOMI_DISABLE_WEB_ADD=1 honyomi web
|
14
|
+
|
15
|
+
* Fix encode error
|
16
|
+
* Specify file encoding in File.read
|
17
|
+
* Add String#scrub
|
18
|
+
|
3
19
|
## 1.1 - 2015-06-23
|
4
20
|
|
5
21
|
* Add book on web
|
data/lib/honyomi/cli.rb
CHANGED
@@ -120,7 +120,7 @@ module Honyomi
|
|
120
120
|
end
|
121
121
|
|
122
122
|
desc "web", "Web search interface"
|
123
|
-
option :no_browser, :type => :boolean, :default => false, :aliases => '-n', :
|
123
|
+
option :no_browser, :type => :boolean, :default => false, :aliases => '-n', :desc => 'Do not launch browser.'
|
124
124
|
option :host, :default => '127.0.0.1', :aliases => '-o', :desc => 'Listen on HOST.'
|
125
125
|
option :port, :default => 9295, :aliases => '-p', :desc => 'Use PORT.'
|
126
126
|
option :server, :default => 'thin', :aliases => '-s', :desc => 'Use SERVER.'
|
@@ -130,6 +130,16 @@ module Honyomi
|
|
130
130
|
core.web(options)
|
131
131
|
end
|
132
132
|
|
133
|
+
desc "image book_id1 [book_id2 ...]", "Generate page images (Need pdftoppm)"
|
134
|
+
def image(*args)
|
135
|
+
core = Core.new
|
136
|
+
core.load_database
|
137
|
+
|
138
|
+
args.each do |id|
|
139
|
+
core.image(id.to_i, { verbose: true })
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
133
143
|
no_tasks do
|
134
144
|
# Override method for support -h
|
135
145
|
# defined in /lib/thor/invocation.rb
|
data/lib/honyomi/core.rb
CHANGED
@@ -120,6 +120,13 @@ EOF
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
+
def image(id, options = {})
|
124
|
+
pdf = Pdf.new(@database.books[id].path)
|
125
|
+
output_dir = File.join(image_dir, id.to_s)
|
126
|
+
pdf.generate_images(output_dir)
|
127
|
+
puts "Generated images to '#{output_dir}'" if options[:verbose]
|
128
|
+
end
|
129
|
+
|
123
130
|
def db_dir
|
124
131
|
File.join(home_dir, 'db')
|
125
132
|
end
|
@@ -138,5 +145,9 @@ EOF
|
|
138
145
|
|
139
146
|
@home_dir
|
140
147
|
end
|
148
|
+
|
149
|
+
def image_dir
|
150
|
+
File.join(home_dir, "image")
|
151
|
+
end
|
141
152
|
end
|
142
153
|
end
|
data/lib/honyomi/pdf.rb
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'honyomi'
|
2
3
|
require 'tmpdir'
|
4
|
+
require 'fileutils'
|
3
5
|
|
4
6
|
module Honyomi
|
5
7
|
class Pdf
|
6
8
|
def initialize(filename)
|
7
9
|
@filename = filename
|
10
|
+
end
|
8
11
|
|
12
|
+
def pages
|
9
13
|
Dir.mktmpdir do |dir|
|
10
14
|
outfile = File.join(dir, "pdf.txt")
|
11
|
-
system("pdftotext", filename, outfile) # Need pdftotext (poppler, xpdf)
|
15
|
+
system("pdftotext", @filename, outfile) # Need pdftotext (poppler, xpdf)
|
12
16
|
@text = File.read(outfile, encoding: Encoding::UTF_8)
|
13
17
|
if String.method_defined? :scrub
|
14
18
|
@text = @text.scrub('?')
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
18
21
|
|
19
|
-
def pages
|
20
22
|
@text.split("\f")
|
21
23
|
end
|
24
|
+
|
25
|
+
def generate_images(output_dir)
|
26
|
+
FileUtils.mkdir_p output_dir
|
27
|
+
system("pdftoppm", "-jpeg", @filename, File.join(output_dir, "book"))
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
data/lib/honyomi/util.rb
CHANGED
@@ -101,5 +101,14 @@ module Honyomi
|
|
101
101
|
def default_home
|
102
102
|
File.expand_path '~'
|
103
103
|
end
|
104
|
+
|
105
|
+
def count_digit(num)
|
106
|
+
num.to_s.length
|
107
|
+
end
|
108
|
+
|
109
|
+
def image_path(page)
|
110
|
+
zerofill = format("%0#{count_digit(page.book.page_num)}d", page.page_no)
|
111
|
+
"#{home_dir}/image/#{page.book.id}/book-#{zerofill}.jpg"
|
112
|
+
end
|
104
113
|
end
|
105
114
|
end
|
data/lib/honyomi/version.rb
CHANGED
data/lib/honyomi/web/app.rb
CHANGED
@@ -93,12 +93,13 @@ get '/v/:id' do
|
|
93
93
|
|
94
94
|
book = @database.books[params[:id].to_i]
|
95
95
|
|
96
|
-
if params[:
|
97
|
-
text_all(book)
|
98
|
-
elsif params[:pdf] == '1'
|
96
|
+
if params[:pdf] == '1'
|
99
97
|
send_file(book.path, :disposition => 'inline')
|
100
98
|
elsif params[:dl] == '1'
|
101
99
|
send_file(book.path, :disposition => 'download')
|
100
|
+
elsif params[:image] == '1'
|
101
|
+
page = @database.pages["#{params[:id].to_i}:#{params[:page].to_i}"]
|
102
|
+
send_file(Util.image_path(page))
|
102
103
|
else
|
103
104
|
if params[:page]
|
104
105
|
text_page(book, params[:page].to_i)
|
@@ -293,6 +294,12 @@ EOF
|
|
293
294
|
wrap_result_body_element(comment_hits) +
|
294
295
|
wrap_result_body_element(text_hits)
|
295
296
|
|
297
|
+
image_path = Util.image_path(page)
|
298
|
+
|
299
|
+
if File.exist? image_path
|
300
|
+
main_contents += %|<div><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="100%"/></div>|
|
301
|
+
end
|
302
|
+
|
296
303
|
<<EOF
|
297
304
|
<div class="result">
|
298
305
|
<div class="title">
|
@@ -339,9 +346,12 @@ EOF
|
|
339
346
|
book = page.book
|
340
347
|
title = book.title
|
341
348
|
|
349
|
+
image_path = Util.image_path(page)
|
350
|
+
has_image = File.exist? image_path
|
351
|
+
|
342
352
|
content = []
|
343
353
|
content << bookmark.comment if bookmark.comment
|
344
|
-
content << page.text if page.text
|
354
|
+
content << page.text if !has_image && page.text
|
345
355
|
|
346
356
|
r = []
|
347
357
|
rest = BOOKMARK_COMMENT_LENGTH
|
@@ -357,6 +367,10 @@ EOF
|
|
357
367
|
|
358
368
|
content = r.map { |e| "<p>#{escape_html(e)}</p>" }.join("\n")
|
359
369
|
|
370
|
+
if has_image
|
371
|
+
content += %|<p><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="100%"/></p>|
|
372
|
+
end
|
373
|
+
|
360
374
|
<<EOF
|
361
375
|
<div class="result">
|
362
376
|
<div class="title">
|
@@ -418,21 +432,28 @@ EOF
|
|
418
432
|
bm_text = ", <a href=\"/v/#{book.id}?b=1\"><span class=\"boomark-number\">#{bm.count}</span></a> bookmarks. "
|
419
433
|
end
|
420
434
|
|
421
|
-
%Q|#{pages} pages#{bm_text} <a href="/v/#{book.id}?dl=1">Download</a> <span class="file-size">(#{file_mb}M)</span
|
435
|
+
%Q|#{pages} pages#{bm_text} <a href="/v/#{book.id}?dl=1">Download</a> <span class="file-size">(#{file_mb}M)</span>|
|
422
436
|
end
|
423
437
|
|
424
438
|
def render_page(page, options = {})
|
425
439
|
book = page.book
|
440
|
+
|
441
|
+
# with_number
|
426
442
|
with_number = ""
|
427
443
|
if options[:with_number]
|
428
444
|
with_number = <<EOF
|
429
445
|
<div class="no row">
|
430
|
-
<div class="col-xs-
|
431
|
-
|
446
|
+
<div class="col-xs-8">
|
447
|
+
<div class="ss-box">#{favstar(page)}</div>
|
448
|
+
<a href="##{page.page_no}">P#{page.page_no}</a>
|
449
|
+
<a href="javascript:" class="page-text-toggle">Text</a>
|
450
|
+
<a href="/v/#{book.id}?pdf=1#page=#{page.page_no}">Pdf</a>
|
451
|
+
</div>
|
432
452
|
</div>
|
433
453
|
EOF
|
434
454
|
end
|
435
455
|
|
456
|
+
# comment
|
436
457
|
comment = ""
|
437
458
|
|
438
459
|
bm = @database.bookmark_from_page(page)
|
@@ -445,17 +466,33 @@ EOF
|
|
445
466
|
EOF
|
446
467
|
end
|
447
468
|
|
448
|
-
text = Util.highlight_keywords(page.text, options[:keywords], 'highlight')
|
449
|
-
text = text.gsub("\n\n", "<br/><br/>")
|
450
|
-
|
451
469
|
<<EOF
|
452
470
|
<div class="page" id="#{page.page_no}">
|
453
471
|
#{with_number}
|
454
472
|
#{comment}
|
473
|
+
#{render_page_main(page, options)}
|
474
|
+
</div>
|
475
|
+
EOF
|
476
|
+
end
|
477
|
+
|
478
|
+
def render_page_main(page, options)
|
479
|
+
image_path = Util.image_path(page)
|
480
|
+
|
481
|
+
text = Util.highlight_keywords(page.text, options[:keywords], 'highlight').gsub("\n\n", "<br/><br/>")
|
482
|
+
|
483
|
+
if File.exist?(image_path)
|
484
|
+
body = <<EOF
|
485
|
+
<div class="page-text hidden">#{text}</div>
|
486
|
+
<div><img src="/v/#{page.book.id}?image=1&page=#{page.page_no}" width="100%"/></div>
|
487
|
+
EOF
|
488
|
+
else
|
489
|
+
body = text
|
490
|
+
end
|
491
|
+
|
492
|
+
<<EOF
|
455
493
|
<div class="main">
|
456
|
-
#{
|
494
|
+
#{body}
|
457
495
|
</div>
|
458
|
-
</div>
|
459
496
|
EOF
|
460
497
|
end
|
461
498
|
|
@@ -3,6 +3,18 @@ function click_clear_button() {
|
|
3
3
|
}
|
4
4
|
|
5
5
|
$(document).ready(function() {
|
6
|
+
$(document).on('click', '.page-text-toggle', function(e) {
|
7
|
+
var node = $(this).parent().parent().parent().find(".page-text");
|
8
|
+
|
9
|
+
if (node.hasClass('hidden')) {
|
10
|
+
node.removeClass("hidden");
|
11
|
+
} else {
|
12
|
+
node.addClass("hidden");
|
13
|
+
}
|
14
|
+
|
15
|
+
e.preventDefault();
|
16
|
+
});
|
17
|
+
|
6
18
|
$(document).on('click', '.star', function(e) {
|
7
19
|
var id = $(this).attr('honyomi-id');
|
8
20
|
var page_no = $(this).attr('honyomi-page-no');
|
data/test/test_pdf.rb
CHANGED
@@ -24,4 +24,15 @@ class TestPdf < MiniTest::Test
|
|
24
24
|
assert_equal 3, pdf.pages.size
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
def test_generate_images
|
29
|
+
Dir.mktmpdir do |dir|
|
30
|
+
pdf = Honyomi::Pdf.new(test_pdf)
|
31
|
+
pdf.generate_images(dir)
|
32
|
+
|
33
|
+
Dir.chdir(dir) do
|
34
|
+
assert_equal %w(book-1.jpg book-2.jpg book-3.jpg), Dir.glob("*")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
27
38
|
end
|
data/test/test_util.rb
CHANGED
@@ -10,4 +10,11 @@ class TestUtil < MiniTest::Test
|
|
10
10
|
assert_equal %w(aa), Util::extract_keywords("aa -bb a:c")
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_count_digit
|
14
|
+
assert_equal 1, Util::count_digit(0)
|
15
|
+
assert_equal 1, Util::count_digit(1)
|
16
|
+
assert_equal 2, Util::count_digit(10)
|
17
|
+
assert_equal 3, Util::count_digit(100)
|
18
|
+
assert_equal 4, Util::count_digit(9999)
|
19
|
+
end
|
13
20
|
end
|
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
|
+
version: 1.2.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-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grn_mini
|