bookbindery 9.2.1 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bookbinder.gemspec +1 -1
- data/lib/bookbinder/spider.rb +1 -1
- data/master_middleman/bookbinder_helpers.rb +5 -1
- data/template_app/lib/search/handler.rb +50 -0
- data/template_app/lib/search/hit.rb +15 -0
- data/template_app/lib/search/query.rb +41 -0
- data/template_app/lib/search/renderer.rb +29 -0
- data/template_app/lib/search/result.rb +35 -0
- data/template_app/rack_app.rb +2 -2
- data/template_app/search-results.html.erb +5 -5
- metadata +59 -55
- data/template_app/lib/search.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa012f4769995d24bbe904174f7e95f7b27c3c08
|
4
|
+
data.tar.gz: 8f9bfab1aa26a8e9502f1039a01ac788e25a99f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9255b2ff21f3fd03c1ea1c929876bd65842e0740f2f8f71faeb99bab42a2406522d72f2529c76efc6cd4c488611b5e001df8c130b332d06d4c8371423c931dd7
|
7
|
+
data.tar.gz: 93b7305cdfd7334605e8d8496426bc7f29a667a40582d1c908d9ff5bcac11a809941a8cfd9c6d3ecdecca6fef39d3429b2cb11af02019a06c7ecb9c5bff030ba
|
data/bookbinder.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'base64'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'bookbindery'
|
5
|
-
s.version = '9.
|
5
|
+
s.version = '9.3.0'
|
6
6
|
s.summary = 'Markdown to Rackup application documentation generator'
|
7
7
|
s.description = 'A command line utility to be run in Book repositories to stitch together their constituent Markdown repos into a static-HTML-serving application'
|
8
8
|
s.authors = ['Mike Grafton', 'Lucas Marks', 'Gavin Morgan', 'Nikhil Gajwani', 'Dan Wendorf', 'Brenda Chan', 'Matthew Boedicker', 'Andrew Bruce', 'Frank Kotsianas', 'Elena Sharma', 'Christa Hartsock', 'Michael Trestman', 'Alpha Chen', 'Sarah McAlear', 'Gregg Van Hove']
|
data/lib/bookbinder/spider.rb
CHANGED
@@ -42,7 +42,7 @@ Found #{@broken_links.count} broken links!
|
|
42
42
|
def find_broken_links(port, broken_link_exclusions: /(?!.*)/)
|
43
43
|
temp_host = "localhost:#{port}"
|
44
44
|
sieve = Sieve.new domain: "http://#{temp_host}"
|
45
|
-
links = crawl_from "http://#{temp_host}/index.html", sieve
|
45
|
+
links = crawl_from "http://#{temp_host}#{ENV['CUSTOM_ROOT']}/index.html", sieve
|
46
46
|
broken_links = links.first
|
47
47
|
public_broken_links = broken_links.reject {|l| l.match(broken_link_exclusions)}
|
48
48
|
|
@@ -141,7 +141,11 @@ module Bookbinder
|
|
141
141
|
private
|
142
142
|
|
143
143
|
def subnav_template_name
|
144
|
-
|
144
|
+
if current_path == 'search.html'
|
145
|
+
config[:subnav_templates].values.first
|
146
|
+
else
|
147
|
+
config[:subnav_templates][template_key] || 'default'
|
148
|
+
end
|
145
149
|
end
|
146
150
|
|
147
151
|
def decreasingly_specific_namespaces
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'elasticsearch'
|
2
|
+
require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require_relative 'query'
|
6
|
+
require_relative 'renderer'
|
7
|
+
|
8
|
+
module Bookbinder
|
9
|
+
module Search
|
10
|
+
class Handler
|
11
|
+
def initialize(client_class = Elasticsearch::Client, environment = ENV)
|
12
|
+
@client_class = client_class
|
13
|
+
@environment = environment
|
14
|
+
@renderer = Renderer.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(request_env)
|
18
|
+
results = query.search(extract_query_params(request_env['QUERY_STRING']))
|
19
|
+
|
20
|
+
[200, {'Content-Type' => 'text/html'}, [renderer.render_results(results)]]
|
21
|
+
rescue Exception => e
|
22
|
+
puts e.message
|
23
|
+
puts e.backtrace.join("\n")
|
24
|
+
|
25
|
+
[500, {'Content-Type' => 'text/plain'}, ['An error occurred']]
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_query_params(param_string)
|
29
|
+
parsed = CGI::parse(param_string || '')
|
30
|
+
parsed.keys.inject(Hash.new('')) do |params, key|
|
31
|
+
# CGI::parse returns values in an array
|
32
|
+
params[key] = parsed[key].first
|
33
|
+
params
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :renderer, :client_class, :environment
|
40
|
+
|
41
|
+
def elasticsearch_url
|
42
|
+
@elasticsearch_url ||= JSON.parse(environment['VCAP_SERVICES'])['searchly'][0]['credentials']['uri']
|
43
|
+
end
|
44
|
+
|
45
|
+
def query
|
46
|
+
Query.new(client_class.new(url: elasticsearch_url))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bookbinder
|
2
|
+
module Search
|
3
|
+
class Hit
|
4
|
+
def initialize(attrs = {})
|
5
|
+
source_fields = attrs.fetch('_source')
|
6
|
+
@title = source_fields.fetch('title').sub(/\A(.+)\|.*\z/, '\\1').strip
|
7
|
+
@url = source_fields.fetch('url')
|
8
|
+
|
9
|
+
@text = attrs.fetch('highlight').fetch('text').first.strip
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :title, :url, :text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
require_relative 'result'
|
4
|
+
|
5
|
+
module Bookbinder
|
6
|
+
module Search
|
7
|
+
class Query
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def search(params)
|
13
|
+
query = params.fetch('q', '')
|
14
|
+
|
15
|
+
return Result.new(query, 0, [], 1) if query == ''
|
16
|
+
|
17
|
+
page_number = [params['page'].to_i, 1].max
|
18
|
+
|
19
|
+
query_options = YAML.load_file(File.expand_path('../../../search.yml', __FILE__))
|
20
|
+
|
21
|
+
query_options['from'] = (page_number - 1) * 10
|
22
|
+
query_options['query']['query_string']['query'] = query
|
23
|
+
|
24
|
+
results = client.search index: 'searching', body: query_options
|
25
|
+
|
26
|
+
Result.new(
|
27
|
+
query,
|
28
|
+
results['hits']['total'],
|
29
|
+
results['hits']['hits'],
|
30
|
+
page_number
|
31
|
+
)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :client
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Bookbinder
|
4
|
+
module Search
|
5
|
+
class Renderer
|
6
|
+
def initialize
|
7
|
+
@template = ERB.new(File.read(File.expand_path('../../../search-results.html.erb', __FILE__)))
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_results(result)
|
11
|
+
result_binding = result.instance_eval { binding }
|
12
|
+
|
13
|
+
render_layout do
|
14
|
+
@template.result(result_binding)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def render_layout
|
21
|
+
layout.result(binding)
|
22
|
+
end
|
23
|
+
|
24
|
+
def layout
|
25
|
+
@layout ||= ERB.new(File.read(File.expand_path('../../../public/search.html', __FILE__)))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'hit'
|
2
|
+
|
3
|
+
module Bookbinder
|
4
|
+
module Search
|
5
|
+
class Result
|
6
|
+
def initialize(query, hit_count, raw_hits, page_number)
|
7
|
+
@query = query
|
8
|
+
@hit_count = hit_count
|
9
|
+
@hits = raw_hits.map { |h| Hit.new(h) }
|
10
|
+
@page_number = page_number
|
11
|
+
@last_page = (hit_count / 10.0).ceil
|
12
|
+
@page_window = calculate_page_window
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :query, :hit_count, :hits, :page_number, :last_page, :page_window
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def calculate_page_window
|
20
|
+
window_start = [page_number - 2, 1].max
|
21
|
+
window_end = [window_start + 4, last_page].min
|
22
|
+
window = (window_start .. window_end).to_a
|
23
|
+
|
24
|
+
if window.length < 5 && window.last == last_page && window.first != 1
|
25
|
+
window.unshift(window.first - 1)
|
26
|
+
if window.length < 5
|
27
|
+
window.unshift(window.first - 1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
window
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/template_app/rack_app.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'rack/rewrite'
|
3
3
|
require_relative './lib/server'
|
4
|
-
require_relative './lib/search'
|
4
|
+
require_relative './lib/search/handler'
|
5
5
|
|
6
6
|
module Bookbinder
|
7
7
|
class RackApp
|
@@ -23,7 +23,7 @@ module Bookbinder
|
|
23
23
|
run Bookbinder::NotFound.new('public/404.html')
|
24
24
|
end
|
25
25
|
map '/search' do
|
26
|
-
run Bookbinder::Search
|
26
|
+
run Bookbinder::Search::Handler.new
|
27
27
|
end
|
28
28
|
if ENV['CUSTOM_ROOT']
|
29
29
|
map ENV['CUSTOM_ROOT'] do
|
@@ -3,18 +3,18 @@
|
|
3
3
|
<input name="q" value="<%= query %>"/>
|
4
4
|
</form>
|
5
5
|
|
6
|
-
<% if
|
6
|
+
<% if hit_count == 0 %>
|
7
7
|
<div class="no-results">No Results</div>
|
8
8
|
<% else %>
|
9
9
|
<div class="result-summary">
|
10
|
-
Showing <%= (page_number - 1) * 10 + 1 %> to <%= [(page_number - 1) * 10 + 10,
|
10
|
+
Showing <%= (page_number - 1) * 10 + 1 %> to <%= [(page_number - 1) * 10 + 10, hit_count].min %> of <%= hit_count %> results.
|
11
11
|
</div>
|
12
12
|
|
13
13
|
<ul class="search-results-list">
|
14
|
-
<%
|
14
|
+
<% hits.each do |hit| %>
|
15
15
|
<li>
|
16
|
-
<a href="<%=
|
17
|
-
<div><%=
|
16
|
+
<a href="<%= hit.url %>"><%= hit.title %></a>
|
17
|
+
<div><%= hit.text %></div>
|
18
18
|
</li>
|
19
19
|
<% end %>
|
20
20
|
</ul>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookbindery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Grafton
|
@@ -22,188 +22,188 @@ authors:
|
|
22
22
|
autorequire:
|
23
23
|
bindir: install_bin
|
24
24
|
cert_chain: []
|
25
|
-
date: 2016-04-
|
25
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
26
26
|
dependencies:
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fog-aws
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.7.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.7.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ansi
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.4'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: middleman
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 3.4.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.4.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: middleman-livereload
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 3.4.3
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.4.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: middleman-syntax
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '2.0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rouge
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '!='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 1.9.1
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '!='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.9.1
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: redcarpet
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: 3.2.3
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 3.2.3
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: anemone
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: css_parser
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: puma
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rack-rewrite
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- -
|
171
|
+
- - '>='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - '>='
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: therubyracer
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- -
|
185
|
+
- - '>='
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
type: :runtime
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- -
|
192
|
+
- - '>='
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: git
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- -
|
199
|
+
- - ~>
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: 1.2.8
|
202
202
|
type: :runtime
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- -
|
206
|
+
- - ~>
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: 1.2.8
|
209
209
|
- !ruby/object:Gem::Dependency
|
@@ -224,98 +224,98 @@ dependencies:
|
|
224
224
|
name: thor
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
|
-
- -
|
227
|
+
- - '>='
|
228
228
|
- !ruby/object:Gem::Version
|
229
229
|
version: '0'
|
230
230
|
type: :runtime
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
|
-
- -
|
234
|
+
- - '>='
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
238
|
name: elasticsearch
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
|
-
- -
|
241
|
+
- - '>='
|
242
242
|
- !ruby/object:Gem::Version
|
243
243
|
version: '0'
|
244
244
|
type: :runtime
|
245
245
|
prerelease: false
|
246
246
|
version_requirements: !ruby/object:Gem::Requirement
|
247
247
|
requirements:
|
248
|
-
- -
|
248
|
+
- - '>='
|
249
249
|
- !ruby/object:Gem::Version
|
250
250
|
version: '0'
|
251
251
|
- !ruby/object:Gem::Dependency
|
252
252
|
name: license_finder
|
253
253
|
requirement: !ruby/object:Gem::Requirement
|
254
254
|
requirements:
|
255
|
-
- -
|
255
|
+
- - '>='
|
256
256
|
- !ruby/object:Gem::Version
|
257
257
|
version: '0'
|
258
258
|
type: :development
|
259
259
|
prerelease: false
|
260
260
|
version_requirements: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
|
-
- -
|
262
|
+
- - '>='
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
265
|
- !ruby/object:Gem::Dependency
|
266
266
|
name: pry-byebug
|
267
267
|
requirement: !ruby/object:Gem::Requirement
|
268
268
|
requirements:
|
269
|
-
- -
|
269
|
+
- - '>='
|
270
270
|
- !ruby/object:Gem::Version
|
271
271
|
version: '0'
|
272
272
|
type: :development
|
273
273
|
prerelease: false
|
274
274
|
version_requirements: !ruby/object:Gem::Requirement
|
275
275
|
requirements:
|
276
|
-
- -
|
276
|
+
- - '>='
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: '0'
|
279
279
|
- !ruby/object:Gem::Dependency
|
280
280
|
name: rake
|
281
281
|
requirement: !ruby/object:Gem::Requirement
|
282
282
|
requirements:
|
283
|
-
- -
|
283
|
+
- - '>='
|
284
284
|
- !ruby/object:Gem::Version
|
285
285
|
version: '0'
|
286
286
|
type: :development
|
287
287
|
prerelease: false
|
288
288
|
version_requirements: !ruby/object:Gem::Requirement
|
289
289
|
requirements:
|
290
|
-
- -
|
290
|
+
- - '>='
|
291
291
|
- !ruby/object:Gem::Version
|
292
292
|
version: '0'
|
293
293
|
- !ruby/object:Gem::Dependency
|
294
294
|
name: rspec
|
295
295
|
requirement: !ruby/object:Gem::Requirement
|
296
296
|
requirements:
|
297
|
-
- -
|
297
|
+
- - '>='
|
298
298
|
- !ruby/object:Gem::Version
|
299
299
|
version: '0'
|
300
300
|
type: :development
|
301
301
|
prerelease: false
|
302
302
|
version_requirements: !ruby/object:Gem::Requirement
|
303
303
|
requirements:
|
304
|
-
- -
|
304
|
+
- - '>='
|
305
305
|
- !ruby/object:Gem::Version
|
306
306
|
version: '0'
|
307
307
|
- !ruby/object:Gem::Dependency
|
308
308
|
name: sendgrid-ruby
|
309
309
|
requirement: !ruby/object:Gem::Requirement
|
310
310
|
requirements:
|
311
|
-
- -
|
311
|
+
- - '>='
|
312
312
|
- !ruby/object:Gem::Version
|
313
313
|
version: '0'
|
314
314
|
type: :development
|
315
315
|
prerelease: false
|
316
316
|
version_requirements: !ruby/object:Gem::Requirement
|
317
317
|
requirements:
|
318
|
-
- -
|
318
|
+
- - '>='
|
319
319
|
- !ruby/object:Gem::Version
|
320
320
|
version: '0'
|
321
321
|
description: A command line utility to be run in Book repositories to stitch together
|
@@ -326,8 +326,6 @@ executables:
|
|
326
326
|
extensions: []
|
327
327
|
extra_rdoc_files: []
|
328
328
|
files:
|
329
|
-
- bookbinder.gemspec
|
330
|
-
- install_bin/bookbinder
|
331
329
|
- lib/bookbinder/cli.rb
|
332
330
|
- lib/bookbinder/code_example_reader.rb
|
333
331
|
- lib/bookbinder/colorizer.rb
|
@@ -402,22 +400,28 @@ files:
|
|
402
400
|
- lib/bookbinder/values/section.rb
|
403
401
|
- lib/bookbinder/values/subnav_template.rb
|
404
402
|
- lib/bookbinder/values/user_message.rb
|
405
|
-
-
|
406
|
-
- master_middleman/bookbinder_helpers.rb
|
407
|
-
- master_middleman/compass_runner.rb
|
408
|
-
- master_middleman/config.rb
|
409
|
-
- master_middleman/quicklinks_renderer.rb
|
410
|
-
- master_middleman/subdirectory_aware_assets.rb
|
403
|
+
- template_app/config.ru
|
411
404
|
- template_app/Gemfile
|
412
405
|
- template_app/Gemfile.lock
|
413
|
-
- template_app/config.ru
|
414
406
|
- template_app/lib/rack_static_if_exists.rb
|
415
|
-
- template_app/lib/search.rb
|
407
|
+
- template_app/lib/search/handler.rb
|
408
|
+
- template_app/lib/search/hit.rb
|
409
|
+
- template_app/lib/search/query.rb
|
410
|
+
- template_app/lib/search/renderer.rb
|
411
|
+
- template_app/lib/search/result.rb
|
416
412
|
- template_app/lib/server.rb
|
417
413
|
- template_app/mail_sender.rb
|
418
414
|
- template_app/rack_app.rb
|
419
415
|
- template_app/search-results.html.erb
|
420
416
|
- template_app/search.yml
|
417
|
+
- master_middleman/archive_drop_down_menu.rb
|
418
|
+
- master_middleman/bookbinder_helpers.rb
|
419
|
+
- master_middleman/compass_runner.rb
|
420
|
+
- master_middleman/config.rb
|
421
|
+
- master_middleman/quicklinks_renderer.rb
|
422
|
+
- master_middleman/subdirectory_aware_assets.rb
|
423
|
+
- install_bin/bookbinder
|
424
|
+
- bookbinder.gemspec
|
421
425
|
homepage: https://github.com/pivotal-cf/bookbinder
|
422
426
|
licenses:
|
423
427
|
- MIT
|
@@ -428,17 +432,17 @@ require_paths:
|
|
428
432
|
- lib
|
429
433
|
required_ruby_version: !ruby/object:Gem::Requirement
|
430
434
|
requirements:
|
431
|
-
- -
|
435
|
+
- - '>='
|
432
436
|
- !ruby/object:Gem::Version
|
433
437
|
version: 2.0.0
|
434
438
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
435
439
|
requirements:
|
436
|
-
- -
|
440
|
+
- - '>='
|
437
441
|
- !ruby/object:Gem::Version
|
438
442
|
version: '0'
|
439
443
|
requirements: []
|
440
444
|
rubyforge_project:
|
441
|
-
rubygems_version: 2.
|
445
|
+
rubygems_version: 2.0.14
|
442
446
|
signing_key:
|
443
447
|
specification_version: 4
|
444
448
|
summary: Markdown to Rackup application documentation generator
|
data/template_app/lib/search.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'elasticsearch'
|
2
|
-
require 'yaml'
|
3
|
-
require 'erb'
|
4
|
-
|
5
|
-
module Bookbinder
|
6
|
-
module Search
|
7
|
-
def self.call(env)
|
8
|
-
search_data = search(get_search_query(env['QUERY_STRING']), get_page_number(env['QUERY_STRING']))
|
9
|
-
|
10
|
-
erb = ERB.new(File.read(File.expand_path('../../search-results.html.erb', __FILE__)))
|
11
|
-
|
12
|
-
[200, {'Content-Type' => 'text/html'}, [search_data.render(erb)]]
|
13
|
-
rescue Exception => e
|
14
|
-
puts e.message
|
15
|
-
puts e.backtrace.join("\n")
|
16
|
-
|
17
|
-
[500, {'Content-Type' => 'text/plain'}, ['An error occurred']]
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.search(query, page_number)
|
21
|
-
return Result.new(query, 0, [], 1) if query == ''
|
22
|
-
|
23
|
-
query_options = YAML.load_file(File.expand_path('../../search.yml', __FILE__))
|
24
|
-
query_options['from'] = (page_number - 1) * 10
|
25
|
-
query_options['query']['query_string']['query'] = query
|
26
|
-
|
27
|
-
results = search_client.search index: 'searching', body: query_options
|
28
|
-
|
29
|
-
Result.new(
|
30
|
-
query,
|
31
|
-
results['hits']['total'],
|
32
|
-
results['hits']['hits'],
|
33
|
-
page_number
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.get_search_query(query_string)
|
38
|
-
q_param = query_string.split('&').detect { |s| s =~ /\Aq=/ }
|
39
|
-
|
40
|
-
return '' if q_param.nil?
|
41
|
-
|
42
|
-
q_param.split('=')[1] || ''
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.get_page_number(query_string)
|
46
|
-
q_param = query_string.split('&').detect { |s| s =~ /\Apage=/ }
|
47
|
-
|
48
|
-
return 1 if q_param.nil?
|
49
|
-
|
50
|
-
q_param.split('=')[1].to_i || 1
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.search_client
|
54
|
-
Elasticsearch::Client.new url: JSON.parse(ENV['VCAP_SERVICES'])['searchly'][0]['credentials']['uri']
|
55
|
-
end
|
56
|
-
|
57
|
-
Result = Struct.new(:query, :result_count, :search_results, :page_number) do
|
58
|
-
def render(erb)
|
59
|
-
bind = binding
|
60
|
-
render_layout do
|
61
|
-
erb.result(bind)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def last_page
|
66
|
-
(result_count / 10.0).ceil
|
67
|
-
end
|
68
|
-
|
69
|
-
def page_window
|
70
|
-
window_start = [page_number - 2, 1].max
|
71
|
-
window_end = [window_start + 4, last_page].min
|
72
|
-
window = (window_start .. window_end).to_a
|
73
|
-
|
74
|
-
if window.length < 5 && window.last == last_page && window.first != 1
|
75
|
-
window.unshift(window.first - 1)
|
76
|
-
if window.length < 5
|
77
|
-
window.unshift(window.first - 1)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
window
|
82
|
-
end
|
83
|
-
|
84
|
-
def render_layout
|
85
|
-
ERB.new(self.class.layout_content).result(binding)
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.layout_content
|
89
|
-
File.read(File.expand_path('../../public/search.html', __FILE__))
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|