honyomi 0.0.3 → 0.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: 7fd511b3f8e468cd36b890f1cd73049eac1c59da
4
- data.tar.gz: c23bc62e9240d32812ec176742d818b140e0b2ef
3
+ metadata.gz: bf7508e7109d3ead69a143592dde4cb74b6e4487
4
+ data.tar.gz: 31fb3eaaf69b663b3d472e77b82042689b45d146
5
5
  SHA512:
6
- metadata.gz: 710cb9e03dff64b15969ba975efc5ba2e3438f9ab0a7967c2035864baf1431b74ce263483484d8aaca63cf3372cae5867837af65fd4d0f1aab9c7be0d88af4b0
7
- data.tar.gz: f786bb8bf384188f9f1bcb855218ed4c0fa7f1f55a84f4226e3e146f504b8864b1c9b87f12ee37bf18327fe69821e7175c869e2709200545786a7a12aa6835d2
6
+ metadata.gz: 9fea83150ee7a69e5e1655ced9eb748e6fb4b80ff216732f762225899f749d3083d98341a5aa76af89ac88ee486a7b62a9cfb7100a46248b820522d3fe23749c
7
+ data.tar.gz: 66252688b26270c8998b13cb348cc07a89e2a960a39fc4abe9f9375b2d1fba79cbfbe6cad11cae735eae79bf63804e08dca4b4a536e6be052993d8828f1a05e3
data/HISTORY.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # HISTORY - Honyomi
2
2
 
3
- ## 0.3 - 2014-07-18
3
+ ## 0.1 - 2014-07-18
4
+
5
+ * Search in book
6
+ * Display the book list
7
+ * Pagination (AutoPagerize)
8
+ * Add favicon
9
+
10
+ ## 0.0.3 - 2014-07-18
4
11
 
5
12
  * Support file name includes parenthesis or any special characters
@@ -1,3 +1,3 @@
1
1
  module Honyomi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -15,60 +15,101 @@ get '/' do
15
15
  @database = $database
16
16
 
17
17
  if @params[:query] && !@params[:query].empty?
18
- results = @database.search(@params[:query])
18
+ search_home
19
+ else
20
+ home
21
+ end
22
+ end
19
23
 
20
- page_entries = results.paginate([["_score", :desc]], :page => 1, :size => 20)
21
- snippet = results.expression.snippet([["<strong>", "</strong>"]], {html_escape: true, normalize: true, max_results: 10})
24
+ post '/search' do
25
+ if params[:book_id] && !@params[:book_id].empty?
26
+ redirect "/v/#{@params[:book_id]}?query=#{escape(params[:query])}"
27
+ else
28
+ redirect "/?query=#{escape(params[:query])}"
29
+ end
30
+ end
22
31
 
23
- books = {}
32
+ get '/v/:id' do
33
+ @database = $database
24
34
 
25
- results.each do |page|
26
- books[page.book.path] = 1
35
+ book = @database.books[params[:id].to_i]
36
+
37
+ if params[:raw] == '1'
38
+ raw_all(book)
39
+ elsif params[:pdf] == '1'
40
+ send_file(book.path, :disposition => 'inline')
41
+ elsif params[:dl] == '1'
42
+ send_file(book.path, :disposition => 'download')
43
+ else
44
+ if params[:page]
45
+ raw_page(book, params[:page].to_i)
46
+ else
47
+ if @params[:query] && !@params[:query].empty?
48
+ search_book_home(book)
49
+ else
50
+ book_home(book)
51
+ end
27
52
  end
53
+ end
54
+ end
28
55
 
29
- r = page_entries.map do |page|
30
- query_plus = escape "#{@params[:query]} book:#{page.book.id}"
31
- query_minus = escape "#{@params[:query]} -book:#{page.book.id}"
56
+ helpers do
32
57
 
58
+ def home
59
+ r = @database.books.map { |book|
33
60
  <<EOF
34
- <div class="result">
35
- <div class="result-header"><a href="/v/#{page.book.id}?page=#{page.page_no}">#{page.book.title}</a> (P#{page.page_no})</div>
36
- <div class="row result-sub-header">
37
- <div class="col-xs-6"><a href="/?query=#{query_plus}">Filter+</a> <a href="/?query=#{query_minus}">Filter-</a></div>
38
- </div>
39
- <div class="result-body">
40
- #{snippet.execute(page.text).map {|segment| "<div class=\"result-body-element\">" + segment.gsub("\n", "") + "</div>"}.join("\n") }
41
- </div>
42
- </div>
61
+ <li>#{book.id}: <a href="/v/#{book.id}">#{book.title}</a> (#{book.page_num}P)</li>
43
62
  EOF
44
- end
63
+ }.reverse
45
64
 
