bookbindery 7.4.4 → 7.5.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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/bookbinder.gemspec +1 -1
  3. data/lib/bookbinder/cli.rb +1 -1
  4. data/lib/bookbinder/commands/bind.rb +17 -17
  5. data/lib/bookbinder/commands/collection.rb +48 -26
  6. data/lib/bookbinder/commands/components/bind/directory_preparer.rb +33 -0
  7. data/lib/bookbinder/commands/components/bind/layout_preparer.rb +27 -0
  8. data/lib/bookbinder/commands/{bind/bind_options.rb → components/command_options.rb} +2 -2
  9. data/lib/bookbinder/commands/components/imprint/directory_preparer.rb +24 -0
  10. data/lib/bookbinder/commands/imprint.rb +62 -0
  11. data/lib/bookbinder/commands/watch.rb +0 -1
  12. data/lib/bookbinder/config/checkers/ditamap_presence_checker.rb +27 -0
  13. data/lib/bookbinder/config/checkers/section_presence_checker.rb +15 -0
  14. data/lib/bookbinder/config/configuration.rb +18 -27
  15. data/lib/bookbinder/config/dita_config_generator.rb +61 -0
  16. data/lib/bookbinder/config/fetcher.rb +4 -3
  17. data/lib/bookbinder/config/imprint/configuration.rb +24 -0
  18. data/lib/bookbinder/config/section_config.rb +4 -0
  19. data/lib/bookbinder/config/validator.rb +4 -2
  20. data/lib/bookbinder/dita_command_creator.rb +31 -16
  21. data/lib/bookbinder/ingest/section_repository.rb +2 -1
  22. data/lib/bookbinder/local_filesystem_accessor.rb +9 -2
  23. data/lib/bookbinder/preprocessing/dita_html_preprocessor.rb +94 -0
  24. data/lib/bookbinder/preprocessing/dita_pdf_preprocessor.rb +50 -0
  25. data/lib/bookbinder/preprocessing/dita_preprocessor.rb +2 -86
  26. data/lib/bookbinder/values/output_locations.rb +12 -0
  27. data/lib/bookbinder/values/section.rb +3 -1
  28. data/master_middleman/bookbinder_helpers.rb +7 -6
  29. metadata +13 -6
  30. data/lib/bookbinder/commands/bind/directory_preparer.rb +0 -31
  31. data/lib/bookbinder/commands/bind/layout_preparer.rb +0 -25
  32. data/lib/bookbinder/config/checkers/dita_section_checker.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90579d5dc063e5b9444b2816d6018cab3e47f76f
4
- data.tar.gz: f9ef0aa5d4f40113f4bc951bc8fcc9634ad8748b
3
+ metadata.gz: 0dd2c6b574a77666001273739f0136dd0465e51c
4
+ data.tar.gz: 854939e21e33cc8bd187f2b7560966d3b0698cb0
5
5
  SHA512:
6
- metadata.gz: c1521e286256db035705dbd91383b0f1ea8d978a10412ce07d3d6238e06eb990ea0fc1e6a8416f6722da605856c2cf7d980fae8d043479e6b9c74f663e976fa6
7
- data.tar.gz: f8b05f4ac7c8cb76abcf5a67eeb6a23ae60f925824e3c28779fa95dc05f9017a4e7238945af26eab21822e88f9994ebe5ce460cfaf7771c67819a118aa7e8ec6
6
+ metadata.gz: a56e6c5664b07e1b6bc862bc21ad716b299999a36baed3889fec5aa227ca8d8c962e3e71dd0281f6bd677dbdc64ff77e154d53ac6597658e7c2c27f3aa32208a
7
+ data.tar.gz: 863e5303ef86d674eba079dd486278e7e11e44f143140b858c8743c2567e31afe73db57315c1946b63b3a159222e460840648b0cbe4cc9a9fd83fb366b62c0cd
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bookbindery'
5
- s.version = '7.4.4'
5
+ s.version = '7.5.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', 'Frank Kotsianas', 'Elena Sharma', 'Christa Hartsock', 'Michael Trestman']
@@ -36,7 +36,7 @@ module Bookbinder
36
36
  end
37
37
 
38
38
  begin
39
- command_runner.run command_name, command_arguments
39
+ command_runner.run(command_name, command_arguments)
40
40
 
41
41
  rescue Config::CfCredentials::CredentialKeyError => e
