Class: Decidim::Exporters::PDF
- Defined in:
- lib/decidim/exporters/pdf.rb
Overview
Exports a PDF using the provided hash, given a collection and a Serializer. This is an abstract class that should be inherited to create PDF exporters, with each PDF exporter class setting the desired template, layout and orientation.
Instance Method Summary collapse
-
#export ⇒ Object
Public: Exports a PDF version of the collection by rendering the template into html and then converting it to PDF.
-
#layout ⇒ Object
implementing classes should return a valid ERB path here.
-
#locals ⇒ Object
This method may be overwritten if the template needs more local variables.
-
#orientation ⇒ Object
may be overwritten if needed.
-
#template ⇒ Object
implementing classes should return a valid ERB path here.
Methods inherited from Exporter
Constructor Details
This class inherits a constructor from Decidim::Exporters::Exporter
Instance Method Details
#export ⇒ Object
Public: Exports a PDF version of the collection by rendering the template into html and then converting it to PDF.
Returns an ExportData instance.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/decidim/exporters/pdf.rb', line 17 def export html = controller.render_to_string( template:, layout:, locals: ) document = WickedPdf.new.pdf_from_string(html, orientation:) ExportData.new(document, "pdf") end |
#layout ⇒ Object
implementing classes should return a valid ERB path here
40 41 42 |
# File 'lib/decidim/exporters/pdf.rb', line 40 def layout raise NotImplementedError end |
#locals ⇒ Object
This method may be overwritten if the template needs more local variables
45 46 47 |
# File 'lib/decidim/exporters/pdf.rb', line 45 def locals { collection: } end |
#orientation ⇒ Object
may be overwritten if needed
30 31 32 |
# File 'lib/decidim/exporters/pdf.rb', line 30 def orientation "Portrait" end |
#template ⇒ Object
implementing classes should return a valid ERB path here
35 36 37 |
# File 'lib/decidim/exporters/pdf.rb', line 35 def template raise NotImplementedError end |