bookbindery 9.0.0 → 9.2.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 +3 -2
- data/lib/bookbinder/commands/generate.rb +13 -6
- data/lib/bookbinder/config/configuration.rb +4 -0
- data/lib/bookbinder/local_filesystem_accessor.rb +2 -2
- data/lib/bookbinder/middleman_runner.rb +2 -1
- data/master_middleman/bookbinder_helpers.rb +4 -0
- data/template_app/Gemfile +1 -0
- data/template_app/Gemfile.lock +10 -0
- data/template_app/lib/search.rb +93 -0
- data/template_app/rack_app.rb +4 -0
- data/template_app/search-results.html.erb +48 -0
- data/template_app/search.yml +14 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5e7b71a753cfd7cbb99c11b2beb2d43cf7fea1e
|
4
|
+
data.tar.gz: ea6520b8bea5845c849ca53a1623c04d3279fbaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3f3af6783dc22bb73b7deb0df1a1f7f5339dcee1630a9a87afb4e68db954f24d87c996c7e1e59065ff3a554b87551770b8be081c82924d5c67404d756f57ee
|
7
|
+
data.tar.gz: 573b1a2f0262ff4a3c72e89b275e97a32e6c3acb20cdde45636320f43b11d3af0df7110e97456aa1f7ab697f98c9aa8ed7113e11046812819a60ee5968a9f237
|
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.2.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']
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.bindir = 'install_bin'
|
15
15
|
s.executable = 'bookbinder'
|
16
16
|
|
17
|
-
s.required_ruby_version = '~> 2.
|
17
|
+
s.required_ruby_version = '~> 2.0.0'
|
18
18
|
s.add_runtime_dependency 'fog-aws', ['~> 0.7.1']
|
19
19
|
s.add_runtime_dependency 'ansi', ['~> 1.4']
|
20
20
|
s.add_runtime_dependency 'middleman', ['~> 3.4.0']
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_runtime_dependency 'git', '~> 1.2.8'
|
31
31
|
s.add_runtime_dependency 'nokogiri', ['1.6.7.2']
|
32
32
|
s.add_runtime_dependency 'thor'
|
33
|
+
s.add_runtime_dependency 'elasticsearch'
|
33
34
|
|
34
35
|
s.add_development_dependency 'license_finder'
|
35
36
|
s.add_development_dependency 'pry-byebug'
|
@@ -10,13 +10,13 @@ module Bookbinder
|
|
10
10
|
@streams = streams
|
11
11
|
end
|
12
12
|
|
13
|
-
def run(
|
13
|
+
def run(name, special_bookbinder_gem_args={})
|
14
14
|
path = context_dir.join(name)
|
15
15
|
streams[:out].puts "Generating book at #{path}…"
|
16
16
|
if fs.file_exist?(path)
|
17
17
|
streams[:err].puts "Cannot generate book: directory already exists"
|
18
18
|
1
|
19
|
-
elsif install(path).success?
|
19
|
+
elsif install(path, special_bookbinder_gem_args).success?
|
20
20
|
streams[:success].puts "Successfully generated book at #{path}"
|
21
21
|
0
|
22
22
|
else
|
@@ -28,9 +28,9 @@ module Bookbinder
|
|
28
28
|
|
29
29
|
attr_reader :fs, :sheller, :streams
|
30
30
|
|
31
|
-
def install(path)
|
31
|
+
def install(path, special_bookbinder_gem_args)
|
32
32
|
make_middleman_dir(path)
|
33
|
-
init_gemfile(path)
|
33
|
+
init_gemfile(path, special_bookbinder_gem_args)
|
34
34
|
init_config(path)
|
35
35
|
init_index(path)
|
36
36
|
bundle_install(path)
|
@@ -40,12 +40,19 @@ module Bookbinder
|
|
40
40
|
fs.make_directory(path.join('master_middleman/build'))
|
41
41
|
end
|
42
42
|
|
43
|
-
def init_gemfile(path)
|
43
|
+
def init_gemfile(path, special_bookbinder_gem_args)
|
44
|
+
bookbinder_config = ''
|
45
|
+
|
46
|
+
unless special_bookbinder_gem_args.empty?
|
47
|
+
config = special_bookbinder_gem_args.first
|
48
|
+
bookbinder_config = ", #{config.first}: \"#{config.last}\""
|
49
|
+
end
|
50
|
+
|
44
51
|
fs.write(
|
45
52
|
text: <<-GEMFILE,
|
46
53
|
source "https://rubygems.org"
|
47
54
|
|
48
|
-
gem "bookbindery"
|
55
|
+
gem "bookbindery"#{bookbinder_config}
|
49
56
|
GEMFILE
|
50
57
|
to: path.join('Gemfile')
|
51
58
|
)
|
@@ -94,9 +94,9 @@ module Bookbinder
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def find_files_extension_agnostically(pattern, directory='.')
|
97
|
-
extensionless_pattern = pattern.
|
97
|
+
extensionless_pattern = File.join(File.dirname(pattern), File.basename(pattern).split('.').first)
|
98
98
|
|
99
|
-
`find -L #{directory} -path '*/#{extensionless_pattern}.*'`.
|
99
|
+
`find -L #{directory} -path '*/#{extensionless_pattern}.*' -type f`.
|
100
100
|
lines.
|
101
101
|
map(&:chomp).
|
102
102
|
map(&Pathname.method(:new))
|
@@ -29,7 +29,8 @@ module Bookbinder
|
|
29
29
|
feedback_enabled: config.feedback_enabled,
|
30
30
|
repo_link_enabled: config.repo_link_enabled,
|
31
31
|
repo_links: config.repo_links,
|
32
|
-
product_info: product_info
|
32
|
+
product_info: product_info,
|
33
|
+
elastic_search: config.elastic_search?
|
33
34
|
}
|
34
35
|
|
35
36
|
fs.write(to: "bookbinder_config.yml", text: YAML.dump(config))
|
data/template_app/Gemfile
CHANGED
data/template_app/Gemfile.lock
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
elasticsearch (1.0.17)
|
5
|
+
elasticsearch-api (= 1.0.17)
|
6
|
+
elasticsearch-transport (= 1.0.17)
|
7
|
+
elasticsearch-api (1.0.17)
|
8
|
+
multi_json
|
9
|
+
elasticsearch-transport (1.0.17)
|
10
|
+
faraday
|
11
|
+
multi_json
|
4
12
|
faraday (0.9.2)
|
5
13
|
multipart-post (>= 1.2, < 3)
|
6
14
|
libv8 (3.16.14.7)
|
7
15
|
mimemagic (0.3.0)
|
16
|
+
multi_json (1.11.2)
|
8
17
|
multipart-post (2.0.0)
|
9
18
|
puma (3.3.0)
|
10
19
|
rack (1.5.2)
|
@@ -23,6 +32,7 @@ PLATFORMS
|
|
23
32
|
ruby
|
24
33
|
|
25
34
|
DEPENDENCIES
|
35
|
+
elasticsearch
|
26
36
|
puma
|
27
37
|
rack
|
28
38
|
rack-rewrite
|
@@ -0,0 +1,93 @@
|
|
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
|
data/template_app/rack_app.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rack'
|
2
2
|
require 'rack/rewrite'
|
3
3
|
require_relative './lib/server'
|
4
|
+
require_relative './lib/search'
|
4
5
|
|
5
6
|
module Bookbinder
|
6
7
|
class RackApp
|
@@ -21,6 +22,9 @@ module Bookbinder
|
|
21
22
|
use MailFeedback, client
|
22
23
|
run Bookbinder::NotFound.new('public/404.html')
|
23
24
|
end
|
25
|
+
map '/search' do
|
26
|
+
run Bookbinder::Search
|
27
|
+
end
|
24
28
|
if ENV['CUSTOM_ROOT']
|
25
29
|
map ENV['CUSTOM_ROOT'] do
|
26
30
|
run Bookbinder::Server
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<div class="search-results">
|
2
|
+
<form method="get">
|
3
|
+
<input name="q" value="<%= query %>"/>
|
4
|
+
</form>
|
5
|
+
|
6
|
+
<% if result_count == 0 %>
|
7
|
+
<div class="no-results">No Results</div>
|
8
|
+
<% else %>
|
9
|
+
<div class="result-summary">
|
10
|
+
Showing <%= (page_number - 1) * 10 + 1 %> to <%= [(page_number - 1) * 10 + 10, result_count].min %> of <%= result_count %> results.
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<ul class="search-results-list">
|
14
|
+
<% search_results.each do |result| %>
|
15
|
+
<li>
|
16
|
+
<a href="<%= result['_source']['url'] %>"><%= result['_source']['title'] %></a>
|
17
|
+
<div><%= result['highlight']['text'].first.strip %></div>
|
18
|
+
</li>
|
19
|
+
<% end %>
|
20
|
+
</ul>
|
21
|
+
|
22
|
+
<div class="pagination">
|
23
|
+
<% if page_number == 1 %>
|
24
|
+
<span class="disabled page first">First</span>
|
25
|
+
<span class="disabled page previous">Prev</span>
|
26
|
+
<% else %>
|
27
|
+
<a class="page first" href="/search?q=<%= query %>">First</a>
|
28
|
+
<a class="page previous" href="/search?q=<%= query %>&page=<%= page_number - 1 %>">Prev</a>
|
29
|
+
<% end %>
|
30
|
+
|
31
|
+
<% page_window.each do |page| %>
|
32
|
+
<% if page == page_number %>
|
33
|
+
<span class="current page"><%= page %></span>
|
34
|
+
<% else %>
|
35
|
+
<a class="page" href="/search?q=<%= query %>&page=<%= page %>"><%= page %></a>
|
36
|
+
<% end %>
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<% if page_number == last_page %>
|
40
|
+
<span class="disabled page next">Next</span>
|
41
|
+
<span class="disabled page last">Last</span>
|
42
|
+
<% else %>
|
43
|
+
<a class="page next" href="/search?q=<%= query %>&page=<%= page_number + 1 %>">Next</a>
|
44
|
+
<a class="page last" href="/search?q=<%= query %>&page=<%= last_page %>">Last</a>
|
45
|
+
<% end %>
|
46
|
+
</div>
|
47
|
+
<% end %>
|
48
|
+
</div>
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Grafton
|
@@ -22,7 +22,7 @@ authors:
|
|
22
22
|
autorequire:
|
23
23
|
bindir: install_bin
|
24
24
|
cert_chain: []
|
25
|
-
date: 2016-04-
|
25
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
26
26
|
dependencies:
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fog-aws
|
@@ -234,6 +234,20 @@ dependencies:
|
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: elasticsearch
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :runtime
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
237
251
|
- !ruby/object:Gem::Dependency
|
238
252
|
name: license_finder
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
@@ -398,9 +412,12 @@ files:
|
|
398
412
|
- template_app/Gemfile.lock
|
399
413
|
- template_app/config.ru
|
400
414
|
- template_app/lib/rack_static_if_exists.rb
|
415
|
+
- template_app/lib/search.rb
|
401
416
|
- template_app/lib/server.rb
|
402
417
|
- template_app/mail_sender.rb
|
403
418
|
- template_app/rack_app.rb
|
419
|
+
- template_app/search-results.html.erb
|
420
|
+
- template_app/search.yml
|
404
421
|
homepage: https://github.com/pivotal-cf/bookbinder
|
405
422
|
licenses:
|
406
423
|
- MIT
|
@@ -413,7 +430,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
413
430
|
requirements:
|
414
431
|
- - "~>"
|
415
432
|
- !ruby/object:Gem::Version
|
416
|
-
version: 2.
|
433
|
+
version: 2.0.0
|
417
434
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
418
435
|
requirements:
|
419
436
|
- - ">="
|
@@ -421,7 +438,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
421
438
|
version: '0'
|
422
439
|
requirements: []
|
423
440
|
rubyforge_project:
|
424
|
-
rubygems_version: 2.
|
441
|
+
rubygems_version: 2.5.1
|
425
442
|
signing_key:
|
426
443
|
specification_version: 4
|
427
444
|
summary: Markdown to Rackup application documentation generator
|