lib/pdfkit/pdfkit.rb in pdfkit-0.4.1 vs lib/pdfkit/pdfkit.rb in pdfkit-0.4.2

- old
+ new

@@ -20,18 +20,19 @@ def initialize(url_file_or_html, options = {}) @source = Source.new(url_file_or_html) @stylesheets = [] - @options = normalize_options(PDFKit.configuration.default_options.merge(options)) + @options = PDFKit.configuration.default_options.merge(options) @options.merge! find_options_in_meta(url_file_or_html) unless source.url? + @options = normalize_options(@options) raise NoExecutableError.new unless File.exists?(PDFKit.configuration.wkhtmltopdf) end def command - args = [PDFKit.configuration.wkhtmltopdf] + args = [executable] args += @options.to_a.flatten.compact args << '--quiet' if @source.html? args << '-' # Get HTML from stdin @@ -39,9 +40,19 @@ args << @source.to_s end args << '-' # Read PDF from stdout args + end + + def executable + default = PDFKit.configuration.wkhtmltopdf + return default if default !~ /^\// # its not a path, so nothing we can do + if File.exist?(default) + default + else + default.split('/').last + end end def to_pdf append_stylesheets \ No newline at end of file