Module: HrLite::PdfRenderer

Defined in:
app/services/hr_lite/pdf_renderer.rb

Overview

Slip PDF entry point. Host override first (earthly_vms plugs its cached WickedPdf service in via config.render_pdf); otherwise a built-in WickedPdf render when the gem is present; otherwise nil — the controller explains that PDF is not configured rather than crashing.

Class Method Summary collapse

Class Method Details

.render(template:, assigns:, cache_key: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'app/services/hr_lite/pdf_renderer.rb', line 7

def self.render(template:, assigns:, cache_key: nil)
  if HrLite.config.render_pdf
    HrLite.config.render_pdf.call(template: template, assigns: assigns, cache_key: cache_key)
  elsif wicked_pdf_class
    html = HrLite::ApplicationController.render(
      template: template, assigns: assigns, layout: "hr_lite/pdf", formats: [ :html ]
    )
    wicked_pdf_class.new.pdf_from_string(html, page_size: "A4")
  end
end

.wicked_pdf_classObject

Seam for tests and for hosts that lazy-load wicked_pdf.



19
20
21
# File 'app/services/hr_lite/pdf_renderer.rb', line 19

def self.wicked_pdf_class
  defined?(WickedPdf) ? WickedPdf : nil
end