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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11c7ab2f100519423aa8e8b3d7f209bb53f800ff
4
- data.tar.gz: 8b95f5075fb79af6b8e9dbe4f21ffccdcd84e30d
3
+ metadata.gz: d5e7b71a753cfd7cbb99c11b2beb2d43cf7fea1e
4
+ data.tar.gz: ea6520b8bea5845c849ca53a1623c04d3279fbaa
5
5
  SHA512:
6
- metadata.gz: b8ce590ae60e8ac526c04ac42f62c8235dfc4ea05ff762735dc7339c694272aabab6602aac95be592ee7291ac9247ff24cfc9f362133cb61068adbac2699b9da
7
- data.tar.gz: 0862ee6272e546779e1b1332d4b6071211611f157f3a2acff2a096abb9cdabf4d58f526077ba079ddc922a912f0ec90ca540eb59f5e9105c77477cc9d6c95124
6
+ metadata.gz: 6b3f3af6783dc22bb73b7deb0df1a1f7f5339dcee1630a9a87afb4e68db954f24d87c996c7e1e59065ff3a554b87551770b8be081c82924d5c67404d756f57ee
7
+ data.tar.gz: 573b1a2f0262ff4a3c72e89b275e97a32e6c3acb20cdde45636320f43b11d3af0df7110e97456aa1f7ab697f98c9aa8ed7113e11046812819a60ee5968a9f237
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bookbindery'
5
- s.version = '9.0.0'
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.3.0'
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((name))
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
  )
@@ -91,6 +91,10 @@ module Bookbinder
91
91
  !!config[key.to_sym]
92
92
  end
93
93
 
94
+ def elastic_search?
95
+ config.fetch(:elastic_search, false)
96
+ end
97
+
94
98
  def ==(o)
95
99
  o.class == self.class && o.instance_variable_get(:@config) == @config
96
100
  end
@@ -94,9 +94,9 @@ module Bookbinder
94
94
  end
95
95
 
96
96
  def find_files_extension_agnostically(pattern, directory='.')
97
- extensionless_pattern = pattern.to_s.split('.').first
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))
@@ -39,6 +39,10 @@ module Bookbinder
39
39
  snippet.prepend("#{delimiter}#{language}\n").concat("\n#{delimiter}")
40
40
  end
41
41
 
42
+ def elastic_search?
43
+ !!config[:elastic_search]
44
+ end
45
+
42
46
  def yield_for_subnav
43
47
  partial "subnavs/#{subnav_template_name}"
44
48
  end
@@ -7,3 +7,4 @@ gem 'rack-rewrite'
7
7
  gem 'puma'
8
8
  gem 'therubyracer'
9
9
  gem 'sendgrid-ruby'
10
+ gem 'elasticsearch'
@@ -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
@@ -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>
@@ -0,0 +1,14 @@
1
+ ---
2
+ query:
3
+ query_string:
4
+ query: ''
5
+ default_field: text
6
+ from: 0
7
+ size: 10
8
+ _source:
9
+ - url
10
+ - title
11
+ highlight:
12
+ fields:
13
+ text:
14
+ type: plain
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.0.0
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-14 00:00:00.000000000 Z
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.3.0
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.6.3
441
+ rubygems_version: 2.5.1
425
442
  signing_key:
426
443
  specification_version: 4
427
444
  summary: Markdown to Rackup application documentation generator