Class: Sakusei::MultiFileBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sakusei/multi_file_builder.rb

Overview

Builds multiple markdown files into a single PDF with consistent page numbering

Instance Method Summary collapse

Constructor Details

#initialize(files, options = {}) ⇒ MultiFileBuilder

Returns a new instance of MultiFileBuilder.



8
9
10
11
12
# File 'lib/sakusei/multi_file_builder.rb', line 8

def initialize(files, options = {})
  @files = expand_files(files)
  @options = options
  @base_dir = options[:base_dir] || Dir.pwd
end

Instance Method Details

#buildObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sakusei/multi_file_builder.rb', line 14

def build
  raise Error, 'No files to build' if @files.empty?

  # Concatenate all markdown files
  combined_content = concatenate_files

  # Process the combined content through the normal pipeline
  temp_file = create_temp_file(combined_content)

  # Derive output path from the first source file if not explicitly specified
  output = @options[:output] || begin
    first = @files.first
    File.join(File.dirname(File.expand_path(first)), "#{File.basename(first, '.*')}.pdf")
  end

  # Use standard Builder with the combined file, pointing it at the real source dir
  Builder.new(temp_file, @options.merge(source_dir: @base_dir, output: output)).build
ensure
  File.delete(temp_file) if temp_file && File.exist?(temp_file)
end