bookbindery 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bookbinder/archive.rb +1 -1
  3. data/lib/bookbinder/archive_menu_configuration.rb +34 -0
  4. data/lib/bookbinder/book.rb +17 -17
  5. data/lib/bookbinder/cli.rb +25 -36
  6. data/lib/bookbinder/code_example.rb +5 -38
  7. data/lib/bookbinder/code_example_reader.rb +40 -0
  8. data/lib/bookbinder/colorizer.rb +14 -0
  9. data/lib/bookbinder/command_runner.rb +9 -16
  10. data/lib/bookbinder/command_validator.rb +14 -7
  11. data/lib/bookbinder/commands/bind.rb +321 -0
  12. data/lib/bookbinder/commands/build_and_push_tarball.rb +7 -6
  13. data/lib/bookbinder/commands/chain.rb +11 -0
  14. data/lib/bookbinder/commands/generate_pdf.rb +4 -3
  15. data/lib/bookbinder/commands/help.rb +49 -10
  16. data/lib/bookbinder/commands/naming.rb +9 -1
  17. data/lib/bookbinder/commands/push_local_to_staging.rb +4 -3
  18. data/lib/bookbinder/commands/push_to_prod.rb +36 -4
  19. data/lib/bookbinder/commands/run_publish_ci.rb +21 -24
  20. data/lib/bookbinder/commands/tag.rb +3 -3
  21. data/lib/bookbinder/commands/update_local_doc_repos.rb +5 -4
  22. data/lib/bookbinder/commands/version.rb +11 -8
  23. data/lib/bookbinder/configuration.rb +8 -3
  24. data/lib/bookbinder/configuration_fetcher.rb +7 -25
  25. data/lib/bookbinder/configuration_validator.rb +21 -0
  26. data/lib/bookbinder/distributor.rb +1 -1
  27. data/lib/bookbinder/dita_html_to_middleman_formatter.rb +37 -0
  28. data/lib/bookbinder/dita_section.rb +7 -0
  29. data/lib/bookbinder/dita_section_gatherer.rb +28 -0
  30. data/lib/bookbinder/git_accessor.rb +17 -0
  31. data/lib/bookbinder/git_client.rb +10 -7
  32. data/lib/bookbinder/git_hub_repository.rb +46 -41
  33. data/lib/bookbinder/local_dita_preprocessor.rb +27 -0
  34. data/lib/bookbinder/local_dita_to_html_converter.rb +49 -0
  35. data/lib/bookbinder/local_file_system_accessor.rb +68 -0
  36. data/lib/bookbinder/middleman_runner.rb +30 -17
  37. data/lib/bookbinder/pdf_generator.rb +1 -1
  38. data/lib/bookbinder/publisher.rb +16 -80
  39. data/lib/bookbinder/remote_yaml_credential_provider.rb +2 -3
  40. data/lib/bookbinder/repositories/command_repository.rb +156 -0
  41. data/lib/bookbinder/repositories/section_repository.rb +31 -0
  42. data/lib/bookbinder/section.rb +5 -67
  43. data/lib/bookbinder/shell_out.rb +1 -0
  44. data/lib/bookbinder/sheller.rb +19 -0
  45. data/lib/bookbinder/sieve.rb +6 -1
  46. data/lib/bookbinder/stabilimentum.rb +5 -1
  47. data/lib/bookbinder/terminal.rb +10 -0
  48. data/lib/bookbinder/user_message.rb +6 -0
  49. data/lib/bookbinder/user_message_presenter.rb +21 -0
  50. data/lib/bookbinder/yaml_loader.rb +18 -7
  51. data/lib/bookbinder.rb +2 -9
  52. data/master_middleman/archive_drop_down_menu.rb +46 -0
  53. data/master_middleman/bookbinder_helpers.rb +47 -40
  54. data/master_middleman/quicklinks_renderer.rb +1 -1
  55. metadata +33 -87
  56. data/lib/bookbinder/commands/publish.rb +0 -138
  57. data/lib/bookbinder/usage_messenger.rb +0 -33
  58. /data/{bin → install_bin}/bookbinder +0 -0
