diff --git a/Rakefile b/Rakefile index bc0af9e..a32fc4f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,20 +1 @@ -require 'rubygems' -require 'rake/packagetask' -require 'rake/gempackagetask' - -spec = Gem::Specification.new do |s| - s.name = "wkhtmltopdf-binary" - s.version = "0.9.9" - s.author = "Research Information Systems, The University of Iowa" - s.email = "vpr-ris-developers@iowa.uiowa.edu,mcollas@aconex.com" - s.platform = Gem::Platform::RUBY - s.summary = "Provides binaries for WKHTMLTOPDF project in an easily accessible package." - s.files = FileList["{bin,libexec,lib}/*"].to_a - s.has_rdoc = false - s.executables << "wkhtmltopdf" - s.require_path = '.' -end - -Rake::GemPackageTask.new(spec) do |pkg| - pkg.need_tar = true -end +load File.expand_path('../wkhtmltopdf-binary.gemspec', __FILE__) diff --git a/bin/wkhtmltopdf b/bin/wkhtmltopdf index ec51b17..04fd90a 100755 --- a/bin/wkhtmltopdf +++ b/bin/wkhtmltopdf @@ -1,17 +1,8 @@ #!/usr/bin/env ruby -arch = case RUBY_PLATFORM - when /64.*linux/ - 'linux-amd64' - when /linux/ - 'linux-x86' - when /darwin/ - 'darwin-x86' - else - raise "Invalid platform. Must be running linux or intel-based Mac OS." -end +NO_WICKEDPDF_PATH = true +require 'wkhtmltopdf-binary' args = $*.map { |x| x.include?(' ') ? "'" + x + "'" : x } -cmd = File.expand_path "#{File.dirname(__FILE__)}/../libexec/wkhtmltopdf-#{arch}" -exec "#{cmd} #{args.join(' ')}" +exec "#{WkHtmlToPdfBinary.binary_path} #{args.join(' ')}" diff --git a/bin/wkhtmltopdf-path b/bin/wkhtmltopdf-path new file mode 100755 index 0000000..5f1e98d --- /dev/null +++ b/bin/wkhtmltopdf-path @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +NO_WICKEDPDF_PATH = true +require 'wkhtmltopdf-binary' + +puts WkHtmlToPdfBinary.binary_path diff --git a/lib/wkhtmltopdf-binary.rb b/lib/wkhtmltopdf-binary.rb index e69de29..13086f6 100644 --- a/lib/wkhtmltopdf-binary.rb +++ b/lib/wkhtmltopdf-binary.rb @@ -0,0 +1,22 @@ +module WkHtmlToPdfBinary + def self.binary_path + arch = case RUBY_PLATFORM + when /64.*linux/ + 'linux-amd64' + when /linux/ + 'linux-x86' + when /darwin/ + 'darwin-x86' + else + raise NotImplementedError, "Invalid platform. Must be running linux or intel-based Mac OS." + end + + File.expand_path("#{File.dirname(__FILE__)}/../libexec/wkhtmltopdf-#{arch}") + end +end + +begin + require 'wicked_pdf' + WickedPdf.config[:exe_path] ||= WkHtmlToPdfBinary.binary_path +rescue LoadError, NotImplementedError +end unless Object.const_defined?(:NO_WICKEDPDF_PATCH) diff --git a/wkhtmltopdf-binary.gemspec b/wkhtmltopdf-binary.gemspec index 51ef187..ea846b1 100644 --- a/wkhtmltopdf-binary.gemspec +++ b/wkhtmltopdf-binary.gemspec @@ -1,23 +1,24 @@ -Gem::Specification.new do |s| - s.platform = Gem::Platform::RUBY - s.name = 'wkhtmltopdf-binary' - s.version = '0.9.9' - s.summary = 'Provides binaries for WKHTMLTOPDF project in an easily accessible package.' - s.description = '' - - s.required_ruby_version = '>= 1.8.7' - s.required_rubygems_version = ">= 1.3.6" +require 'rubygems' +require 'rubygems/package_task' - s.author = '- Research Information Systems, The University of Iowa' - s.homepage = '' - s.email = 'vpr-ris-developers@iowa.uiowa.edu,mcollas@aconex.com' - - s.bindir = 'bin' - s.executables = %w(wkhtmltopdf) +Gem::Specification.new do |s| + s.name = "wkhtmltopdf-binary" + s.version = "0.10" + s.author = "Research Information Systems, The University of Iowa" + s.email = "vpr-ris-developers@iowa.uiowa.edu,mcollas@aconex.com" + s.platform = Gem::Platform::RUBY + s.summary = "Provides binaries for WKHTMLTOPDF project in an easily accessible package." + s.description = <<-EOF + Provides binaries and utilities of WKHTMLTOPDF. + Also patches WickedPdf (if installed) to use provided binary + EOF + s.homepage = 'https://github.com/steerio/wkhtmltopdf-binary' + s.files = FileList["{bin,libexec,lib}/*"].to_a + s.has_rdoc = false + s.rdoc_options += ['-x', 'libexec/.*'] + s.executables << "wkhtmltopdf" << 'wkhtmltopdf-path' - s.files = %w( - lib/wkhtmltopdf-binary.rb bin/wkhtmltopdf - libexec/wkhtmltopdf-darwin-x86 - libexec/wkhtmltopdf-linux-amd64 - libexec/wkhtmltopdf-linux-x86) + Gem::PackageTask.new(s) do |pkg| + pkg.need_tar = true + end end