Class: Klipbook::ToHtml::HtmlPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/klipbook/tohtml/html_printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(message_stream = $stdout) ⇒ HtmlPrinter

Returns a new instance of HtmlPrinter.



5
6
7
# File 'lib/klipbook/tohtml/html_printer.rb', line 5

def initialize(message_stream=$stdout)
  @message_stream = message_stream
end

Instance Method Details



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/klipbook/tohtml/html_printer.rb', line 9

def print_to_file(book, output_dir, force)
  filename = filename_for_book(book)
  filepath = File.join(output_dir, filename)

  if !force && File.exists?(filepath)
    @message_stream.puts(Colours.yellow("Skipping ") + filename)
    return
  end

  @message_stream.puts(Colours.green("Writing ") + filename)
  File.open(filepath, 'w') do |f|
    f.write generate_html(book)
  end
end