data/lib/bookbinder.rb CHANGED
@@ -1,10 +1,7 @@
1
- require 'fog'
1
+ require 'fog/aws'
2
2
  require 'tmpdir'
3
3
  require 'ansi'
4
- require 'faraday'
5
- require 'faraday_middleware'
6
4
  require 'octokit'
7
- require 'padrino-contrib'
8
5
  require 'middleman-syntax'
9
6
  require 'middleman-core/cli'
10
7
  require 'middleman-core/profiling'
@@ -14,10 +11,8 @@ require 'vienna'
14
11
  require 'popen4'
15
12
  require 'puma'
16
13
 
17
- #require_relative 'bookbinder/shell_out'
18
14
  require_relative 'bookbinder/bookbinder_logger'
19
15
  require_relative 'bookbinder/git_client'
20
- #require_relative 'bookbinder/repository'
21
16
  require_relative 'bookbinder/section'
22
17
  require_relative 'bookbinder/book'
23
18
  require_relative 'bookbinder/code_example'
@@ -43,7 +38,7 @@ require_relative 'bookbinder/distributor'
43
38
 
44
39
  require_relative 'bookbinder/commands/bookbinder_command'
45
40
  require_relative 'bookbinder/commands/build_and_push_tarball'
46
- require_relative 'bookbinder/commands/publish'
41
+ require_relative 'bookbinder/commands/bind'
47
42
  require_relative 'bookbinder/commands/push_local_to_staging'
48
43
  require_relative 'bookbinder/commands/push_to_prod'
49
44
  require_relative 'bookbinder/commands/run_publish_ci'
@@ -51,8 +46,6 @@ require_relative 'bookbinder/commands/update_local_doc_repos'
51
46
  require_relative 'bookbinder/commands/tag'
52
47
  require_relative 'bookbinder/commands/generate_pdf'
53
48
 
54
- require_relative 'bookbinder/usage_messenger'
55
-
56
49
  require_relative 'bookbinder/cli'
57
50
 
58
51
  # Finds the project root for both spec & production
