-
Notifications
You must be signed in to change notification settings - Fork 39
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
Require any installed prawn extensions #29
Require any installed prawn extensions #29
Conversation
lib/prawn-rails/document.rb
Outdated
require 'prawn' | ||
require 'prawn/table' | ||
require "prawn-rails/extension" | ||
Gem::Specification.find_all{|s| s.name =~ /prawn/}.map(&:name).each do |gem_name| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the condition for find_all should probably bes.name.start_with?('prawn-')
lib/prawn-rails/document.rb
Outdated
@@ -1,6 +1,9 @@ | |||
require 'prawn' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-add this require prawn and remove require prawn from the loop.
We need to be careful with requiring random files as it could prove to be brittle. Please verify and test with all prawn plugins and report if any cause error during require time. For a list see: https://rubygems.org/search?utf8=%E2%9C%93&query=prawn- For Bundler, did you ensure this searches within the bundled gems only? and does not included other installed gems within the current Ruby version? |
lib/prawn-rails/document.rb
Outdated
@@ -1,6 +1,9 @@ | |||
require 'prawn' | |||
require 'prawn/table' | |||
require "prawn-rails/extension" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-add require "prawn-rails/extension" after this loop and remove from inside the loop
…rawn-rails into require-prawn-extensions
@westonganger I've updated the PR to address your feedback. This will now only search within the bundled gems, as Bundler ensures that only the bundled gems are loaded. I've tested with a good chunk of the more used Prawn extensions in the list on rubygems. Of those that are still supported and can be bundled with a current version of Prawn, only |
Also I think it will be a good idea rescue |
Okay this looks good enough. I'm going to merge this. Note im planning to adjust the puts to something simple instead of the exception output. |
v1.1.0 released which includes this feature. |
I just discovered this as I was working on #30 and, at the very least, this seems to be a solution in search of a problem and is likely unnecessary. It could cause unwanted behavior when loading dependencies. With the below Gemfile we can expect that gem "prawn-rails" With the below Gemfile and this PR in place, it seems expected that gem "prawn-rails"
gem "prawn-svg"
gem "prawn-icon" For one last example, the developer's expectation in the below Gemfile is that gem "prawn-rails"
gem "prawn-svg", require: false |
I can only tell you that it was an actual issue I ran into when trying to integrate I don’t think it is unreasonable for every prawn extension to be available to |
Until I receive a report where this feature "actually" effected someone then I am inclined to keep it, since like @CodingAnarchy states, it solves a real world issue. One idea to mitigate would be to add an alternative require method that doesn't load plugins. Example: # Gemfile
gem 'prawn-rails' ### loads with all plugins
# or
gem 'prawn-rail', require: ['just_prawn_rails'] ### loads with only prawn-table |
That's fair though my gut is telling me it's fixing a symptom but not the root cause. If I have time, I'll try to recreate the issue that @CodingAnarchy was having in #28. |
@gaffneyc I would love a full review of the situation and to discuss an alternative PR if you are so inclined. |
In adding Essentially the problem appears to do with the order the plug-ins are required and the use of My first thought is it may be possible to refactor out the |
This will search the loaded
Gem::Specification
for anything that matches the nameprawn
and require it as appropriate when loadingprawn-rails
. This assumes that extensions, other thanprawn-rails
, are named in a particular fashion (such that the gem isprawn-<extension>
and is required withrequire prawn/<extension>
), but I have only tested and verified that it works withprawn-emoji
andprawn-table
.Closes #28.