honyomi 1.0.0 → 1.1.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 +11 -0
- data/lib/honyomi/cli.rb +1 -0
- data/lib/honyomi/core.rb +11 -18
- data/lib/honyomi/database.rb +13 -0
- data/lib/honyomi/pdf.rb +4 -1
- data/lib/honyomi/util.rb +7 -0
- data/lib/honyomi/version.rb +1 -1
- data/lib/honyomi/web/app.rb +37 -0
- data/lib/honyomi/web/public/css/honyomi.css +8 -0
- data/lib/honyomi/web/public/js/honyomi.js +35 -0
- data/lib/honyomi/web/views/add.haml +12 -0
- data/lib/honyomi/web/views/layout.haml +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c387aa69369e0ac0b0c92d5ce0c56a0d6f9b782
|
4
|
+
data.tar.gz: 36bd6672cc22367b2a368eb913122e96bd2ff322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53df1091d9e29ba8d7fbabb7b0b4ba27d1080b74d29cc2f5af2afdb5f6947689f279094bffb0fb7c4e75d37c17b3c1eed0d324db88af83893eb6cd60890ebb99
|
7
|
+
data.tar.gz: 00b79ec2b4122df5b55d7c869f102f1916dbf5406bb202f073806f8e2afb61ef5d3bb3e7a74955c8adc31a41df5e8805a35d533f9bf6686958bb1ca22e732fa1
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# HISTORY - Honyomi
|
2
2
|
|
3
|
+
## 1.1 - 2015-06-23
|
4
|
+
|
5
|
+
* Add book on web
|
6
|
+
* Drag & drop OR Dialog
|
7
|
+
* If you want to disable this feature, set ENV["HONYOMI_DISABLE_WEB_ADD"]
|
8
|
+
* $ HONYOMI_DISABLE_WEB_ADD=1 honyomi web
|
9
|
+
|
10
|
+
* Fix encode error
|
11
|
+
* Specify file encoding in File.read
|
12
|
+
* Add String#scrub
|
13
|
+
|
3
14
|
## 1.0 - 2014-11-15
|
4
15
|
|
5
16
|
* Bookmark a page
|
data/lib/honyomi/cli.rb
CHANGED
@@ -110,6 +110,7 @@ module Honyomi
|
|
110
110
|
end
|
111
111
|
|
112
112
|
desc "list [book_id1 book_id2 ...]", "List books"
|
113
|
+
option :path, :type => :boolean, :desc => 'Display path'
|
113
114
|
option :title, :aliases => '-t', :type => :string, :desc => 'Filter title'
|
114
115
|
def list(*args)
|
115
116
|
core = Core.new
|
data/lib/honyomi/core.rb
CHANGED
@@ -23,16 +23,7 @@ module Honyomi
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def add(filename, options = {})
|
26
|
-
|
27
|
-
filename = File.expand_path(filename)
|
28
|
-
options = options.dup
|
29
|
-
pages = Pdf.new(filename).pages
|
30
|
-
pages = pages.map { |page| Util.strip_page(page) } if options[:strip]
|
31
|
-
options[:timestamp] = File.stat(filename).mtime
|
32
|
-
@database.add_book(filename, pages, options)
|
33
|
-
else
|
34
|
-
nil
|
35
|
-
end
|
26
|
+
@database.add_from_pdf(filename, options)
|
36
27
|
end
|
37
28
|
|
38
29
|
def update(book_id, options)
|
@@ -71,9 +62,15 @@ module Honyomi
|
|
71
62
|
id_length = books.max { |book| book.id.to_s.length }
|
72
63
|
id_length = id_length ? id_length.id.to_s.length : 0
|
73
64
|
|
74
|
-
|
75
|
-
|
76
|
-
|
65
|
+
if options[:path]
|
66
|
+
books.map do |book|
|
67
|
+
"#{book.id.to_s.rjust(id_length)} #{book.path}"
|
68
|
+
end
|
69
|
+
else
|
70
|
+
books.map do |book|
|
71
|
+
# "#{book.id} #{book.title} (#{book.page_num} pages) #{book.path}"
|
72
|
+
"#{book.id.to_s.rjust(id_length)} #{book.title} (#{book.page_num} pages)"
|
73
|
+
end
|
77
74
|
end
|
78
75
|
else
|
79
76
|
results = []
|
@@ -135,15 +132,11 @@ EOF
|
|
135
132
|
|
136
133
|
def home_dir
|
137
134
|
unless @home_dir
|
138
|
-
@home_dir = @opts[:home_dir] ||
|
135
|
+
@home_dir = @opts[:home_dir] || Util.home_dir
|
139
136
|
FileUtils.mkdir_p(@home_dir) unless File.exist?(@home_dir)
|
140
137
|
end
|
141
138
|
|
142
139
|
@home_dir
|
143
140
|
end
|
144
|
-
|
145
|
-
def default_home
|
146
|
-
File.expand_path '~'
|
147
|
-
end
|
148
141
|
end
|
149
142
|
end
|
data/lib/honyomi/database.rb
CHANGED
@@ -33,6 +33,19 @@ module Honyomi
|
|
33
33
|
)
|
34
34
|
end
|
35
35
|
|
36
|
+
def add_from_pdf(filename, options = {})
|
37
|
+
if File.exist?(filename)
|
38
|
+
filename = File.expand_path(filename)
|
39
|
+
options = options.dup
|
40
|
+
pages = Pdf.new(filename).pages
|
41
|
+
pages = pages.map { |page| Util.strip_page(page) } if options[:strip]
|
42
|
+
options[:timestamp] = File.stat(filename).mtime
|
43
|
+
add_book(filename, pages, options)
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
36
49
|
def add_book(path, pages, options = {})
|
37
50
|
book = book_from_path(path)
|
38
51
|
|
data/lib/honyomi/pdf.rb
CHANGED
@@ -9,7 +9,10 @@ module Honyomi
|
|
9
9
|
Dir.mktmpdir do |dir|
|
10
10
|
outfile = File.join(dir, "pdf.txt")
|
11
11
|
system("pdftotext", filename, outfile) # Need pdftotext (poppler, xpdf)
|
12
|
-
@text = File.read(outfile)
|
12
|
+
@text = File.read(outfile, encoding: Encoding::UTF_8)
|
13
|
+
if String.method_defined? :scrub
|
14
|
+
@text = @text.scrub('?')
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
data/lib/honyomi/util.rb
CHANGED
data/lib/honyomi/version.rb
CHANGED
data/lib/honyomi/web/app.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'haml'
|
3
|
+
require 'honyomi/core'
|
3
4
|
require 'honyomi/database'
|
4
5
|
require 'honyomi/util'
|
5
6
|
require 'sinatra'
|
@@ -31,6 +32,42 @@ get '/' do
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
get '/add' do
|
36
|
+
if !ENV['HONYOMI_DISABLE_WEB_ADD']
|
37
|
+
haml :add
|
38
|
+
else
|
39
|
+
""
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
post '/upload' do
|
44
|
+
return "" if ENV['HONYOMI_DISABLE_WEB_ADD']
|
45
|
+
|
46
|
+
@database = $database
|
47
|
+
|
48
|
+
if params[:files]
|
49
|
+
save_dir = File.join(Util.home_dir, "book")
|
50
|
+
FileUtils.mkdir_p(save_dir) unless File.exist?(save_dir)
|
51
|
+
|
52
|
+
params[:files].each do |file|
|
53
|
+
save_path = File.join(save_dir, file[:filename])
|
54
|
+
|
55
|
+
File.open(save_path, 'wb') do |f|
|
56
|
+
# p file[:tempfile]
|
57
|
+
f.write file[:tempfile].read
|
58
|
+
end
|
59
|
+
|
60
|
+
@database.add_from_pdf(save_path)
|
61
|
+
end
|
62
|
+
|
63
|
+
@message = "Upload Success"
|
64
|
+
else
|
65
|
+
@message = "Upload Failed"
|
66
|
+
end
|
67
|
+
|
68
|
+
redirect "/"
|
69
|
+
end
|
70
|
+
|
34
71
|
get '/help' do
|
35
72
|
haml :help
|
36
73
|
end
|
@@ -152,4 +152,39 @@ $(document).ready(function() {
|
|
152
152
|
$("#title-form-cancel").click(function (e) {
|
153
153
|
hideTitleForm();
|
154
154
|
});
|
155
|
+
|
156
|
+
$(function() {
|
157
|
+
document.addEventListener("dragover", function(e) {
|
158
|
+
e.preventDefault();
|
159
|
+
}, true);
|
160
|
+
|
161
|
+
$('.droparea').on('drop', function(e) {
|
162
|
+
e.preventDefault();
|
163
|
+
e.stopPropagation();
|
164
|
+
|
165
|
+
var files = e.originalEvent.dataTransfer.files;
|
166
|
+
|
167
|
+
var fd = new FormData();
|
168
|
+
|
169
|
+
for (var i = 0; i < files.length; i++) {
|
170
|
+
fd.append("files[]", files[i]);
|
171
|
+
}
|
172
|
+
|
173
|
+
if (confirm("Upload?")) {
|
174
|
+
$.ajax({
|
175
|
+
url: "/upload",
|
176
|
+
type: "POST",
|
177
|
+
data: fd,
|
178
|
+
processData: false,
|
179
|
+
contentType: false,
|
180
|
+
success: function(msg) {
|
181
|
+
document.location = "/";
|
182
|
+
}
|
183
|
+
});
|
184
|
+
}
|
185
|
+
|
186
|
+
return false;
|
187
|
+
});
|
188
|
+
});
|
189
|
+
|
155
190
|
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
!!!
|
2
|
+
|
3
|
+
.container
|
4
|
+
%h1 Add books
|
5
|
+
|
6
|
+
.droparea
|
7
|
+
Drag & Drop file.
|
8
|
+
%form{:action => "/upload", :method => "post", :enctype => "multipart/form-data"}
|
9
|
+
%input{:id => "file", :type => "file", :name => "files[]", :multiple => ""}
|
10
|
+
%input{:type => "submit", :name => "upload"}
|
11
|
+
|
12
|
+
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ongaeshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grn_mini
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- lib/honyomi/web/public/image/favicon.ico
|
202
202
|
- lib/honyomi/web/public/image/star.png
|
203
203
|
- lib/honyomi/web/public/js/honyomi.js
|
204
|
+
- lib/honyomi/web/views/add.haml
|
204
205
|
- lib/honyomi/web/views/help.haml
|
205
206
|
- lib/honyomi/web/views/index.haml
|
206
207
|
- lib/honyomi/web/views/layout.haml
|
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
235
|
version: '0'
|
235
236
|
requirements: []
|
236
237
|
rubyforge_project:
|
237
|
-
rubygems_version: 2.
|
238
|
+
rubygems_version: 2.4.5
|
238
239
|
signing_key:
|
239
240
|
specification_version: 4
|
240
241
|
summary: e-book (pdf) search engine, command line interface, and web application
|