Sha256: f8205c41f08a0e59a1a777a2f3caf92d3140286652c02578b4ca5d6e6491a16f

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

require "active_support/concern"

module Renalware
  module Concerns
    module PdfRenderable
      extend ActiveSupport::Concern

      included do
        def default_pdf_options
          {
            page_size: "A4",
            layout: "renalware/layouts/pdf",
            disposition: "inline",
            footer: {
              font_size: 8,
              right: "Page [page] of [topage]"
            },
            show_as_html: Rails.env.development? && params.key?(:debug),
            encoding: "UTF-8"
          }
        end

        # Render a Liquid template loaded from the database.
        # The template may have variable place holders w.g. {{ patient.name }} and these
        # are resolved by passing instance of Liquid Drops (presenters) in the variables hash.
        def render_liquid_template_to_pdf(template_name:, filename:, variables: nil)
          variables ||= default_liquid_variables
          body = System::RenderLiquidTemplate.call(template_name: template_name,
                                                   variables: variables)
          options = default_pdf_options.merge!(pdf: filename, locals: { body: body })
          render options
        end

        private

        # By default if no variables supplied, we insert the patient drop to allow basic patient
        # data to be accessed in the template with eg {{ patient.name }}
        # Note the has key must be a string and not a symbol.
        def default_liquid_variables
          { "patient" => Patients::PatientDrop.new(patient) }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
renalware-core-2.0.15 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.14 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.13 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.12 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.11 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.9 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.8 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.7 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.5 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.4 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.3 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.2 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.1 app/controllers/renalware/concerns/pdf_renderable.rb
renalware-core-2.0.0 app/controllers/renalware/concerns/pdf_renderable.rb