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
@@ -0,0 +1,50 @@
1
+ require_relative 'dita_preprocessor'
2
+
3
+ module Bookbinder
4
+ module Preprocessing
5
+ class DitaPDFPreprocessor < DitaPreprocessor
6
+ DitaToPDFLibraryFailure = Class.new(RuntimeError)
7
+
8
+ def initialize(fs, command_creator, sheller)
9
+ @fs = fs
10
+ @command_creator = command_creator
11
+ @sheller = sheller
12
+ end
13
+
14
+ def applicable_to?(section)
15
+ !!section.pdf_output_filename
16
+ end
17
+
18
+ def preprocess(sections, output_locations, options: [], output_streams: nil, **_)
19
+ sections.each do |section|
20
+ command = command_creator.convert_to_pdf_command(
21
+ section,
22
+ dita_flags: dita_flags(options),
23
+ write_to: output_locations.pdf_from_preprocessing_dir
24
+ )
25
+ status = sheller.run_command(command, output_streams.to_h)
26
+
27
+ if status.success?
28
+ pdf_path = most_recent_pdf(output_locations.pdf_from_preprocessing_dir)
29
+ pdf_destination = output_locations.pdf_artifact_dir.join(section.pdf_output_filename)
30
+ fs.copy_and_rename(pdf_path, pdf_destination)
31
+ else
32
+ raise DitaToPDFLibraryFailure.new 'The DITA-to-PDF conversion failed. ' +
33
+ 'Please check that you have specified the path to your DITA-OT library in the ENV, ' +
34
+ 'that your DITA-specific keys/values in config.yml are set, ' +
35
+ 'and that your DITA toolkit is correctly configured.'
36
+ end
37
+ end
38
+ end
39
+
40
+ def most_recent_pdf(dir_path)
41
+ pdfs_by_modified_date = Dir.glob(dir_path + '*.pdf').sort_by{ |f| File.mtime(f) }
42
+ pdfs_by_modified_date.last
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :command_creator, :sheller, :fs
48
+ end
49
+ end
50
+ end
@@ -1,88 +1,8 @@
1
- require_relative '../values/subnav_template'
2
- require_relative '../../../lib/bookbinder/subnav/json_from_html_toc'
3
-
4
1
  module Bookbinder
5
2
  module Preprocessing
6
3
  class DitaPreprocessor
7
- DitaToHtmlLibraryFailure = Class.new(RuntimeError)
8
-
9
- ACCEPTED_IMAGE_FORMATS = %w(png jpeg jpg svg gif bmp tif tiff eps)
10
-
11
- def initialize(fs, subnav_gen_factory, dita_formatter, command_creator, sheller)
12
- @fs = fs
13
- @subnav_gen_factory = subnav_gen_factory
14
- @dita_formatter = dita_formatter
15
- @command_creator = command_creator
16
- @sheller = sheller
17
- end
18
-
19
- def applicable_to?(section)
20
- section.subnav_template.include?('dita_subnav') if section.subnav_template
21
- end
22
-
23
- def preprocess(sections, output_locations, options: [], output_streams: nil, **_)
24
- @output_locations = output_locations
25
-
26
- dita_options = dita_flags(options)
27
-
28
- sections.each do |section|
29
- if section.path_to_preprocessor_attribute('ditamap_location')
30
- convert_dita_files(section,
31
- command_creator,
32
- dita_options,
33
- section_html_dir(section),
34
- sheller,
35
- output_streams)
36
-
37
- subnav_generator.generate(section)
38
- end
39
-
40
- dita_formatter.format_html(section_html_dir(section), formatted_dir(section))
41
- copy_images(section.path_to_repo_dir, formatted_dir(section))
42
- fs.copy_contents(formatted_dir(section), source_for_site_gen_dir(section))
43
- end
44
- end
45
-
46
- private
47
4
 
48
- attr_reader :fs, :subnav_gen_factory, :dita_formatter, :command_creator, :sheller, :subnav_generator, :output_locations
49
-
50
- def section_html_dir(section)
51
- output_locations.html_from_preprocessing_dir.join(section.destination_directory)
52
- end
53
-
54
- def formatted_dir(section)
55
- output_locations.formatted_dir.join(section.destination_directory)
56
- end
57
-
58
- def source_for_site_gen_dir(section)
59
- output_locations.source_for_site_generator.join(section.destination_directory)
60
- end
61
-
62
- def convert_dita_files(section, command_creator, options, section_html_dir, sheller, output_streams)
63
- command = command_creator.convert_to_html_command(
64
- section,
65
- dita_flags: options,
66
- write_to: section_html_dir
67
- )
68
- status = sheller.run_command(command, output_streams.to_h)
69
- unless status.success?
70
- raise DitaToHtmlLibraryFailure.new 'The DITA-to-HTML conversion failed. ' +
71
- 'Please check that you have specified the path to your DITA-OT library in the ENV, ' +
72
- 'that your DITA-specific keys/values in config.yml are set, ' +
73
- 'and that your DITA toolkit is correctly configured.'
74
- end
75
- end
76
-
77
- def copy_images(src, dest)
78
- image_paths = ACCEPTED_IMAGE_FORMATS.map do |format|
79
- fs.find_files_with_ext(format, src)
80
- end.flatten
81
-
82
- image_paths.each do |image_path|
83
- fs.copy_including_intermediate_dirs(image_path, src, dest)
84
- end
85
- end
5
+ protected
86
6
 
