Sha256: 8a19fb043f2da2e6641f46b8c82cf0c8d43e72f8d59aca5761a426ca840934f6

Contents?: true

Size: 687 Bytes

Versions: 11

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true
require_relative 'template'
require 'prawn'

module Tilt
  # Prawn template implementation. See: http://prawnpdf.org
  class PrawnTemplate < Template
    self.default_mime_type = 'application/pdf'
    
    def prepare
      @options[:page_size] = 'A4' unless @options.has_key?(:page_size)
      @options[:page_layout] = :portrait unless @options.has_key?(:page_layout)
      @engine = ::Prawn::Document.new(@options)
    end
    
    def evaluate(scope, locals, &block)
      pdf = @engine
      locals = locals.dup
      locals[:pdf] = pdf
      super
      pdf.render
    end
    
    def precompiled_template(locals)
      @data.to_str
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
tilt-2.6.0 lib/tilt/prawn.rb
brakeman-7.0.0 bundle/ruby/3.1.0/gems/tilt-2.5.0/lib/tilt/prawn.rb
tilt-2.5.0 lib/tilt/prawn.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/prawn.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/tilt-2.4.0/lib/tilt/prawn.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/prawn.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/tilt-2.4.0/lib/tilt/prawn.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/tilt-2.4.0/lib/tilt/prawn.rb
tilt-2.4.0 lib/tilt/prawn.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/tilt-2.3.0/lib/tilt/prawn.rb
tilt-2.3.0 lib/tilt/prawn.rb