Class: Sakusei::Builder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Builder.



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

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

Instance Attribute Details

#source_dirObject (readonly)

Returns the value of attribute source_dir.



21
22
23
# File 'lib/sakusei/builder.rb', line 21

def source_dir
  @source_dir
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



21
22
23
# File 'lib/sakusei/builder.rb', line 21

def source_file
  @source_file
end

Instance Method Details

#buildObject



31
32
33
34
35
36
37
38
# File 'lib/sakusei/builder.rb', line 31

def build
  style_pack, processed_content = build_processed_content
  $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

#build_htmlObject

Run the full pipeline up to (but not including) PDF conversion, then render the processed markdown to a styled HTML string via md-to-pdf –as-html. Returns [html_string, style_pack].



43
44
45
46
47
# File 'lib/sakusei/builder.rb', line 43

def build_html
  style_pack, processed_content = build_processed_content
  html = HtmlConverter.new(processed_content, style_pack, @options.merge(source_dir: @source_dir)).convert
  [html, style_pack]
end

#resolved_input_filesObject

Files that contributed to the most recent build (source + @include partials). Populated after #build, #build_html, or #build_processed_content runs.



25
26
27
28
29
# File 'lib/sakusei/builder.rb', line 25

def resolved_input_files
  files = [@source_file]
  files.concat(@file_resolver.resolved_files.to_a) if @file_resolver
  files.uniq
end