@@ -0,0 +1,46 @@
1
+ module Bookbinder
2
+ class ArchiveDropDownMenu
3
+ def initialize(config, current_path: nil)
4
+ @config = config || default_config
5
+ @current_path = current_path
6
+ end
7
+
8
+ def title
9
+ directory_config.first
10
+ end
11
+
12
+ def dropdown_links
13
+ versions_to_paths.map { |version_path|
14
+ {version_path.keys.first => "/#{version_path.values.first}"}
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :config, :current_path
21
+
22
+ def versions_to_paths
23
+ directory_config[1..-1]
24
+ end
25
+
26
+ def directory_config
27
+ config.fetch(directory, config.fetch(root_menu_reference)) || empty_menu
28
+ end
29
+
30
+ def directory
31
+ File.dirname(current_path)
32
+ end
33
+
34
+ def default_config
35
+ { root_menu_reference => empty_menu }
36
+ end
37
+
38
+ def empty_menu
39
+ [nil]
40
+ end
41
+
42
+ def root_menu_reference
43
+ '.'
44
+ end
45
+ end
46
+ end
@@ -1,15 +1,9 @@
1
1
  require 'date'
2
- # mostly from https://github.com/multiscan/middleman-navigation but modified slightly
2
+ require_relative 'archive_drop_down_menu'
3
3
  require_relative 'quicklinks_renderer'
4
4
 
5
5
  I18n.enforce_available_locales = false
6
6
 
7
- class ArchiveMenuTemplateNotFound < StandardError;
8
- end
9
-
10
- class ArchiveConfigFormatError < StandardError;
11
- end
12
-
13
7
  module Bookbinder
14
8
  module Navigation
15
9
  class << self
@@ -23,8 +17,44 @@ module Bookbinder
23
17
  module HelperMethods
24
18
 
25
19
  def yield_for_code_snippet(from: nil, at: nil)
26
- example = CodeExample.get_instance(bookbinder_logger, section_hash: {'repository' => {'name' => from}}, local_repo_dir: config[:local_repo_dir], git_accessor: config[:git_accessor])
27
- snippet, language = example.get_snippet_and_language_at(at)
20
+ git_accessor = config[:git_accessor]
21
+ local_repo_dir = config[:local_repo_dir]
22
+ attributes = {'repository' => {'name' => from}}
23
+ workspace = config[:workspace]
24
+ code_example_reader = CodeExampleReader.new(bookbinder_logger)
25
+
26
+ vcs_repo =
27
+ if local_repo_dir
28
+ GitHubRepository.
29
+ build_from_local(bookbinder_logger,
30
+ attributes,
31
+ local_repo_dir,
32
+ git_accessor).
33
+ tap { |repo| repo.copy_from_local(workspace) }
34
+ else
35
+ GitHubRepository.
36
+ build_from_remote(bookbinder_logger, attributes, nil, git_accessor).
37
+ tap { |repo| repo.copy_from_remote(workspace) }
38
+ end
39
+ example = code_example_repo.get_instance(attributes,
40
+ vcs_repo: vcs_repo,
41
+ build: ->(path_to_repository,
42
+ full_name,
43
+ copied,
44
+ _,
45
+ destination_dir,
46
+ directory_name) {
47
+ CodeExample.new(path_to_repository,
48
+ full_name,
49
+ copied,
50
+ destination_dir,
51
+ directory_name)
52
+ })
53
+ snippet, language = code_example_reader.get_snippet_and_language_at(at,
54
+ example.path_to_repository,
55
+ example.copied,
56
+ example.full_name)
57
+
28
58
  delimiter = '```'
29
59
 
30
60
  snippet.prepend("#{delimiter}#{language}\n").concat("\n#{delimiter}")
@@ -43,20 +73,13 @@ module Bookbinder
43
73
  end
44
74
 
45
75
  def yield_for_archive_drop_down_menu
46
- if config.respond_to?(:archive_menu)
47
- title = config[:archive_menu].first
48
- links = config[:archive_menu][1..-1]
49
-
50
- new_links_based_from_root = links.map do |link|
51
- link_from_root = link.dup
52
- link_from_root.map do |k, v|
53
- link_from_root[k] = "/#{v}"
54
- end
55
- link_from_root
56
- end
76
+ menu = ArchiveDropDownMenu.new(
77
+ config[:archive_menu],
78
+ current_path: current_page.path
79
+ )
57
80
 
58
- partial 'archive_menus/default', locals: { menu_title: title, dropdown_links: new_links_based_from_root }
59
- end
81
+ partial 'archive_menus/default', locals: { menu_title: menu.title,
82
+ dropdown_links: menu.dropdown_links }
60
83
  end
61
84
 
62
85
  def breadcrumbs
@@ -72,13 +95,6 @@ module Bookbinder
72
95
  OpenStruct.new config[:template_variables]
73
96
  end
74
97
 
75
- def modified_date(format=nil)
76
- current_file_in_repo = current_path.dup.gsub(File.basename(current_path), File.basename(current_page.source_file))
77
- current_section = get_section_or_book_for(current_file_in_repo)
78
- modified_time = current_section.get_modification_date_for(file: current_file_in_repo, full_path: current_page.source_file)
79
- (format.nil? ? modified_time : modified_time.strftime(format))
80
- end
81
-
82
98
  def quick_links
83
99
  page_src = File.read(current_page.source_file)
84
100
  quicklinks_renderer = QuicklinksRenderer.new(vars)
@@ -87,17 +103,8 @@ module Bookbinder
87
103
 
88
104
  private
89
105
 
90
- def get_section_or_book_for(path)
91
- sections = config[:sections]
92
- book = config[:book]
93
-
94
- raise "Book or Selections are incorrectly specified for Middleman." if book.nil? || sections.nil?
95
-
96
- current_section = nil
97
- sections.each { |section| current_section = section if File.dirname(current_path).match(/^#{section.directory}/) }
98
-
99
- return book if current_section.nil?
100
- return current_section
106
+ def code_example_repo
107
+ @code_example_repo ||= Repositories::SectionRepository.new(bookbinder_logger)
101
108
  end
102
109
 
103
110
  def index_subnav
@@ -30,7 +30,7 @@ class QuicklinksRenderer < Redcarpet::Render::Base
30
30
  @items[header_level] = li
31
31
  nil
32
32
  rescue BadHeadingLevelError => e
33
- raise BadHeadingLevelError.new "The header \"#{text}\", which is at level #{e.message} has no higher-level headers occuring before it."
33
+ raise BadHeadingLevelError.new "The header \"#{text}\", which is at level #{e.message}, has no higher-level headers occurring before it."
34
34
  end
35
35
 
36
36
  private
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: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Grafton
@@ -13,24 +13,24 @@ authors:
13
13
  - Matthew Boedicker
14
14
  - Frank Kotsianas
15
15
  autorequire:
16
- bindir: bin
16
+ bindir: install_bin
17
17
  cert_chain: []
18
- date: 2015-01-08 00:00:00.000000000 Z
18
+ date: 2015-02-17 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: fog
21
+ name: fog-aws
22
22
  requirement: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: 0.0.6
27
27
  type: :runtime
28
28
  prerelease: false
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.17'
33
+ version: 0.0.6
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: octokit
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -73,20 +73,6 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.1'
76
- - !ruby/object:Gem::Dependency
77
- name: padrino-contrib
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- type: :runtime
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
76
  - !ruby/object:Gem::Dependency
91
77
  name: middleman
92
78
  requirement: !ruby/object:Gem::Requirement
@@ -157,34 +143,6 @@ dependencies:
157
143
  - - '='
158
144
  - !ruby/object:Gem::Version
159
145
  version: 0.12.3
160
- - !ruby/object:Gem::Dependency
161
- name: faraday
162
- requirement: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 0.8.8
167
- type: :runtime
168
- prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 0.8.8
174
- - !ruby/object:Gem::Dependency
175
- name: faraday_middleware
176
- requirement: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 0.9.0
181
- type: :runtime
182
- prerelease: false
183
- version_requirements: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: 0.9.0
188
146
  - !ruby/object:Gem::Dependency
189
147
  name: anemone
190
148
  requirement: !ruby/object:Gem::Requirement
@@ -255,20 +213,6 @@ dependencies:
255
213
  - - ">="
256
214
  - !ruby/object:Gem::Version
257
215
  version: '0'
258
- - !ruby/object:Gem::Dependency
259
- name: ruby-progressbar
260
- requirement: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - ">="
263
- - !ruby/object:Gem::Version
264
- version: '0'
265
- type: :runtime
266
- prerelease: false
267
- version_requirements: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - ">="
270
- - !ruby/object:Gem::Version
271
- version: '0'
272
216
  - !ruby/object:Gem::Dependency
273
217
  name: therubyracer
274
218
  requirement: !ruby/object:Gem::Requirement
@@ -353,20 +297,6 @@ dependencies:
353
297
  - - ">="
354
298
  - !ruby/object:Gem::Version
355
299
  version: '0'
356
- - !ruby/object:Gem::Dependency
357
- name: webmock
358
- requirement: !ruby/object:Gem::Requirement
359
- requirements:
360
- - - ">="
361
- - !ruby/object:Gem::Version
362
- version: '0'
363
- type: :development
364
- prerelease: false
365
- version_requirements: !ruby/object:Gem::Requirement
366
- requirements:
367
- - - ">="
368
- - !ruby/object:Gem::Version
369
- version: '0'
370
300
  description: A command line utility to be run in Book repositories to stitch together
371
301
  their constituent Markdown repos into a static-HTML-serving application
372
302
  email: gmorgan@gopivotal.com
@@ -375,10 +305,9 @@ executables:
375
305
  extensions: []
376
306
  extra_rdoc_files: []
377
307
  files:
378
- - bin/bookbinder
379
- - lib/bookbinder.rb
380
308
  - lib/bookbinder/app_fetcher.rb
381
309
  - lib/bookbinder/archive.rb
310
+ - lib/bookbinder/archive_menu_configuration.rb
382
311
  - lib/bookbinder/artifact_namer.rb
383
312
  - lib/bookbinder/blue_green_app.rb
384
313
  - lib/bookbinder/book.rb
@@ -388,14 +317,17 @@ files:
388
317
  - lib/bookbinder/cli.rb
389
318
  - lib/bookbinder/cli_error.rb
390
319
  - lib/bookbinder/code_example.rb
320
+ - lib/bookbinder/code_example_reader.rb
321
+ - lib/bookbinder/colorizer.rb
391
322
  - lib/bookbinder/command_runner.rb
392
323
  - lib/bookbinder/command_validator.rb
324
+ - lib/bookbinder/commands/bind.rb
393
325
  - lib/bookbinder/commands/bookbinder_command.rb
394
326
  - lib/bookbinder/commands/build_and_push_tarball.rb
327
+ - lib/bookbinder/commands/chain.rb
395
328
  - lib/bookbinder/commands/generate_pdf.rb
396
329
  - lib/bookbinder/commands/help.rb
397
330
  - lib/bookbinder/commands/naming.rb
398
- - lib/bookbinder/commands/publish.rb
399
331
  - lib/bookbinder/commands/push_local_to_staging.rb
400
332
  - lib/bookbinder/commands/push_to_prod.rb
401
333
  - lib/bookbinder/commands/run_publish_ci.rb
@@ -408,33 +340,47 @@ files:
408
340
  - lib/bookbinder/css_link_checker.rb
409
341
  - lib/bookbinder/directory_helpers.rb
410
342
  - lib/bookbinder/distributor.rb
343
+ - lib/bookbinder/dita_html_to_middleman_formatter.rb
344
+ - lib/bookbinder/dita_section.rb
345
+ - lib/bookbinder/dita_section_gatherer.rb
346
+ - lib/bookbinder/git_accessor.rb
411
347
  - lib/bookbinder/git_client.rb
412
348
  - lib/bookbinder/git_hub_repository.rb
349
+ - lib/bookbinder/local_dita_preprocessor.rb
350
+ - lib/bookbinder/local_dita_to_html_converter.rb
413
351
  - lib/bookbinder/local_file_system_accessor.rb
414
352
  - lib/bookbinder/middleman_runner.rb
415
353
  - lib/bookbinder/pdf_generator.rb
416
354
  - lib/bookbinder/publisher.rb
417
355
  - lib/bookbinder/pusher.rb
418
356
  - lib/bookbinder/remote_yaml_credential_provider.rb
357
+ - lib/bookbinder/repositories/command_repository.rb
358
+ - lib/bookbinder/repositories/section_repository.rb
419
359
  - lib/bookbinder/section.rb
420
360
  - lib/bookbinder/server_director.rb
421
361
  - lib/bookbinder/shell_out.rb
362
+ - lib/bookbinder/sheller.rb
422
363
  - lib/bookbinder/sieve.rb
423
364
  - lib/bookbinder/sitemap_generator.rb
424
365
  - lib/bookbinder/spider.rb
425
366
  - lib/bookbinder/stabilimentum.rb
426
- - lib/bookbinder/usage_messenger.rb
367
+ - lib/bookbinder/terminal.rb
368
+ - lib/bookbinder/user_message.rb
369
+ - lib/bookbinder/user_message_presenter.rb
427
370
  - lib/bookbinder/yaml_loader.rb
428
- - master_middleman/bookbinder_helpers.rb
429
- - master_middleman/config.rb
430
- - master_middleman/quicklinks_renderer.rb
431
- - master_middleman/submodule_aware_assets.rb
432
- - template_app/Gemfile
433
- - template_app/Gemfile.lock
371
+ - lib/bookbinder.rb
434
372
  - template_app/app.rb
435
373
  - template_app/config.ru
374
+ - template_app/Gemfile
375
+ - template_app/Gemfile.lock
436
376
  - template_app/lib/rack_static.rb
437
377
  - template_app/lib/vienna_application.rb
378
+ - master_middleman/archive_drop_down_menu.rb
379
+ - master_middleman/bookbinder_helpers.rb
380
+ - master_middleman/config.rb
381
+ - master_middleman/quicklinks_renderer.rb
382
+ - master_middleman/submodule_aware_assets.rb
383
+ - install_bin/bookbinder
438
384
  homepage: https://github.com/cloudfoundry-incubator/bookbinder
439
385
  licenses:
440
386
  - MIT
@@ -455,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
455
401
  version: '0'
456
402
  requirements: []
457
403
  rubyforge_project:
458
- rubygems_version: 2.4.1
404
+ rubygems_version: 2.0.14
459
405
  signing_key:
460
406
  specification_version: 4
461
407
  summary: Markdown to Rackup application documentation generator
@@ -1,138 +0,0 @@
1
- require_relative '../book'
2
- require_relative '../cli_error'
3
- require_relative '../configuration'
4
- require_relative '../directory_helpers'
5
- require_relative '../middleman_runner'
6
- require_relative '../publisher'
7
- require_relative '../spider'
8
- require_relative 'bookbinder_command'
9
- require_relative 'naming'
10
-
11
- module Bookbinder
12
- module Commands
13
- class Publish < BookbinderCommand
14
- VersionUnsupportedError = Class.new(StandardError)
15
-
16
- include Bookbinder::DirectoryHelperMethods
17
- extend Commands::Naming
18
-
19
- def self.usage
20
- "publish <local|github> [--verbose] \t Bind the sections specified in config.yml from <local> or <github> into the final_app directory"
21
- end
22
-
23
- def run(cli_arguments, git_accessor=Git)
24
- raise CliError::InvalidArguments unless arguments_are_valid?(cli_arguments)
25
- @git_accessor = git_accessor
26
-
27
- final_app_dir = File.absolute_path('final_app')
28
- bind_book(cli_arguments, final_app_dir)
29
- end
30
-
31
- private
32
-
33
- def bind_book(cli_arguments, final_app_dir)
34
- generate_site_etc(cli_arguments, final_app_dir)
35
- end
36
-
37
- def generate_site_etc(cli_args, final_app_dir, target_tag=nil)
38
- # TODO: general solution to turn all string keys to symbols
39
- verbosity = cli_args.include?('--verbose')
40
- location = cli_args[0]
41
-
42
- cli_options = { verbose: verbosity, target_tag: target_tag }
43
- output_paths = output_directory_paths(location, final_app_dir)
44
- publish_config = publish_config(location)
45
- spider = Spider.new(@logger, app_dir: final_app_dir)
46
- static_site_generator = MiddlemanRunner.new(@logger)
47
-
48
- success = Publisher.new(@logger, spider, static_site_generator).publish(cli_options, output_paths, publish_config, @git_accessor)
49
- success ? 0 : 1
50
- end
51
-
52
- def output_directory_paths(location, final_app_dir)
53
- local_repo_dir = (location == 'local') ? File.absolute_path('..') : nil
54
-
55
- {
56
- final_app_dir: final_app_dir,
57
- local_repo_dir: local_repo_dir,
58
- output_dir: File.absolute_path(output_dir_name),
59
- master_middleman_dir: layout_repo_path(local_repo_dir)
60
- }
61
- end
62
-
63
- def publish_config(location)
64
- arguments = {
65
- sections: config.sections,
66
- book_repo: config.book_repo,
67
- host_for_sitemap: config.public_host,
68
- archive_menu: config.archive_menu
69
- }
70
-
71
- optional_arguments = {}
72
- optional_arguments.merge!(template_variables: config.template_variables) if config.respond_to?(:template_variables)
73
- if publishing_to_github? location
74
- config.versions.each { |version| arguments[:sections].concat sections_from version, @git_accessor }
75
- optional_arguments.merge!(versions: config.versions)
76
- end
77
-
78
- arguments.merge! optional_arguments
79
- end
80
-
81
- def sections_from(version, git_accessor)
82
- config_file = File.join book_checkout(version, git_accessor), 'config.yml'
83
- attrs = YAML.load(File.read(config_file))['sections']
84
- raise VersionUnsupportedError.new(version) if attrs.nil?
85
-
86
- attrs.map do |section_hash|
87
- section_hash['repository']['ref'] = version
88
- section_hash['directory'] = File.join(version, section_hash['directory'])
89
- section_hash
90
- end
91
- end
92
-
93
- def book_checkout(ref, git_accessor=Git)
94
- temp_workspace = Dir.mktmpdir('book_checkout')
95
- book = Book.from_remote(logger: @logger,
96
- full_name: config.book_repo,
97
- destination_dir: temp_workspace,
98
- ref: ref,
99
- git_accessor: git_accessor,
100
- )
101
-
102
- File.join temp_workspace, book.directory
103
- end
104
-
105
- def layout_repo_path(local_repo_dir)
106
- if config.has_option?('layout_repo')
107
- if local_repo_dir
108
- File.join(local_repo_dir, config.layout_repo.split('/').last)
109
- else
110
- section = {'repository' => {'name' => config.layout_repo}}
111
- destination_dir = Dir.mktmpdir
112
- repository = GitHubRepository.build_from_remote(@logger, section, destination_dir, 'master', @git_accessor)
113
- if repository
114
- File.join(destination_dir, repository.directory)
115
- else
116
- raise 'failed to fetch repository'
117
- end
118
- end
119
- else
120
- File.absolute_path('master_middleman')
121
- end
122
- end
123
-
124
- def arguments_are_valid?(arguments)
125
- return false unless arguments.any?
126
- verbose = arguments[1] && arguments[1..-1].include?('--verbose')
127
- tag_provided = arguments[1] && (arguments[1..-1] - ['--verbose']).any?
128
- nothing_special = arguments[1..-1].empty?
129
-
130
- %w(local github).include?(arguments[0]) && (tag_provided || verbose || nothing_special)
131
- end
132
-
133
- def publishing_to_github?(publish_location)
134
- config.has_option?('versions') && publish_location != 'local'
135
- end
136
- end
137
- end
138
- end
@@ -1,33 +0,0 @@
1
- module Bookbinder
2
- class UsageMessenger
3
-
4
- def construct_for commands, flags
5
- log_usage_header + "\n" + flag_usage_messages(flags) + command_usage_messages(commands)
6
- end
7
-
8
- private
9
-
10
- def flag_usage_messages(flags)
11
- flag_usage_messages = ""
12
- flags.each { |f| flag_usage_messages += " \t#{f.usage}\n" }
13
- flag_usage_messages
14
- end
15
-
16
- def command_usage_messages(commands)
17
- flag_command_messages = ""
18
- commands.each do |command_class|
19
- flag_command_messages += " \t#{command_class.usage}\n"
20
- end
21
- flag_command_messages
22
- end
23
-
24
- def log_usage_header
25
- <<TEXT
26
-
27
- \e[1;39;49mDocumentation\e[0m: https://github.com/pivotal-cf/docs-bookbinder
28
-
29
- \e[1;39;49mUsage\e[0m: bookbinder <command|flag> [args]
30
- TEXT
31
- end
32
- end
33
- end
File without changes