87
7
  def dita_flags(opts)
88
8
  matching_flags = opts.map {|o| o[flag_value_regex("dita-flags"), 1] }
@@ -90,11 +10,7 @@ module Bookbinder
90
10
  end
91
11
 
92
12
  def flag_value_regex(flag_name)
93
- Regexp.new(/--#{flag_name}=(.+)/)
94
- end
95
-
96
- def subnav_generator
97
- @subnav_generator ||= subnav_gen_factory.produce(Subnav::JsonFromHtmlToc.new(fs))
13
+ Regexp.new(/--#{flag_name}="(.+)"/)
98
14
  end
99
15
  end
100
16
  end
@@ -46,6 +46,10 @@ module Bookbinder
46
46
  preprocessing_home_dir.join('html_from_preprocessing')
47
47
  end
48
48
 
49
+ def pdf_from_preprocessing_dir
50
+ preprocessing_home_dir.join('pdf_from_preprocessing')
51
+ end
52
+
49
53
  def formatted_dir
50
54
  preprocessing_home_dir.join('site_generator_ready')
51
55
  end
@@ -66,6 +70,14 @@ module Bookbinder
66
70
  context_dir
67
71
  end
68
72
 
73
+ def artifact_dir
74
+ context_dir.join('artifacts')
75
+ end
76
+
77
+ def pdf_artifact_dir
78
+ artifact_dir.join('pdfs')
79
+ end
80
+
69
81
  private
70
82
 
71
83
  def context_dir
@@ -10,7 +10,9 @@ module Bookbinder
10
10
  :preprocessor_config,
11
11
  :at_repo_path,
12
12
  :repo_name,
13
- :source_ref) do
13
+ :source_ref,
14
+ :pdf_output_filename) do
15
+
14
16
  def path_to_repo_dir
15
17
  at_repo_path.nil? ? path_to_repository : path_to_repository.join(at_repo_path)
16
18
  end
@@ -83,13 +83,12 @@ module Bookbinder
83
83
  @_out_buf.concat "<div class='mermaid'>#{escaped_text}</div>"
84
84
  end
85
85
 
86
- def modified_date(format: "%B %-d, %Y", default_date: nil)
87
- date = page_last_modified_date
88
- author_date = date.strftime(format) if date
86
+ def modified_date(default_date: nil)
87
+ parsed_default_date = Time.parse(default_date).utc if default_date
89
88
 
90
- display_date = author_date || default_date
89
+ date = page_last_modified_date || parsed_default_date
91
90
 
92
- "Page last updated: #{display_date}" if display_date
91
+ "Page last updated: <span data-behavior=\"DisplayModifiedDate\" data-modified-date=\"#{date}\"></span>" if date
93
92
  end
94
93
 
95
94
  def breadcrumbs
@@ -133,11 +132,13 @@ module Bookbinder
133
132
  def page_last_modified_date
134
133
  git_accessor = Ingest::GitAccessor.new
135
134
 
136
- if current_page.data.dita
135
+ current_date = if current_page.data.dita
137
136
  git_accessor.author_date(preprocessing_path(current_page.source_file), dita: true)
138
137
  else
139
138
  git_accessor.author_date(current_page.source_file)
140
139
  end
140
+
141
+ current_date.utc if current_date
141
142
  end
142
143
 
143
144
  def repo_url
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: 7.4.4
4
+ version: 7.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Grafton
@@ -18,7 +18,7 @@ authors:
18
18
  autorequire:
19
19
  bindir: install_bin
20
20
  cert_chain: []
21
- date: 2016-01-25 00:00:00.000000000 Z
21
+ date: 2016-02-16 00:00:00.000000000 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: fog-aws
@@ -317,14 +317,16 @@ files:
317
317
  - lib/bookbinder/command_runner.rb
318
318
  - lib/bookbinder/command_validator.rb
319
319
  - lib/bookbinder/commands/bind.rb
320
- - lib/bookbinder/commands/bind/bind_options.rb
321
- - lib/bookbinder/commands/bind/directory_preparer.rb
322
- - lib/bookbinder/commands/bind/layout_preparer.rb
323
320
  - lib/bookbinder/commands/build_and_push_tarball.rb
324
321
  - lib/bookbinder/commands/chain.rb
325
322
  - lib/bookbinder/commands/collection.rb
323
+ - lib/bookbinder/commands/components/bind/directory_preparer.rb
324
+ - lib/bookbinder/commands/components/bind/layout_preparer.rb
325
+ - lib/bookbinder/commands/components/command_options.rb
326
+ - lib/bookbinder/commands/components/imprint/directory_preparer.rb
326
327
  - lib/bookbinder/commands/generate.rb
327
328
  - lib/bookbinder/commands/help.rb