42
42
  colorized_streams[:err].puts "#{e.message}, in credentials.yml"
@@ -1,7 +1,6 @@
1
1
  require 'middleman-syntax'
2
2
 
3
- require_relative '../errors/cli_error'
4
- require_relative 'bind/bind_options'
3
+ require_relative 'components/command_options'
5
4
  require_relative 'naming'
6
5
 
7
6
  module Bookbinder
@@ -10,22 +9,23 @@ module Bookbinder
10
9
  include Commands::Naming
11
10
 
12
11
  def initialize(base_streams,
13
- output_locations,
14
- config_fetcher,
15
- config_decorator,
16
- file_system_accessor,
17
- static_site_generator,
18
- sitemap_writer,
19
- preprocessor,
20
- cloner_factory,
21
- section_repository,
22
- directory_preparer)
12
+ output_locations: nil,
13
+ config_fetcher: nil,
14
+ config_decorator: nil,
15
+ file_system_accessor: nil,
16
+ middleman_runner: nil,
17
+ sitemap_writer: nil,
18
+ preprocessor: nil,
19
+ cloner_factory: nil,
20
+ section_repository: nil,
21
+ directory_preparer: nil)
22
+
23
23
  @base_streams = base_streams
24
24
  @output_locations = output_locations
25
25
  @config_fetcher = config_fetcher
26
26
  @config_decorator = config_decorator
27
27
  @file_system_accessor = file_system_accessor
28
- @static_site_generator = static_site_generator
28
+ @middleman_runner = middleman_runner
29
29
  @sitemap_writer = sitemap_writer
30
30
  @preprocessor = preprocessor
31
31
  @cloner_factory = cloner_factory
@@ -34,7 +34,7 @@ module Bookbinder
34
34
  end
35
35
 
36
36
  def usage
37
- ["bind <local|remote> [--verbose] [--dita-flags='<dita-option>=<value>']",
37
+ ["bind <local|remote> [--verbose] [--dita-flags=\\\"<dita-option>=<value>\\\"]",
38
38
  "Bind the sections specified in config.yml from <local> or <remote> into the final_app directory"]
39
39
  end
40
40
 
@@ -47,7 +47,7 @@ module Bookbinder
47
47
  end
48
48
 
49
49
  def run(cli_arguments)
50
- bind_options = BindComponents::BindOptions.new(cli_arguments, base_streams).tap(&:validate!)
50
+ bind_options = Components::CommandOptions.new(cli_arguments, base_streams).tap(&:validate!)
51
51
  bind_config = config_fetcher.fetch_config
52
52
  cloner = cloner_factory.produce(bind_options.local_repo_dir)
53
53
 
@@ -75,7 +75,7 @@ module Bookbinder
75
75
  if file_system_accessor.file_exist?('redirects.rb')
76
76
  file_system_accessor.copy('redirects.rb', output_locations.final_app_dir)
77
77
  end
78
- generation_result = static_site_generator.run(
78
+ generation_result = middleman_runner.run(
79
79
  ["build", bind_options.verbosity].compact.join(" "),
80
80
  streams: bind_options.streams,
81
81
  output_locations: output_locations,
@@ -114,7 +114,7 @@ module Bookbinder
114
114
  :preprocessor,
115
115
  :section_repository,
116
116
  :sitemap_writer,
117
- :static_site_generator,
117
+ :middleman_runner,
118
118
  )
119
119
 
120
120
  def subnavs(sections)
@@ -2,12 +2,15 @@ Dir.glob(File.expand_path('../../commands/*.rb', __FILE__)).each do |command_fil
2
2
  require command_file
3
3
  end
4
4
 
5
- require_relative '../commands/bind/directory_preparer'
5
+ require_relative '../commands/components/bind/directory_preparer'
6
+ require_relative '../commands/components/imprint/directory_preparer'
6
7
  require_relative '../config/configuration_decorator'
7
8
  require_relative '../config/fetcher'
8
9
  require_relative '../config/remote_yaml_credential_provider'
9
10
  require_relative '../config/validator'
10
11
  require_relative '../config/yaml_loader'
12
+ require_relative '../config/configuration'
13
+ require_relative '../config/imprint/configuration'
11
14
  require_relative '../dita_command_creator'
12
15
  require_relative '../dita_html_for_middleman_formatter'
13
16
  require_relative '../html_document_manipulator'
@@ -16,7 +19,8 @@ require_relative '../ingest/section_repository'
16
19
  require_relative '../local_filesystem_accessor'
17
20
  require_relative '../middleman_runner'
18
21
  require_relative '../postprocessing/sitemap_writer'
19
- require_relative '../preprocessing/dita_preprocessor'
22
+ require_relative '../preprocessing/dita_html_preprocessor'
23
+ require_relative '../preprocessing/dita_pdf_preprocessor'
20
24
  require_relative '../preprocessing/link_to_site_gen_dir'
21
25
  require_relative '../preprocessing/preprocessor'
22
26
  require_relative '../subnav/subnav_generator_factory'
@@ -67,17 +71,18 @@ module Bookbinder
67
71
  ),
68
72
  build_and_push_tarball,
69
73
  bind,
70
- Commands::PushFromLocal.new(streams, logger, configuration_fetcher, 'acceptance'),
74
+ Commands::PushFromLocal.new(streams, logger, configuration_fetcher(Config::Configuration), 'acceptance'),
71
75
  push_local_to_staging,
72
- Commands::PushToProd.new(streams, logger, configuration_fetcher, Dir.mktmpdir),
76
+ Commands::PushToProd.new(streams, logger, configuration_fetcher(Config::Configuration), Dir.mktmpdir),
73
77
  Commands::RunPublishCI.new(bind, push_local_to_staging, build_and_push_tarball),
74
- Commands::Punch.new(streams, configuration_fetcher, version_control_system),
78
+ Commands::Punch.new(streams, configuration_fetcher(Config::Configuration), version_control_system),
75
79
  Commands::UpdateLocalDocRepos.new(
76
80
  streams,
77
- configuration_fetcher,
81
+ configuration_fetcher(Config::Configuration),
78
82
  version_control_system
79
83
  ),
80
- watch
84
+ watch,
85
+ imprint
81
86
  ]
