Top Level Namespace
Defined Under Namespace
Classes: IMGKit
Instance Method Summary collapse
- #cleanup(install_to) ⇒ Object
- #detect_architecture ⇒ Object
- #download_wkhtmltoimage(arch) ⇒ Object
- #install(download, arch, install_to) ⇒ Object
Instance Method Details
#cleanup(install_to) ⇒ Object
21 22 23 24 |
# File 'bin/imgkit', line 21 def cleanup(install_to) `rm -rf wkhtmltoimage*` `rm #{install_to}` end |
#detect_architecture ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'bin/imgkit', line 8 def detect_architecture case Config::CONFIG['arch'] when /x86_64-linux/i 'amd64' when /linux/i 'i386' when /darwin/i 'OS-X.i386' else raise "No binaries found for your system. Please install wkhtmltoimage by hand." end end |
#download_wkhtmltoimage(arch) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'bin/imgkit', line 26 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("http://code.google.com/p/wkhtmltopdf/downloads/list").read download = page.match(/href=".*name=(.*wkhtmltoimage-.*#{arch}.*?)&/) || raise("File not found..") 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'bin/imgkit', line 42 def install(download, arch, install_to) puts "Installing #{download} to #{install_to}" if download =~ /.tar.bz2$/ `sudo tar xjvf #{download}` `sudo mv wkhtmltoimage-#{arch} #{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" `sudo lzcat #{download} | tar x` `sudo mv wkhtmltoimage-#{arch} #{install_to}` else `sudo mv #{download} #{install_to}` end `sudo chmod +x #{install_to}` end |