Top Level Namespace

Defined Under Namespace

Classes: PDFKit

Instance Method Summary collapse

Instance Method Details

#cleanup(install_to) ⇒ Object



21
22
23
24
# File 'bin/pdfkit', line 21

def cleanup(install_to)
  `rm -rf wkhtmltopdf*`
  `rm #{install_to}`
end

#detect_architectureObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'bin/pdfkit', line 8

def detect_architecture
  case Config::CONFIG['host_os']
  when /x86_64-linux/i
    'amd64'
  when /linux/i
    'i386'
  when /darwin/i
    'OS-X.i368'
  else
    raise "No binaries found for your system. Please install wkhtmltopdf by hand."
  end
end

#download_wkhtmltopdf(arch) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'bin/pdfkit', line 26

def download_wkhtmltopdf(arch)
  page = open("http://code.google.com/p/wkhtmltopdf/downloads/list").read
  download = page.match(/href=".*name=(.*wkhtmltopdf-.*#{arch}.*?)&/) || raise("File not found..")
  download = download[1]
  url = "http://wkhtmltopdf.googlecode.com/files/#{download}"
  puts "Downloading #{download} from #{url}"
  
  `curl #{url} > #{download}`
  download
end

#install(download, arch, install_to) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'bin/pdfkit', line 37

def install(download, arch, install_to)
  puts "Installing #{download} to #{install_to}"
  if download =~ /.tar.bz2$/
    `tar xjvf #{download}`
    `mv wkhtmltopdf-#{arch} #{install_to}`
  elsif download =~ /.tar.lzma$/
    raise "couldn't extract archive: lzcat not found" unless system("which lzcat > /dev/null 2>/dev/null")
    `lzcat #{download} | tar x`
    `mv wkhtmltopdf-#{arch} #{install_to}`
  else
    `mv #{download} #{install_to}`
  end
  `sudo chmod +x #{install_to}`
end