internetee-registry/app/models/invoice/pdf_generator.rb
Artur Beljajev 27ea790b28 Refactor invoice PDF generation, download and delivery
- Remove `Que::Mailer` (#895)
- Extract controllers
- Extract translations
- Convert HAML to ERB
- Add mailer preview
- Improve UI
- Remove unused routes
- Add tests
2019-04-11 13:04:42 +03:00

22 lines
No EOL
457 B
Ruby

class Invoice
class PdfGenerator
attr_reader :invoice
def initialize(invoice)
@invoice = invoice
end
def as_pdf
generator = PDFKit.new(invoice_html)
generator.to_pdf
end
private
def invoice_html
view = ActionView::Base.new(ActionController::Base.view_paths, invoice: invoice)
view.class_eval { include ApplicationHelper }
view.render(file: 'invoice/pdf', layout: false)
end
end
end