2019-10-17 19:30:14 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
WickedPdf.config ||= {}
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2019-10-17 19:30:14 +08:00
|
|
|
ENV['PATH'].split(':').each do |path|
|
|
|
|
exe_path = File.join(path, 'wkhtmltopdf')
|
|
|
|
WickedPdf.config[:exe_path] = File.join(path, 'wkhtmltopdf') if File.file?(exe_path)
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
|
|
# WickedPdfHelper patch that fixes issue with including application.css
|
2016-07-21 19:11:15 +08:00
|
|
|
# in environments like Heroku where assets.compile option is disabled and
|
2016-02-12 23:52:43 +08:00
|
|
|
# it is not acceptable to enable it.
|
2019-10-17 19:30:14 +08:00
|
|
|
if Rails.env.production? && Rails.configuration.assets.compile == false
|
2017-07-07 19:19:39 +08:00
|
|
|
WickedPdf::WickedPdfHelper::Assets.module_eval do
|
2016-02-12 23:52:43 +08:00
|
|
|
def read_asset(source)
|
2019-10-17 19:30:14 +08:00
|
|
|
manifest = Rails.application.assets_manifest
|
|
|
|
path = File.join(manifest.dir, manifest.assets[source])
|
|
|
|
File.read(path)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def asset_exists?(source)
|
2019-10-17 19:30:14 +08:00
|
|
|
Rails.application.assets_manifest.assets.key?(source)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|