1- require 'os '
1+ require 'open3 '
22
33module Jekyll
44 module Webp
@@ -17,18 +17,23 @@ def self.run(quality, input_file, output_file)
1717 # What is the OS and architecture specific executable name?
1818 exe_name = WebpExec . exe_name
1919
20- full_path = File . join ( bin_path , exe_name )
20+ # We need to locate the Gems bin path as we're currently running inside the
21+ # jekyll site working directory
22+ # http://stackoverflow.com/a/10083594/779521
23+ gem_spec = Gem ::Specification . find_by_name ( "jekyll-webp" )
24+ gem_root = gem_spec . gem_dir
25+
26+ # Construct the full path to the executable
27+ full_path = File . join ( gem_root , bin_path , exe_name )
2128
2229 # Construct the full program call
2330 cmd = "\" #{ full_path } \" -quiet -mt -q #{ quality . to_s } \" #{ input_file } \" -o \" #{ output_file } \" "
24-
25- puts "Command: " +cmd
2631
2732 # Execute the command
28- retValue = %x[ #{ cmd } ]
33+ stdin , stdout , stderr = Open3 . popen3 ( cmd )
2934
3035 # Return any captured return value
31- return retValue
36+ return [ stdin , stdout , stderr ]
3237 end #function run
3338
3439 #
@@ -38,13 +43,13 @@ def self.exe_name
3843 if OS . mac?
3944 return "osx-cwebp"
4045 elsif OS . windows?
41- if OS . 32 bit ?
46+ if OS . x32 ?
4247 return "win-x86-cwebp.exe"
4348 else
4449 return "win-x64-cwebp.exe"
4550 end
4651 elsif OS . unix? || OS . linux?
47- if OS . 32 bit ?
52+ if OS . x32 ?
4853 return "linux-x86-cwebp"
4954 else
5055 return "linux-x64-cwebp"
@@ -75,11 +80,11 @@ def OS.linux?
7580 OS . unix? and not OS . mac?
7681 end
7782
78- def OS . 32 bit ?
83+ def OS . x32 ?
7984 return 1 . size != 8
8085 end
8186
82- def OS . 64 bit ?
87+ def OS . x64 ?
8388 return 1 . size == 8
8489 end
8590 end #module OS
0 commit comments