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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2f44bb420e77ab9fbef9b1508052aca915ffbd7
4
- data.tar.gz: d443c1e385c34c9f67f25cffc201070a49503dd2
3
+ metadata.gz: 4c387aa69369e0ac0b0c92d5ce0c56a0d6f9b782
4
+ data.tar.gz: 36bd6672cc22367b2a368eb913122e96bd2ff322
5
5
  SHA512:
6
- metadata.gz: b9dd0c9422a025fefa25e36d64bfd20b5f0083d16595219b920acb6ce67529adda81624cefb6801714f50a51765b999024fd0b77121c1acbd3c6daedd5956c4b
7
- data.tar.gz: da02decc4acb9741aae5492378f520b3c0940026f2717d3a7b4a3ed6051d84b120470f99a57807211b9446914016cb9e1b443adb3482905995a0ba7662799590
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
- if File.exist?(filename)
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
- books.map do |book|
75
- # "#{book.id} #{book.title} (#{book.page_num} pages) #{book.path}"
76
- "#{book.id.to_s.rjust(id_length)} #{book.title} (#{book.page_num} pages)"
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] || ENV['HONYOMI_DATABASE_DIR'] || File.join(default_home, '.honyomi')
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
@@ -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
@@ -94,5 +94,12 @@ module Honyomi
94
94
  comment.gsub("\n", "<br/>")
95
95
  end
96
96
 
97
+ def home_dir
98
+ ENV['HONYOMI_DATABASE_DIR'] || File.join(default_home, '.honyomi')
99
+ end
100
+
101
+ def default_home
102
+ File.expand_path '~'
103
+ end
97
104
  end
98
105
  end
@@ -1,3 +1,3 @@
1
1
  module Honyomi
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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
@@ -126,3 +126,11 @@ input#clear {
126
126
  #help h3 {
127
127
  font-size: 120%;
128
128
  }
129
+
130
+ /* add */
131
+
132
+ .droparea {
133
+ border : solid 1px black;
134
+ padding : 100px;
135
+ background-color : #f0f0f0;
136
+ }
@@ -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
+
@@ -20,6 +20,10 @@
20
20
  %a(class="navbar-brand" href="/")
21
21
  Honyomi
22
22
  .navbar-collapse.collapse
23
+ -if !ENV['HONYOMI_DISABLE_WEB_ADD']
24
+ %ul(class="nav navbar-nav")
25
+ %li
26
+ <a href="/add">Add</a>
23
27
  %ul(class="nav navbar-nav")
24
28
  %li
25
29
  <a href="/help">Help</a>
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.0.0
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: 2014-11-16 00:00:00.000000000 Z
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.2.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