Sha256: 2e36a4ad3fd490a67256464d40a03c191166d1cdcabb2e80fefecf3f1027d0cd

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

require 'prawn'
require 'prawn/table'
require "prawn-rails/extension"

module PrawnRails
  # This derives from Prawn::Document in order to override defaults. Note
  # that the Prawn::Document behaviour itself shouldn't be changed.
  class Document < Prawn::Document
    def initialize(opts = {})
      default = PrawnRails.config.to_h.merge(opts)
      super(default)
    end

    # Typicall text expects a string. But rails views have this interesting
    # concept that they implicitly call `to_s` on all the variables before
    # rendering. So, passing an integer to text fails:
    #
    # pdf.text 10       #=> fails because 10 is not a string
    # pdf.text 10.to_s  #=> works
    #
    # To circumvent this situation, we call to_s on value, and delegate
    # action to actual Prawn::Document.
    def text(value, options = {})
      super(value.to_s, options)
    end
  end

  Document.extensions << Extension
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prawn-rails-0.1.1 lib/prawn-rails/document.rb