class PDFKit::Configuration

Attributes

default_options[RW]
meta_tag_prefix[RW]
root_url[RW]
use_xvfb[W]
verbose[W]

Public Class Methods

new() click to toggle source
# File lib/pdfkit/configuration.rb, line 6
def initialize
  @verbose         = false
  @use_xvfb        = false
  @meta_tag_prefix = 'pdfkit-'
  @default_options = {
    :disable_smart_shrinking => false,
    :quiet => true,
    :page_size => 'Letter',
    :margin_top => '0.75in',
    :margin_right => '0.75in',
    :margin_bottom => '0.75in',
    :margin_left => '0.75in',
    :encoding => 'UTF-8'
  }
end

Public Instance Methods

default_wkhtmltopdf() click to toggle source
# File lib/pdfkit/configuration.rb, line 26
def default_wkhtmltopdf
  @default_command_path ||= (defined?(Bundler::GemfileError) && File.exists?('Gemfile') ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
end
executable() click to toggle source
# File lib/pdfkit/configuration.rb, line 39
def executable
  using_xvfb? ? "xvfb-run #{wkhtmltopdf}" : wkhtmltopdf
end
quiet?() click to toggle source
# File lib/pdfkit/configuration.rb, line 47
def quiet?
  !@verbose
end
using_xvfb?() click to toggle source
# File lib/pdfkit/configuration.rb, line 43
def using_xvfb?
  @use_xvfb
end
verbose?() click to toggle source
# File lib/pdfkit/configuration.rb, line 51
def verbose?
  @verbose
end
wkhtmltopdf() click to toggle source
# File lib/pdfkit/configuration.rb, line 22
def wkhtmltopdf
  @wkhtmltopdf ||= default_wkhtmltopdf
end
wkhtmltopdf=(path) click to toggle source
# File lib/pdfkit/configuration.rb, line 30
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