lib/pdfkit/configuration.rb in pdfkit-0.8.2 vs lib/pdfkit/configuration.rb in pdfkit-0.8.3

- old
+ new

@@ -1,9 +1,9 @@ class PDFKit class Configuration attr_accessor :meta_tag_prefix, :default_options, :root_url - attr_writer :wkhtmltopdf, :verbose + attr_writer :verbose def initialize @verbose = false @meta_tag_prefix = 'pdfkit-' @default_options = { @@ -17,10 +17,23 @@ :encoding => 'UTF-8' } end def wkhtmltopdf - @wkhtmltopdf ||= (defined?(Bundler::GemfileError) && File.exists?('Gemfile') ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp + @wkhtmltopdf ||= default_wkhtmltopdf + end + + def default_wkhtmltopdf + @default_command_path ||= (defined?(Bundler::GemfileError) && File.exists?('Gemfile') ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp + end + + def wkhtmltopdf=(path) + if File.exist?(path) + @wkhtmltopdf = path + else + warn "No executable found at #{path}. Will fall back to #{default_wkhtmltopdf}" unless File.exist?(path) + @wkhtmltopdf = default_wkhtmltopdf + end end def quiet? !@verbose end