Top Level Namespace
Defined Under Namespace
Classes: IMGKit
Constant Summary collapse
- GOOGLE_CODE_URL =
ENV['GOOGLE_CODE_URL'] || "http://code.google.com/p/wkhtmltopdf/downloads/list?can=1"
Instance Method Summary collapse
- #cant_find_binaries(arch) ⇒ Object
- #cleanup(install_to) ⇒ Object
- #detect_architecture ⇒ Object
- #download_wkhtmltoimage(arch) ⇒ Object
- #install(download, arch, install_to) ⇒ Object
Instance Method Details
#cant_find_binaries(arch) ⇒ Object
24 25 26 27 28 |
# File 'bin/imgkit', line 24 def cant_find_binaries(arch) puts "Sorry, I couldn't find the binary for your architecture (#{arch}) \n at #{GOOGLE_CODE_URL}" puts "Please go to that page, unzip the appropriate binary, and install" exit(1) end |
#cleanup(install_to) ⇒ Object
30 31 32 33 |
# File 'bin/imgkit', line 30 def cleanup(install_to) `rm -rf wkhtmltoimage*` rescue nil `rm #{install_to}` rescue nil end |
#detect_architecture ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'bin/imgkit', line 11 def detect_architecture case arch = Config::CONFIG['arch'] when /x86_64-linux/i 'amd64' when /linux/i 'i386' when /darwin/i 'OSX' else cant_find_binaries(arch) end end |
#download_wkhtmltoimage(arch) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'bin/imgkit', line 35 def download_wkhtmltoimage(arch) if ENV['BZIP'] download = "wkhtmltoimage-0.10.0_beta4-static-#{arch}.tar.bz2" url = "http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.10.0_beta4-static-#{arch}.tar.bz2" else page = open(GOOGLE_CODE_URL).read download = page.match(/href=".*name=(.*wkhtmltoimage-.*#{arch}.*?)&/) or cant_find_binaries(arch) download = download[1] url = "http://wkhtmltopdf.googlecode.com/files/#{download}" end puts "Downloading #{download} from #{url}" `curl #{url} > #{download}` download end |
#install(download, arch, install_to) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'bin/imgkit', line 51 def install(download, arch, install_to) puts "Installing #{download} to #{install_to}" if download =~ /.tar.bz2$/ `tar xjvf #{download}` `mv wkhtmltoimage #{install_to}` elsif download =~ /.tar.lzma$/ raise "couldn't extract archive: lzcat not found" unless system("which lzcat > /dev/null 2>/dev/null") puts "Warning: lzcat is broken on Ubuntu. Re-run with --use-bzip to install alternate version" `lzcat #{download} | tar x` `mv wkhtmltoimage-#{arch} #{install_to}` else `mv #{download} #{install_to}` end `chmod +x #{install_to}` end |