Class: ReqresRspec::Generators::Pdf

Inherits:
Object
  • Object
show all
Defined in:
lib/reqres_rspec/generators/pdf.rb

Instance Method Summary collapse

Instance Method Details

#generateObject

generates PDF file from existing HTML docs TODO: more info



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/reqres_rspec/generators/pdf.rb', line 6

def generate
  wkhtmltopdf_path = '/Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf'
  html_docs_root = File.join(Rails.root, 'docs')
  pdf_doc_path = File.join(Rails.root, 'docs', "spec_#{Time.now.strftime("%d-%h-%Y_%H-%M")}.pdf")

  if File.exists?(wkhtmltopdf_path)
    files = Dir["#{html_docs_root}/rspec_docs_*.html"]
    files_arg = files.map { |f| f if f =~ /\/rspec_docs_\d+\.html/ }.compact.sort.join(' ')

    `#{wkhtmltopdf_path} #{files_arg} #{pdf_doc_path}`

    puts "saved to #{pdf_doc_path}" if File.exists? pdf_doc_path
  else
    puts 'ERROR: wkhtmltopdf app not installed! Please check http://code.google.com/p/wkhtmltopdf/ for more info'
  end
end