From 24765fa98b01e0edcad66bee3e0b099495a2c3d3 Mon Sep 17 00:00:00 2001 From: naquad Date: Fri, 21 Dec 2012 21:31:31 +0200 Subject: [PATCH 1/2] wkhtmltopdf-path, WickedPdf integration --- Rakefile | 21 +------------------ bin/wkhtmltopdf | 15 +++---------- bin/wkhtmltopdf-path | 6 ++++++ lib/wkhtmltopdf-binary.rb | 22 +++++++++++++++++++ wkhtmltopdf-binary.gemspec | 43 ++++++++++++++++++++------------------ 5 files changed, 55 insertions(+), 52 deletions(-) create mode 100755 bin/wkhtmltopdf-path diff --git a/Rakefile b/Rakefile index bc0af9e1..a32fc4fc 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 ec51b172..04fd90a9 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 00000000..5f1e98d2 --- /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 e69de29b..13086f63 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 51ef187c..ac46230f 100644 --- a/wkhtmltopdf-binary.gemspec +++ b/wkhtmltopdf-binary.gemspec @@ -1,23 +1,26 @@ -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" - - s.author = '- Research Information Systems, The University of Iowa' - s.homepage = '' - s.email = 'vpr-ris-developers@iowa.uiowa.edu,mcollas@aconex.com' +require 'rubygems' +require 'rubygems/package_task' - s.bindir = 'bin' - s.executables = %w(wkhtmltopdf) +spec = 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' +end - s.files = %w( - lib/wkhtmltopdf-binary.rb bin/wkhtmltopdf - libexec/wkhtmltopdf-darwin-x86 - libexec/wkhtmltopdf-linux-amd64 - libexec/wkhtmltopdf-linux-x86) +Gem::PackageTask.new(spec) do |pkg| + pkg.need_tar = true end + +spec From 197b48452c82c0653715890aa2f78e3769cff639 Mon Sep 17 00:00:00 2001 From: naquad Date: Fri, 21 Dec 2012 21:35:32 +0200 Subject: [PATCH 2/2] minor gemspec style fix --- wkhtmltopdf-binary.gemspec | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/wkhtmltopdf-binary.gemspec b/wkhtmltopdf-binary.gemspec index ac46230f..ea846b1e 100644 --- a/wkhtmltopdf-binary.gemspec +++ b/wkhtmltopdf-binary.gemspec @@ -1,7 +1,7 @@ require 'rubygems' require 'rubygems/package_task' -spec = Gem::Specification.new do |s| +Gem::Specification.new do |s| s.name = "wkhtmltopdf-binary" s.version = "0.10" s.author = "Research Information Systems, The University of Iowa" @@ -17,10 +17,8 @@ spec = Gem::Specification.new do |s| s.has_rdoc = false s.rdoc_options += ['-x', 'libexec/.*'] s.executables << "wkhtmltopdf" << 'wkhtmltopdf-path' -end -Gem::PackageTask.new(spec) do |pkg| - pkg.need_tar = true + Gem::PackageTask.new(s) do |pkg| + pkg.need_tar = true + end end - -spec