329
+ - lib/bookbinder/commands/imprint.rb
328
330
  - lib/bookbinder/commands/naming.rb
329
331
  - lib/bookbinder/commands/punch.rb
330
332
  - lib/bookbinder/commands/push_from_local.rb
@@ -336,15 +338,18 @@ files:
336
338
  - lib/bookbinder/config/aws_credentials.rb
337
339
  - lib/bookbinder/config/cf_credentials.rb
338
340
  - lib/bookbinder/config/checkers/archive_menu_checker.rb
339
- - lib/bookbinder/config/checkers/dita_section_checker.rb
341
+ - lib/bookbinder/config/checkers/ditamap_presence_checker.rb
340
342
  - lib/bookbinder/config/checkers/duplicate_section_name_checker.rb
341
343
  - lib/bookbinder/config/checkers/repository_name_presence_checker.rb
342
344
  - lib/bookbinder/config/checkers/required_keys_checker.rb
345
+ - lib/bookbinder/config/checkers/section_presence_checker.rb
343
346
  - lib/bookbinder/config/checkers/subnavs_checker.rb
344
347
  - lib/bookbinder/config/checkers/topics_checker.rb
345
348
  - lib/bookbinder/config/configuration.rb
346
349
  - lib/bookbinder/config/configuration_decorator.rb
350
+ - lib/bookbinder/config/dita_config_generator.rb
347
351
  - lib/bookbinder/config/fetcher.rb
352
+ - lib/bookbinder/config/imprint/configuration.rb
348
353
  - lib/bookbinder/config/remote_yaml_credential_provider.rb
349
354
  - lib/bookbinder/config/section_config.rb
350
355
  - lib/bookbinder/config/subnav_config.rb
@@ -383,6 +388,8 @@ files:
383
388
  - lib/bookbinder/local_filesystem_accessor.rb
384
389
  - lib/bookbinder/middleman_runner.rb
385
390
  - lib/bookbinder/postprocessing/sitemap_writer.rb
391
+ - lib/bookbinder/preprocessing/dita_html_preprocessor.rb
392
+ - lib/bookbinder/preprocessing/dita_pdf_preprocessor.rb
386
393
  - lib/bookbinder/preprocessing/dita_preprocessor.rb
387
394
  - lib/bookbinder/preprocessing/link_to_site_gen_dir.rb
388
395
  - lib/bookbinder/preprocessing/preprocessor.rb
@@ -1,31 +0,0 @@
1
- require_relative 'layout_preparer'
2
-
3
- module Bookbinder
4
- module Commands
5
- module BindComponents
6
- class DirectoryPreparer
7
- def initialize(fs)
8
- @fs = fs
9
- end
10
-
11
- def prepare_directories(config, gem_root, output_locations, cloner, ref_override: nil)
12
- fs.remove_directory(output_locations.output_dir)
13
- fs.empty_directory(output_locations.final_app_dir)
14
-
15
- copy_directory_from_gem(gem_root, 'template_app', output_locations.final_app_dir)
16
- copy_directory_from_gem(gem_root, 'master_middleman', output_locations.site_generator_home)
17
-
18
- LayoutPreparer.new(fs).prepare(output_locations, cloner, ref_override, config)
19
- end
20
-
21
- private
22
-
23
- attr_reader :fs
24
-
25
- def copy_directory_from_gem(gem_root, dir, output_dir)
26
- fs.copy_contents(File.join(gem_root, dir), output_dir)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- module Bookbinder
2
- module Commands
3
- module BindComponents
4
- class LayoutPreparer
5
- def initialize(fs)
6
- @fs = fs
7
- end
8
-
9
- attr_reader :fs
10
-
11
- def prepare(output_locations, cloner, ref_override, config)
12
- if config.has_option?('layout_repo')
13
-
14
- cloned_repo = cloner.call(source_repo_name: config.layout_repo,
15
- source_ref: ref_override || config.layout_repo_ref,
16
- destination_parent_dir: Dir.mktmpdir)
17
-
18
- fs.copy_contents(cloned_repo.path, output_locations.site_generator_home)
19
- end
20
- fs.copy_contents(File.absolute_path('master_middleman'), output_locations.site_generator_home)
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,31 +0,0 @@
1
- module Bookbinder
2
- module Config
3
- module Checkers
4
- class DitaSectionChecker
5
- DitamapLocationError = Class.new(RuntimeError)
6
-
7
- def check(config)
8
- if none_with_pred?(dita_sections(config)) { |s|
9
- s.preprocessor_config['ditamap_location']
10
- }
11
- DitamapLocationError.new(
12
- "You must have at least one 'ditamap_location' key in dita_sections."
13
- )
14
- end
15
- end
16
-
17
- private
18
-
19
- def none_with_pred?(coll, &block)
20
- coll.any? && coll.none?(&block)
21
- end
22
-
23
- def dita_sections(config)
24
- config.sections.select {|s|
25
- s.preprocessor_config.has_key?('ditamap_location')
26
- }
27
- end
28
- end
29
- end
30
- end
31
- end