46
65
  @content = <<EOF
47
- <div class="matches">#{books.size} books, #{results.size} pages</div>
66
+ <div class="matches">#{@database.books.size} books, #{@database.pages.size} pages.</div>
67
+ <div class="result">
68
+ <ul>
48
69
  #{r.join("\n")}
70
+ </ul>
71
+ </div>
49
72
  EOF
50
- else
51
- @content = <<EOF
52
- <div class="result">#{@database.books.size} books, #{@database.pages.size} pages.</div>
53
- EOF
73
+
74
+ haml :index
54
75
  end
55
76
 
56
- haml :index
57
- end
77
+ def search_home
78
+ search_common(@params[:query],
79
+ [["_score", :desc]],
80
+ true
81
+ )
82
+ end
58
83
 
59
- post '/search' do
60
- redirect "/?query=#{escape(params[:query])}"
61
- end
84
+ def book_home(book)
85
+ @book_id = book.id
86
+ @navbar_href = "/v/#{book.id}"
87
+ @navbar_title = book.title
88
+ file_mb = File.stat(book.path).size / (1024 * 1024)
62
89
 
63
- get '/v/:id' do
64
- @database = $database
90
+ @content = <<EOF
91
+ <div class="result">
92
+ <div class="matches">#{book.page_num} pages. <a href="/v/#{book.id}?dl=1">Download</a> <span class="result-file-size">(#{file_mb}M)</span>&nbsp;&nbsp;&nbsp;<a href="/v/#{book.id}?pdf=1">Pdf</a>&nbsp;&nbsp;&nbsp;<a href="/v/#{book.id}?raw=1">Raw</a></div>
93
+ </div>
94
+ EOF
95
+ haml :index
96
+ end
65
97
 
66
- book = @database.books[params[:id].to_i]
98
+ def search_book_home(book)
99
+ @book_id = book.id
100
+ @navbar_href = "/v/#{book.id}"
101
+ @navbar_title = book.title
67
102
 
68
- if params[:raw] == '1'
103
+ search_common(@params[:query] + " book: #{book.id}",
104
+ [["page_no", :asc]],
105
+ false
106
+ )
107
+ end
108
+
109
+ def raw_all(book)
69
110
  pages = @database.book_pages(book.id)
70
111
 
71
- @navbar_href = "#1"
112
+ @navbar_href = "/v/#{book.id}"
72
113
  @navbar_title = book.title
73
114
 
74
115
  @content = pages.map { |page|
@@ -81,27 +122,78 @@ EOF
81
122
  }.join("\n")
82
123
 
83
124
  haml :raw
84
- elsif params[:pdf] == '1'
85
- send_file(book.path, :disposition => 'inline')
86
- elsif params[:dl] == '1'
87
- send_file(book.path, :disposition => 'download')
88
- else
89
- @navbar_href = ""
90
- @navbar_title = book.title
125
+ end
91
126
 
92
- pages = @database.book_pages(book.id)
93
- page = pages[params[:page].to_i]
94
- file_mb = File.stat(page.book.path).size / (1024 * 1024)
127
+ def raw_page(book, page_no)
128
+ @navbar_href = "/v/#{book.id}"
129
+ @navbar_title = book.title
130
+ page = @database.book_pages(book.id)[page_no]
131
+ file_mb = File.stat(book.path).size / (1024 * 1024)
95
132
 
96
133
  @content = <<EOF
97
134
  <div class="landing-page" id="#{page.page_no}">
98
135
  <div class="landing-page-no"><i class="fa fa-file-text-o"></i> P#{page.page_no} &nbsp;&nbsp;&nbsp;