82
87
  end
83
88
 
@@ -88,34 +93,38 @@ module Bookbinder
88
93
  def bind
89
94
  @bind ||= Commands::Bind.new(
90
95
  streams,
91
- output_locations,
92
- configuration_fetcher,
93
- Config::ConfigurationDecorator.new(loader: config_loader, config_filename: 'bookbinder.yml'),
94
- local_filesystem_accessor,
95
- runner,
96
- Postprocessing::SitemapWriter.build(logger, final_app_directory, sitemap_port),
97
- Preprocessing::Preprocessor.new(
98
- Preprocessing::DitaPreprocessor.new(
96
+ output_locations: output_locations,
97
+ config_fetcher: configuration_fetcher(Config::Configuration),
98
+ config_decorator: Config::ConfigurationDecorator.new(loader: config_loader, config_filename: 'bookbinder.yml'),
99
+ file_system_accessor: local_filesystem_accessor,
100
+ middleman_runner: runner,
101
+ sitemap_writer: Postprocessing::SitemapWriter.build(logger, final_app_directory, sitemap_port),
102
+ preprocessor: Preprocessing::Preprocessor.new(
103
+ Preprocessing::DitaHTMLPreprocessor.new(
99
104
  local_filesystem_accessor,
100
105
  subnav_generator_factory,
101
106
  DitaHtmlForMiddlemanFormatter.new(local_filesystem_accessor, html_document_manipulator),
102
- DitaCommandCreator.new(ENV['PATH_TO_DITA_OT_LIBRARY']),
107
+ dita_command_creator,
103
108
  sheller
104
109
  ),
105
110
  Preprocessing::LinkToSiteGenDir.new(local_filesystem_accessor, subnav_generator_factory)
106
111
  ),
107
- Ingest::ClonerFactory.new(streams, local_filesystem_accessor, version_control_system),
108
- Ingest::SectionRepository.new,
109
- directory_preparer
112
+ cloner_factory: Ingest::ClonerFactory.new(streams, local_filesystem_accessor, version_control_system),
113
+ section_repository: Ingest::SectionRepository.new,
114
+ directory_preparer: directory_preparer
110
115
  )
111
116
  end
112
117
 
118
+ def dita_command_creator
119
+ DitaCommandCreator.new(ENV['PATH_TO_DITA_OT_LIBRARY'])
120
+ end
121
+
113
122
  def watch
114
123
  @watch ||= Commands::Watch.new(
115
124
  streams,
116
125
  middleman_runner: runner,
117
126
  output_locations: output_locations,
118
- config_fetcher: configuration_fetcher,
127
+ config_fetcher: configuration_fetcher(Config::Configuration),
119
128
  config_decorator: Config::ConfigurationDecorator.new(loader: config_loader, config_filename: 'bookbinder.yml'),
120
129
  file_system_accessor: local_filesystem_accessor,
121
130
  preprocessor: Preprocessing::Preprocessor.new(Preprocessing::LinkToSiteGenDir.new(local_filesystem_accessor, subnav_generator_factory)),
@@ -125,11 +134,23 @@ module Bookbinder
125
134
  )
126
135
  end
127
136
 
137
+ def imprint
138
+ Commands::Imprint.new(
139
+ streams,
140
+ output_locations: output_locations,
141
+ config_fetcher: configuration_fetcher(Config::Imprint::Configuration),
142
+ preprocessor: Preprocessing::Preprocessor.new(Preprocessing::DitaPDFPreprocessor.new(local_filesystem_accessor, dita_command_creator, sheller)),
143
+ cloner_factory: Ingest::ClonerFactory.new(streams, local_filesystem_accessor, version_control_system),
144
+ section_repository: Ingest::SectionRepository.new,
145
+ directory_preparer: Commands::Components::Imprint::DirectoryPreparer.new(local_filesystem_accessor)
146
+ )
147
+ end
148
+
128
149
  def push_local_to_staging
129
150
  @push_local_to_staging ||= Commands::PushFromLocal.new(
130
151
  streams,
131
152
  logger,
132
- configuration_fetcher,
153
+ configuration_fetcher(Config::Configuration),
133
154
  'staging'
134
155
  )
135
156
  end
@@ -137,15 +158,16 @@ module Bookbinder
137
158
  def build_and_push_tarball
138
159
  @build_and_push_tarball ||= Commands::BuildAndPushTarball.new(
139
160
  streams,
140
- configuration_fetcher
161
+ configuration_fetcher(Config::Configuration)
141
162
  )
142
163
  end
143
164
 
144
- def configuration_fetcher
145
- @configuration_fetcher ||= Config::Fetcher.new(
165
+ def configuration_fetcher(config_class)
166
+ Config::Fetcher.new(
146
167
  Config::Validator.new(local_filesystem_accessor),
147
168
  config_loader,
148
- Config::RemoteYamlCredentialProvider.new(logger, version_control_system)
169
+ Config::RemoteYamlCredentialProvider.new(logger, version_control_system),
170
+ config_class
149
171
  ).tap do |fetcher|
150
172
  fetcher.set_config_file_path './config.yml'
151
173
  fetcher.set_config_dir_path './config/'
@@ -161,7 +183,7 @@ module Bookbinder
161
183
  end
162
184
 
163
185
  def directory_preparer
164
- Commands::BindComponents::DirectoryPreparer.new(local_filesystem_accessor)
186
+ Commands::Components::Bind::DirectoryPreparer.new(local_filesystem_accessor)
165
187
  end
166
188
 
167
189
  def output_locations
@@ -0,0 +1,33 @@
1
+ require_relative 'layout_preparer'
2
+
3
+ module Bookbinder
4
+ module Commands
5
+ module Components
6
+ module Bind
7
+ class DirectoryPreparer
8
+ def initialize(fs)
9
+ @fs = fs
10
+ end
11
+
12
+ def prepare_directories(config, gem_root, output_locations, cloner, ref_override: nil)
13
+ fs.remove_directory(output_locations.output_dir)
14
+ fs.empty_directory(output_locations.final_app_dir)
15
+
16
+ copy_directory_from_gem(gem_root, 'template_app', output_locations.final_app_dir)
17
+ copy_directory_from_gem(gem_root, 'master_middleman', output_locations.site_generator_home)
18
+
19
+ LayoutPreparer.new(fs).prepare(output_locations, cloner, ref_override, config)
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :fs
25
+
26
+ def copy_directory_from_gem(gem_root, dir, output_dir)
27
+ fs.copy_contents(File.join(gem_root, dir), output_dir)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ module Bookbinder
2
+ module Commands
3
+ module Components
4
+ module Bind
5
+ class LayoutPreparer
6
+ def initialize(fs)
7
+ @fs = fs
8
+ end
9
+
10
+ attr_reader :fs
11
+
12
+ def prepare(output_locations, cloner, ref_override, config)
13
+ if config.has_option?('layout_repo')
14
+
15
+ cloned_repo = cloner.call(source_repo_name: config.layout_repo,
16
+ source_ref: ref_override || config.layout_repo_ref,
17
+ destination_parent_dir: Dir.mktmpdir)
18
+
19
+ fs.copy_contents(cloned_repo.path, output_locations.site_generator_home)
20
+ end
21
+ fs.copy_contents(File.absolute_path('master_middleman'), output_locations.site_generator_home)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,8 +2,8 @@ require_relative '../../sheller'
2
2
 
3
3
  module Bookbinder
4
4
  module Commands
5
- module BindComponents
6
- class BindOptions
5
+ module Components
6
+ class CommandOptions
7
7
  def initialize(opts, base_streams)
8
8
  @opts = opts
9
9
  @base_streams = base_streams
@@ -0,0 +1,24 @@
1
+ module Bookbinder
2
+ module Commands
3
+ module Components
4
+ module Imprint
5
+ class DirectoryPreparer
6
+ def initialize(fs)
7
+ @fs = fs
8
+ end
9
+
10
+ def prepare_directories(output_locations)
11
+ fs.empty_directory(output_locations.output_dir)
12
+ fs.make_directory(output_locations.pdf_from_preprocessing_dir)
13
+
14
+ fs.empty_directory(output_locations.pdf_artifact_dir)
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :fs
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'components/command_options'
2
+ require_relative 'naming'
3
+
4
+ module Bookbinder
5
+ module Commands
6
+ class Imprint
7
+ include Commands::Naming
8
+
9
+ def initialize(base_streams,
10
+ output_locations: nil,
11
+ config_fetcher: nil,
12
+ preprocessor: nil,
13
+ cloner_factory: nil,
14
+ section_repository: nil,
15
+ directory_preparer: nil)
16
+
17
+ @base_streams = base_streams
18
+ @output_locations = output_locations
19
+ @config_fetcher = config_fetcher
20
+ @preprocessor = preprocessor
21
+ @cloner_factory = cloner_factory
22
+ @section_repository = section_repository
23
+ @directory_preparer = directory_preparer
24
+ end
25
+
26
+ def usage
27
+ ["imprint <local|remote> [--verbose] [--dita-flags=\\\"<dita-option>=<value>\\\"]", "Generate a PDF for a given book"]
28
+ end
29
+
30
+ def run(cli_arguments)
31
+ options = Components::CommandOptions.new(cli_arguments, base_streams).tap(&:validate!)
32
+ config = config_fetcher.fetch_config
33
+ cloner = cloner_factory.produce(options.local_repo_dir)
34
+
35
+ directory_preparer.prepare_directories(output_locations)
36
+
37
+ sections = section_repository.fetch(
38
+ configured_sections: config.sections,
39
+ destination_dir: output_locations.cloned_preprocessing_dir,
40
+ ref_override: options.ref_override,
41
+ cloner: cloner,
42
+ streams: base_streams
43
+ )
44
+
45
+ preprocessor.preprocess(
46
+ sections,
47
+ output_locations,
48
+ options: options.options,
49
+ output_streams: options.streams,
50
+ config: config
51
+ )
52
+
53
+ options.streams[:success].puts "Bookbinder printed your pdf(s) into #{output_locations.pdf_artifact_dir}"
54
+ 0
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :preprocessor, :output_locations, :section_repository, :base_streams, :config_fetcher, :directory_preparer, :cloner_factory
60
+ end
61
+ end
62
+ end
@@ -1,4 +1,3 @@
1
- require_relative 'bind/bind_options'
2
1
  require_relative 'naming'
3
2
 
4
3
  module Bookbinder
@@ -0,0 +1,27 @@
1
+ module Bookbinder
2
+ module Config
3
+ module Checkers
4
+ class DitamapPresenceChecker
5
+ DitamapLocationError = Class.new(RuntimeError)
6
+
7
+ def check(config)
8
+ if any_sections_missing_ditamaps?(config.sections)
9
+ DitamapLocationError.new(
10
+ "You must have a 'ditamap_location' for each key in dita_sections."
11
+ )
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def any_sections_missing_ditamaps?(sections)
18
+ sections.any? do |s|
19
+ if s.preprocessor_config.has_key?('ditamap_location')
20
+ s.preprocessor_config['ditamap_location'].nil? || s.preprocessor_config['ditamap_location'].empty?
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end