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

Utilize activesupport lazy load hooks #52

Merged
merged 1 commit into from
Sep 12, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

* `Unreleased` - [View Diff](https://github.com/cortiz/prawn-rails/compare/v1.4.2...master)
- [#52](https://github.com/cortiz/prawn-rails/pull/52) - Add active_support as a dependency and use the active_support lazy load hooks
- Remove unnecessary method `get_metadata` from `PrawnRailsHelper` which was getting included into `ActionView::Base`
- Remove unnecessary rescue in `PrawnRails.config`
- Remove redundant method `PrawnRails::Document.extensions`
Expand Down
20 changes: 12 additions & 8 deletions lib/prawn-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
require "prawn-rails/version"
require "prawn-rails/config"

require "prawn-rails/rails_helper"
require "prawn-rails/renderer"
require 'active_support/lazy_load_hooks'

ActionView::Base.send(:include, PrawnRails::RailsHelper)
ActionView::Template.register_template_handler(:prawn, PrawnRails::Renderer)

unless Mime::Type.lookup_by_extension(:pdf)
Mime::Type.register_alias("application/pdf", :pdf)
module PrawnRails
end

module PrawnRails
ActiveSupport.on_load(:action_view) do
unless Mime::Type.lookup_by_extension(:pdf)
Mime::Type.register_alias("application/pdf", :pdf)
end

require "prawn-rails/rails_helper"
require "prawn-rails/renderer"

ActionView::Base.send(:include, PrawnRails::RailsHelper)
ActionView::Template.register_template_handler(:prawn, PrawnRails::Renderer)
end
6 changes: 2 additions & 4 deletions prawn-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ Gem::Specification.new do |s|
s.add_dependency "prawn"
s.add_dependency "prawn-table"
s.add_dependency "actionview", ">= 3.1.0"
s.add_dependency "activesupport", ">= 3.1.0"

s.add_development_dependency "pdf-reader"
s.add_development_dependency 'rake'
s.add_development_dependency 'minitest'
s.add_development_dependency 'pry'
s.add_development_dependency 'warning'

if RUBY_VERSION.to_f >= 3.1
s.add_development_dependency 'matrix'
end

if RUBY_VERSION.to_f >= 2.4
s.add_development_dependency 'warning'
end
end
18 changes: 7 additions & 11 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
ENV["RAILS_ENV"] = "test"

begin
require 'warning'
require 'warning'

Warning.ignore(
%r{mail/parsers/address_lists_parser}, ### Hide mail gem warnings
)
Warning.ignore(
%r{mail/parsers/address_lists_parser}, ### Hide mail gem warnings
)

Warning.ignore(
%r{pdf/reader/font.* assigned but unused variable}, ### Hide pdf/reader gem warnings
)
rescue LoadError
# Do nothing
end
Warning.ignore(
%r{pdf/reader/font.* assigned but unused variable}, ### Hide pdf/reader gem warnings
)

if RUBY_VERSION.to_f >= 3.1
require "matrix"
Expand Down
2 changes: 2 additions & 0 deletions test/unit/rails_helpers_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'test_helper'

require "prawn-rails/rails_helper"

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

Expand Down
Loading