class DocumentExporter::PDF::Base
Constants
- TEMPLATE_EXTS
Public Class Methods
s3_folder()
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 6 def self.s3_folder @s3_folder ||= ENV.fetch('SWAP_DOCS', 'documents') end
Public Instance Methods
export()
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 10 def export WickedPdf.new.pdf_from_string(pdf_content, pdf_params) end
pdf_content()
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 14 def pdf_content content = render_template template_path('show'), layout: 'lcms/engine/cg_pdf' content.gsub(/(___+)/, '<span class="o-od-compress-underscore">\1</span>') end
Protected Instance Methods
combine_pdf_for(pdf, material_ids)
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 21 def combine_pdf_for(pdf, material_ids) material_ids.each do |id| next unless (url = @document.links['materials']&.dig(id.to_s, 'url')) pdf << CombinePDF.parse(Net::HTTP.get(URI.parse(url))) end pdf end
Private Instance Methods
base_path(name)
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 35 def base_path(name) custom_template_for(name).presence || File.join('lcms', 'engine', 'documents', 'pdf', name) end
custom_template_for(name)
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 39 def custom_template_for(name) result = '' Array .wrap(DocTemplate::Tags.config['pdf_templates_path']) .each do |path| file = TEMPLATE_EXTS .map { |ext| File.join path, "#{name}.#{ext}" } .detect { |f| File.exist? f } break if (result = file).present? end result end
pdf_custom_params()
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 52 def pdf_custom_params @document.config.slice(:margin, :dpi) end
pdf_params()
click to toggle source
# File lib/document_exporter/pdf/base.rb, line 56 def pdf_params { disable_internal_links: false, disable_external_links: false, disable_smart_shrinking: true, disposition: 'attachment', footer: { content: render_template(base_path('_footer'), layout: 'lcms/engine/cg_plain_pdf'), line: false, spacing: 2 }, javascript_delay: 500, orientation: @document.orientation, outline: { outline_depth: 3 }, page_size: 'Letter', print_media_type: false }.merge(pdf_custom_params) end