You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
668 B
20 lines
668 B
module RenderExpand
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
ActionController.add_renderer :pdf do |template, options|
|
|
file = File.open(Rails.root.join('app/templates', template << '.html.erb'))
|
|
html = ERB.new(file.read).result(binding)
|
|
kit = PDFKit.new(html)
|
|
|
|
base_css = %w(app/templates/shared/main.css)
|
|
base_css.each { |css| kit.stylesheets << Rails.root.join(css) }
|
|
|
|
Array.wrap(options.delete(:stylesheets)).each do |path|
|
|
kit.stylesheets << Rails.root.join('app/templates', path)
|
|
end
|
|
|
|
send_data kit.to_pdf, filename: options[:filename], type: 'application/pdf'
|
|
end
|
|
end
|
|
end |