99
- <a href="/v/#{page.book.id}?dl=1">Download</a> <span class="result-file-size">(#{file_mb}M)</span>&nbsp;&nbsp;&nbsp;<a href="/v/#{page.book.id}?pdf=1#page=#{page.page_no}">Pdf</a>&nbsp;&nbsp;&nbsp;<a href="/v/#{page.book.id}?raw=1##{page.page_no}">Raw</a></div>
136
+ <a href="/v/#{book.id}?dl=1">Download</a> <span class="result-file-size">(#{file_mb}M)</span>&nbsp;&nbsp;&nbsp;<a href="/v/#{book.id}?pdf=1#page=#{page.page_no}">Pdf</a>&nbsp;&nbsp;&nbsp;<a href="/v/#{book.id}?raw=1##{page.page_no}">Raw</a></div>
100
137
  <pre>#{escape_html page.text}</pre>
101
138
  </div>
102
139
  EOF
103
-
104
140
  haml :raw
105
141
  end
106
- end
107
142
 
143
+ RPAGE_SIZE = 20
144
+
145
+ def search_common(query, sort_keys, is_filter)
146
+ results = @database.search(query)
147
+
148
+ rpage = @params[:rpage] ? @params[:rpage].to_i : 1
149
+ rpage_entries = results.paginate(sort_keys, :page => rpage, :size => RPAGE_SIZE)
150
+ pagination_str = ""
151
+ if (rpage - 1) * RPAGE_SIZE + rpage_entries.count < results.count
152
+ pagination_str = <<EOF
153
+ <ul class="pager">
154
+ <li><a href='#{url + "?query=#{escape(@params[:query])}&rpage=#{rpage + 1}"}' rel='next'>Next</a></li>
155
+ </ul>
156
+ EOF
157
+ end
158
+
159
+ snippet = results.expression.snippet([["<strong>", "</strong>"]], {html_escape: true, normalize: true, max_results: 10})
160
+
161
+ books = {}
162
+
163
+ results.each do |page|
164
+ books[page.book.path] = 1
165
+ end
166
+
167
+ r = rpage_entries.map do |page|
168
+ if is_filter
169
+ query_plus = escape "#{query} book:#{page.book.id}"
170
+ query_minus = escape "#{query} -book:#{page.book.id}"
171
+ filter_str = "<div class=\"col-xs-6\"><a href=\"/?query=#{query_plus}\">Filter+</a> <a href=\"/?query=#{query_minus}\">Filter-</a></div>"
172
+ else
173
+ filter_str = ""
174
+ end
175
+
176
+ <<EOF
177
+ <div class="result">
178
+ <div class="result-header"><a href="/v/#{page.book.id}?page=#{page.page_no}">#{page.book.title}</a> (P#{page.page_no})</div>
179
+ <div class="row result-sub-header">
180
+ #{filter_str}
181
+ </div>
182
+ <div class="result-body">
183
+ #{snippet.execute(page.text).map {|segment| "<div class=\"result-body-element\">" + segment.gsub("\n", "") + "</div>"}.join("\n") }
184
+ </div>
185
+ </div>
186
+ EOF
187
+ end
188
+
189
+ @content = <<EOF
190
+ <div class="matches">#{books.size} books, #{results.size} pages</div>
191
+ <div class="autopagerize_page_element">
192
+ #{r.join("\n")}
193
+ </div>
194
+ #{pagination_str}
195
+ EOF
196
+
197
+ haml :index
198
+ end
199
+ end
@@ -44,4 +44,15 @@
44
44
  padding: 0px 0px 10px 0px;
45
45
  }
46
46
 
47
+ .result ul {
48
+ font-size: 120%;
49
+ list-style: none;
50
+ padding-left: 0px;
51
+ }
52
+
53
+ .landing-page ul {
54
+ font-size: 120%;
55
+ list-style: none;
56
+ padding-left: 0px;
57
+ }
47
58
 
@@ -6,5 +6,6 @@
6
6
  %form(class="form-inline" method="post" action="/search")
7
7
  .form-group
8
8
  %input(class="form-control" type="text" size=40 name="query" value="#{@params[:query]}")
9
+ %input(type="hidden" name="book_id" value="#{@book_id}")
9
10
  %input(class="btn btn-primary" type="submit" value="Search")
10
11
  = @content
@@ -5,6 +5,7 @@
5
5
  %meta(charset='utf-8')
6
6
  %title Honyomi
7
7
  %meta(name="viewport" content="width=device-width, initial-scale=1.0")
8
+ %link(rel="shortcut icon" href="/image/favicon.ico")
8
9
  %link(rel="stylesheet" href="/css/bootstrap.min.css")
9
10
  %link(rel="stylesheet" href="/css/honyomi.css")
10
11
  %link(rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css")
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: 0.0.3
4
+ version: 0.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-07-18 00:00:00.000000000 Z
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grn_mini
@@ -194,6 +194,7 @@ files:
194
194
  - lib/honyomi/web/config.ru
195
195
  - lib/honyomi/web/public/css/bootstrap.min.css
196
196
  - lib/honyomi/web/public/css/honyomi.css
197
+ - lib/honyomi/web/public/image/favicon.ico
197
198
  - lib/honyomi/web/views/index.haml
198
199
  - lib/honyomi/web/views/layout.haml
199
200
  - lib/honyomi/web/views/raw.haml