Class: Sakusei::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(source_file, options = {}) ⇒ Builder

Returns a new instance of Builder.



13
14
15
16
17
# File 'lib/sakusei/builder.rb', line 13

def initialize(source_file, options = {})
  @source_file = File.expand_path(source_file)
  @options = options
  @source_dir = File.dirname(@source_file)
end

Instance Method Details

#buildObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sakusei/builder.rb', line 19

def build
  # 1. Discover and load style pack
  $stderr.puts "[sakusei] discovering style pack..."
  style_pack = discover_style_pack
  $stderr.puts "[sakusei] style pack: #{style_pack.name} (#{style_pack.path})"

  # 2. Resolve and concatenate file references
  $stderr.puts "[sakusei] resolving file includes..."
  resolved_content = resolve_files

  # 3. Process ERB templates
  $stderr.puts "[sakusei] processing ERB..."
  processed_content = process_erb(resolved_content)

  # 4. Process Vue components (if available)
  processed_content = process_vue(processed_content, style_pack)

  # 4.5 Wrap h2/h3 headings with their following block to prevent orphaned headings
  processed_content = wrap_headings(processed_content)

  # 5. Convert to PDF
  $stderr.puts "[sakusei] converting to PDF..."
  output_path = generate_output_path
  convert_to_pdf(processed_content, output_path, style_pack)

  $stderr.puts "[sakusei] written: #{output_path}"
  output_path
end