Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Prawn::Document.extensions in favor of custom plug-in loading #31

Merged
merged 3 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source "http://rubygems.org"

gem 'prawn-svg', require: false # to test prawn plugin LoadError

gemspec
6 changes: 5 additions & 1 deletion lib/prawn-rails/document.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require 'prawn'
require 'prawn-rails/load_prawn_plugins'
require 'prawn/table'

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 self.extensions
Prawn::Document.extensions
end

def initialize(opts = {})
if PrawnRails.config.respond_to?(:to_h)
default = PrawnRails.config.to_h.merge(opts)
Expand Down
11 changes: 0 additions & 11 deletions lib/prawn-rails/load_prawn_plugins.rb

This file was deleted.

4 changes: 0 additions & 4 deletions test/dummy_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

Bundler.require

silence_warnings do
require 'prawn-svg'
end

require "prawn-rails"

module Dummy
Expand Down
18 changes: 15 additions & 3 deletions test/prawn_rails_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
### FOR GENERIC NON-RAILS TESTS

require 'test_helper'
require 'pdf/reader'

class PrawnRailsTest < ActiveSupport::TestCase
include PrawnRails::RailsHelper

test "config" do
assert true
end
test "text can take non strings" do
@filename = ""

output = prawn_document do |pdf|
pdf.text "Number:"
pdf.text 10
end

reader = PDF::Reader.new(StringIO.new(output))
assert_not_nil(reader)

page = reader.page(1).to_s
assert page.include?("Number:\n10")
end
end