From 61170b89ea7a2d7e5a54f902a0204e32909d513a Mon Sep 17 00:00:00 2001 From: Wojtek Kruszewski Date: Thu, 26 Jan 2017 14:17:07 +0100 Subject: [PATCH 1/3] Handle situations when Rails module is defined without env Gems like rails-html-sanitizer open Rails namespace without requiring Rails. Instead check if Rails.env is defined. Similar to: https://github.com/rails/activeresource/pull/216 --- lib/wicked_pdf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index 62a321f5..50a9cc73 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -96,7 +96,7 @@ def pdf_from_url(url, options = {}) private def in_development_mode? - return Rails.env == 'development' if defined?(Rails) + return Rails.env == 'development' if defined?(Rails.env) RAILS_ENV == 'development' if defined?(RAILS_ENV) end From 1944170113bcfed3ec2b67df5013dc7f35698bfd Mon Sep 17 00:00:00 2001 From: Wojtek Kruszewski Date: Thu, 26 Jan 2017 14:46:29 +0100 Subject: [PATCH 2/3] Move condition before block to make Rubocop happy > lib/wicked_pdf.rb:198:5: C: Favor a normal unless-statement over a > modifier clause in a multiline statement. --- lib/wicked_pdf.rb | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index 50a9cc73..80497436 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -195,24 +195,26 @@ def make_options(options, names, prefix = '', type = :string) def parse_header_footer(options) r = [] - [:header, :footer].collect do |hf| - next if options[hf].blank? - opt_hf = options[hf] - r += make_options(opt_hf, [:center, :font_name, :left, :right], hf.to_s) - r += make_options(opt_hf, [:font_size, :spacing], hf.to_s, :numeric) - r += make_options(opt_hf, [:line], hf.to_s, :boolean) - if options[hf] && options[hf][:content] - @hf_tempfiles = [] unless defined?(@hf_tempfiles) - @hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html")) - tf.write options[hf][:content] - tf.flush - options[hf][:html] = {} - options[hf][:html][:url] = "file:///#{tf.path}" - end - unless opt_hf[:html].blank? - r += make_option("#{hf}-html", opt_hf[:html][:url]) unless opt_hf[:html][:url].blank? + unless options.blank? + [:header, :footer].collect do |hf| + next if options[hf].blank? + opt_hf = options[hf] + r += make_options(opt_hf, [:center, :font_name, :left, :right], hf.to_s) + r += make_options(opt_hf, [:font_size, :spacing], hf.to_s, :numeric) + r += make_options(opt_hf, [:line], hf.to_s, :boolean) + if options[hf] && options[hf][:content] + @hf_tempfiles = [] unless defined?(@hf_tempfiles) + @hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html")) + tf.write options[hf][:content] + tf.flush + options[hf][:html] = {} + options[hf][:html][:url] = "file:///#{tf.path}" + end + unless opt_hf[:html].blank? + r += make_option("#{hf}-html", opt_hf[:html][:url]) unless opt_hf[:html][:url].blank? + end end - end unless options.blank? + end r end From 0494c10b2962bdedbbe41945001a3db82cb433b1 Mon Sep 17 00:00:00 2001 From: Wojtek Kruszewski Date: Thu, 26 Jan 2017 16:33:02 +0100 Subject: [PATCH 3/3] Check for Rails application presence also in railtie.rb --- lib/wicked_pdf/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wicked_pdf/railtie.rb b/lib/wicked_pdf/railtie.rb index feac925f..95e2afa4 100644 --- a/lib/wicked_pdf/railtie.rb +++ b/lib/wicked_pdf/railtie.rb @@ -3,7 +3,7 @@ require 'wicked_pdf/wicked_pdf_helper/assets' class WickedPdf - if defined?(Rails) + if defined?(Rails.env) if Rails::VERSION::MAJOR >= 5