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
22
23
24
25
26
# File 'lib/reqres_rspec/generators/pdf.rb', line 6

def generate
  # http://www.princexml.com/download/
  pdf_tool_path = 'prince'
  html_docs_root = File.join(Rails.root, 'doc')
  pdf_doc_path = File.join(Rails.root, 'doc', "rspec_doc_#{Time.now.strftime("%d-%h-%Y_%H-%M")}.pdf")

  if `which #{pdf_tool_path}`.size > 0
    files = Dir["#{html_docs_root}/rspec_doc_*.html"]
    if files.size > 0
      files_arg = files.map { |f| f if f =~ /\/rspec_doc_\d+\.html/ }.compact.sort.join('" "')

      `#{pdf_tool_path} "#{files_arg}" -o "#{pdf_doc_path}"`

      puts "ReqresRspec::Generators::Pdf saved doc to #{pdf_doc_path}" if File.exists? pdf_doc_path
    else
      puts 'No HTML files found'
    end
  else
    puts "ERROR: #{pdf_tool_path} is not installed! Check README.md for more info"
  end
end