class Bookbinder::Preprocessing::DitaHTMLPreprocessor
Constants
- ACCEPTED_IMAGE_FORMATS
- DitaToHtmlLibraryFailure
Attributes
command_creator[R]
dita_formatter[R]
fs[R]
output_locations[R]
sheller[R]
Public Class Methods
new(fs, subnav_gen_factory, dita_formatter, command_creator, sheller)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 11 def initialize(fs, subnav_gen_factory, dita_formatter, command_creator, sheller) @fs = fs @subnav_gen_factory = subnav_gen_factory @dita_formatter = dita_formatter @command_creator = command_creator @sheller = sheller end
Public Instance Methods
applicable_to?(section)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 19 def applicable_to?(section) section.subnav_template.include?('dita_subnav') if section.subnav_template end
preprocess(sections, output_locations, options: {}, output_streams: nil, **_)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 23 def preprocess(sections, output_locations, options: {}, output_streams: nil, **_) @output_locations = output_locations sections.each do |section| if section.path_to_preprocessor_attribute('ditamap_location') convert_dita_files(section, command_creator, options[:dita_flags], section_html_dir(section), sheller, output_streams) subnav_generator.generate(section) end dita_formatter.format_html(section_html_dir(section), formatted_dir(section)) copy_images(section.path_to_repo_dir, formatted_dir(section)) fs.copy_contents(formatted_dir(section), source_for_site_gen_dir(section)) end end
Private Instance Methods
convert_dita_files(section, command_creator, options, section_html_dir, sheller, output_streams)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 60 def convert_dita_files(section, command_creator, options, section_html_dir, sheller, output_streams) command = command_creator.convert_to_html_command( section, dita_flags: options, write_to: section_html_dir ) status = sheller.run_command(command, output_streams.to_h) unless status.success? raise DitaToHtmlLibraryFailure.new 'The DITA-to-HTML conversion failed. ' + 'Please check that you have specified the path to your DITA-OT library in the ENV, ' + 'that your DITA-specific keys/values in config.yml are set, ' + 'and that your DITA toolkit is correctly configured.' end end
copy_images(src, dest)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 75 def copy_images(src, dest) image_paths = ACCEPTED_IMAGE_FORMATS.map do |format| fs.find_files_with_ext(format, src) end.flatten image_paths.each do |image_path| fs.copy_including_intermediate_dirs(image_path, src, dest) end end
formatted_dir(section)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 52 def formatted_dir(section) output_locations.formatted_dir.join(section.destination_directory) end
section_html_dir(section)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 48 def section_html_dir(section) output_locations.html_from_preprocessing_dir.join(section.destination_directory) end
source_for_site_gen_dir(section)
click to toggle source
# File lib/bookbinder/preprocessing/dita_html_preprocessor.rb, line 56 def source_for_site_gen_dir(section) output_locations.source_for_site_generator.join(section.destination_directory) end