wicked_pdf 0.11.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +13 -3
- data/Gemfile +1 -1
- data/README.md +152 -142
- data/Rakefile +24 -12
- data/gemfiles/2.3.gemfile +2 -0
- data/gemfiles/3.1.gemfile +3 -2
- data/gemfiles/3.2.gemfile +3 -2
- data/gemfiles/4.0.gemfile +2 -2
- data/gemfiles/4.1.gemfile +6 -0
- data/gemfiles/4.2.gemfile +6 -0
- data/gemfiles/rails_edge.gemfile +3 -3
- data/generators/wicked_pdf/templates/wicked_pdf.rb +19 -3
- data/generators/wicked_pdf/wicked_pdf_generator.rb +1 -1
- data/lib/generators/wicked_pdf_generator.rb +2 -2
- data/lib/wicked_pdf.rb +241 -212
- data/lib/wicked_pdf/middleware.rb +6 -7
- data/lib/wicked_pdf/pdf_helper.rb +53 -53
- data/lib/wicked_pdf/railtie.rb +14 -14
- data/lib/wicked_pdf/tempfile.rb +2 -2
- data/lib/wicked_pdf/version.rb +2 -2
- data/lib/wicked_pdf/wicked_pdf_helper.rb +30 -15
- data/test/functional/pdf_helper_test.rb +5 -5
- data/test/functional/wicked_pdf_helper_assets_test.rb +35 -8
- data/test/functional/wicked_pdf_helper_test.rb +2 -2
- data/test/test_helper.rb +10 -5
- data/test/unit/wicked_pdf_test.rb +90 -57
- data/wicked_pdf.gemspec +5 -4
- metadata +20 -72
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -59
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -58
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
@@ -26,11 +26,11 @@ class WickedPdf
|
|
26
26
|
headers.delete('ETag')
|
27
27
|
headers.delete('Cache-Control')
|
28
28
|
|
29
|
-
headers[
|
30
|
-
headers[
|
29
|
+
headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
|
30
|
+
headers['Content-Type'] = 'application/pdf'
|
31
31
|
if @options.fetch(:disposition, '') == 'attachment'
|
32
|
-
headers[
|
33
|
-
headers[
|
32
|
+
headers['Content-Disposition'] = 'attachment'
|
33
|
+
headers['Content-Transfer-Encoding'] = 'binary'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -81,10 +81,9 @@ class WickedPdf
|
|
81
81
|
|
82
82
|
def set_request_to_render_as_pdf(env)
|
83
83
|
@render_pdf = true
|
84
|
-
|
85
|
-
%w[PATH_INFO REQUEST_URI].each { |e| env[e] = path }
|
84
|
+
%w(PATH_INFO REQUEST_URI).each { |e| env[e] = env[e].sub(%r{\.pdf\b}, '') }
|
86
85
|
env['HTTP_ACCEPT'] = concat(env['HTTP_ACCEPT'], Rack::Mime.mime_type('.html'))
|
87
|
-
env[
|
86
|
+
env['Rack-Middleware-WickedPdf'] = 'true'
|
88
87
|
end
|
89
88
|
|
90
89
|
def concat(accepts, type)
|
@@ -15,7 +15,7 @@ module PdfHelper
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def render_with_wicked_pdf(options = nil, *args, &block)
|
18
|
-
if options.is_a?(Hash) && options.
|
18
|
+
if options.is_a?(Hash) && options.key?(:pdf)
|
19
19
|
log_pdf_creation
|
20
20
|
options[:basic_auth] = set_basic_auth(options)
|
21
21
|
make_and_send_pdf(options.delete(:pdf), (WickedPdf.config || {}).merge(options))
|
@@ -25,7 +25,7 @@ module PdfHelper
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def render_to_string_with_wicked_pdf(options = nil, *args, &block)
|
28
|
-
if options.is_a?(Hash) && options.
|
28
|
+
if options.is_a?(Hash) && options.key?(:pdf)
|
29
29
|
log_pdf_creation
|
30
30
|
options[:basic_auth] = set_basic_auth(options)
|
31
31
|
options.delete :pdf
|
@@ -37,66 +37,66 @@ module PdfHelper
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def log_pdf_creation
|
41
|
+
logger.info '*' * 15 + 'WICKED' + '*' * 15 unless logger.nil?
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
44
|
+
def set_basic_auth(options = {})
|
45
|
+
options[:basic_auth] ||= WickedPdf.config.fetch(:basic_auth) { false }
|
46
|
+
if options[:basic_auth] && request.env['HTTP_AUTHORIZATION']
|
47
|
+
request.env['HTTP_AUTHORIZATION'].split(' ').last
|
49
48
|
end
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
51
|
+
def clean_temp_files
|
52
|
+
if defined?(@hf_tempfiles)
|
53
|
+
@hf_tempfiles.each { |tf| tf.close! }
|
55
54
|
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def make_pdf(options = {})
|
58
|
+
render_opts = { :template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers] }
|
59
|
+
render_opts.merge!(:locals => options[:locals]) if options[:locals]
|
60
|
+
render_opts.merge!(:file => options[:file]) if options[:file]
|
61
|
+
html_string = render_to_string(render_opts)
|
62
|
+
options = prerender_header_and_footer(options)
|
63
|
+
w = WickedPdf.new(options[:wkhtmltopdf])
|
64
|
+
w.pdf_from_string(html_string, options)
|
65
|
+
end
|
56
66
|
|
57
|
-
|
58
|
-
|
67
|
+
def make_and_send_pdf(pdf_name, options = {})
|
68
|
+
options[:wkhtmltopdf] ||= nil
|
69
|
+
options[:layout] ||= false
|
70
|
+
options[:template] ||= File.join(controller_path, action_name)
|
71
|
+
options[:disposition] ||= 'inline'
|
72
|
+
if options[:show_as_html]
|
73
|
+
render_opts = { :template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => 'text/html' }
|
59
74
|
render_opts.merge!(:locals => options[:locals]) if options[:locals]
|
60
75
|
render_opts.merge!(:file => options[:file]) if options[:file]
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def make_and_send_pdf(pdf_name, options={})
|
68
|
-
options[:wkhtmltopdf] ||= nil
|
69
|
-
options[:layout] ||= false
|
70
|
-
options[:template] ||= File.join(controller_path, action_name)
|
71
|
-
options[:disposition] ||= "inline"
|
72
|
-
if options[:show_as_html]
|
73
|
-
render_opts = {:template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => "text/html"}
|
74
|
-
render_opts.merge!(:locals => options[:locals]) if options[:locals]
|
75
|
-
render_opts.merge!(:file => options[:file]) if options[:file]
|
76
|
-
render(render_opts)
|
77
|
-
else
|
78
|
-
pdf_content = make_pdf(options)
|
79
|
-
File.open(options[:save_to_file], 'wb') {|file| file << pdf_content } if options[:save_to_file]
|
80
|
-
send_data(pdf_content, :filename => pdf_name + '.pdf', :type => 'application/pdf', :disposition => options[:disposition]) unless options[:save_only]
|
81
|
-
end
|
76
|
+
render(render_opts)
|
77
|
+
else
|
78
|
+
pdf_content = make_pdf(options)
|
79
|
+
File.open(options[:save_to_file], 'wb') { |file| file << pdf_content } if options[:save_to_file]
|
80
|
+
send_data(pdf_content, :filename => pdf_name + '.pdf', :type => 'application/pdf', :disposition => options[:disposition]) unless options[:save_only]
|
82
81
|
end
|
82
|
+
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
84
|
+
# Given an options hash, prerenders content for the header and footer sections
|
85
|
+
# to temp files and return a new options hash including the URLs to these files.
|
86
|
+
def prerender_header_and_footer(options)
|
87
|
+
[:header, :footer].each do |hf|
|
88
|
+
if options[hf] && options[hf][:html] && options[hf][:html][:template]
|
89
|
+
@hf_tempfiles = [] unless defined?(@hf_tempfiles)
|
90
|
+
@hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html"))
|
91
|
+
options[hf][:html][:layout] ||= options[:layout]
|
92
|
+
render_opts = { :template => options[hf][:html][:template], :layout => options[hf][:html][:layout], :formats => options[hf][:html][:formats], :handlers => options[hf][:html][:handlers] }
|
93
|
+
render_opts.merge!(:locals => options[hf][:html][:locals]) if options[hf][:html][:locals]
|
94
|
+
render_opts.merge!(:file => options[hf][:html][:file]) if options[:file]
|
95
|
+
tf.write render_to_string(render_opts)
|
96
|
+
tf.flush
|
97
|
+
options[hf][:html][:url] = "file:///#{tf.path}"
|
99
98
|
end
|
100
|
-
options
|
101
99
|
end
|
100
|
+
options
|
101
|
+
end
|
102
102
|
end
|
data/lib/wicked_pdf/railtie.rb
CHANGED
@@ -3,41 +3,41 @@ require 'wicked_pdf/wicked_pdf_helper'
|
|
3
3
|
|
4
4
|
if defined?(Rails)
|
5
5
|
|
6
|
-
if Rails::VERSION::MAJOR ==
|
6
|
+
if Rails::VERSION::MAJOR == 3
|
7
7
|
|
8
8
|
class WickedRailtie < Rails::Railtie
|
9
|
-
initializer
|
9
|
+
initializer 'wicked_pdf.register' do |app|
|
10
10
|
ActionController::Base.send :include, PdfHelper
|
11
|
-
|
11
|
+
if Rails::VERSION::MINOR > 0 && Rails.configuration.assets.enabled
|
12
|
+
ActionView::Base.send :include, WickedPdfHelper::Assets
|
13
|
+
else
|
14
|
+
ActionView::Base.send :include, WickedPdfHelper
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
19
|
elsif Rails::VERSION::MAJOR == 2
|
16
20
|
|
17
|
-
unless ActionController::Base.instance_methods.include?
|
21
|
+
unless ActionController::Base.instance_methods.include? 'render_with_wicked_pdf'
|
18
22
|
ActionController::Base.send :include, PdfHelper
|
19
23
|
end
|
20
|
-
unless ActionView::Base.instance_methods.include?
|
24
|
+
unless ActionView::Base.instance_methods.include? 'wicked_pdf_stylesheet_link_tag'
|
21
25
|
ActionView::Base.send :include, WickedPdfHelper
|
22
26
|
end
|
23
|
-
|
27
|
+
|
24
28
|
else
|
25
29
|
|
26
30
|
class WickedRailtie < Rails::Railtie
|
27
|
-
initializer
|
31
|
+
initializer 'wicked_pdf.register' do |app|
|
28
32
|
ActionController::Base.send :include, PdfHelper
|
29
|
-
|
30
|
-
ActionView::Base.send :include, WickedPdfHelper::Assets
|
31
|
-
else
|
32
|
-
ActionView::Base.send :include, WickedPdfHelper
|
33
|
-
end
|
33
|
+
ActionView::Base.send :include, WickedPdfHelper::Assets
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
if Mime::Type.lookup_by_extension(:pdf).nil?
|
40
40
|
Mime::Type.register('application/pdf', :pdf)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
data/lib/wicked_pdf/tempfile.rb
CHANGED
@@ -2,10 +2,10 @@ require 'tempfile'
|
|
2
2
|
|
3
3
|
class WickedPdfTempfile < Tempfile
|
4
4
|
# ensures the Tempfile's filename always keeps its extension
|
5
|
-
def initialize(filename, temp_dir=nil)
|
5
|
+
def initialize(filename, temp_dir = nil)
|
6
6
|
temp_dir ||= Dir.tmpdir
|
7
7
|
extension = File.extname(filename)
|
8
8
|
basename = File.basename(filename, extension)
|
9
9
|
super([basename, extension], temp_dir)
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
data/lib/wicked_pdf/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
class WickedPdf
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
end
|
@@ -6,7 +6,7 @@ module WickedPdfHelper
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.add_extension(filename, extension)
|
9
|
-
(
|
9
|
+
(filename.to_s.split(".").include?(extension) ? filename : "#{filename}.#{extension}")
|
10
10
|
end
|
11
11
|
|
12
12
|
def wicked_pdf_stylesheet_link_tag(*sources)
|
@@ -18,34 +18,44 @@ module WickedPdfHelper
|
|
18
18
|
css_text.respond_to?(:html_safe) ? css_text.html_safe : css_text
|
19
19
|
end
|
20
20
|
|
21
|
-
def wicked_pdf_image_tag(img, options={})
|
21
|
+
def wicked_pdf_image_tag(img, options = {})
|
22
22
|
image_tag "file:///#{WickedPdfHelper.root_path.join('public', 'images', img)}", options
|
23
23
|
end
|
24
24
|
|
25
|
-
def wicked_pdf_javascript_src_tag(jsfile, options={})
|
25
|
+
def wicked_pdf_javascript_src_tag(jsfile, options = {})
|
26
26
|
jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
|
27
27
|
src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}"
|
28
|
-
content_tag(
|
28
|
+
content_tag('script', '', { 'type' => Mime::JS, 'src' => path_to_javascript(src) }.merge(options))
|
29
29
|
end
|
30
30
|
|
31
31
|
def wicked_pdf_javascript_include_tag(*sources)
|
32
|
-
js_text = sources.collect{ |source| wicked_pdf_javascript_src_tag(source, {}) }.join("\n")
|
32
|
+
js_text = sources.collect { |source| wicked_pdf_javascript_src_tag(source, {}) }.join("\n")
|
33
33
|
js_text.respond_to?(:html_safe) ? js_text.html_safe : js_text
|
34
34
|
end
|
35
35
|
|
36
36
|
module Assets
|
37
|
+
ASSET_URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/
|
38
|
+
|
37
39
|
def wicked_pdf_stylesheet_link_tag(*sources)
|
38
|
-
sources.collect
|
40
|
+
stylesheet_contents = sources.collect do |source|
|
39
41
|
source = WickedPdfHelper.add_extension(source, 'css')
|
40
42
|
"<style type='text/css'>#{read_asset(source)}</style>"
|
41
|
-
|
43
|
+
end.join("\n")
|
44
|
+
|
45
|
+
stylesheet_contents.gsub(ASSET_URL_REGEX) do
|
46
|
+
if Regexp.last_match[1].starts_with?('data:')
|
47
|
+
"url(#{Regexp.last_match[1]})"
|
48
|
+
else
|
49
|
+
"url(#{wicked_pdf_asset_path(Regexp.last_match[1])})"
|
50
|
+
end
|
51
|
+
end.html_safe
|
42
52
|
end
|
43
53
|
|
44
|
-
def wicked_pdf_image_tag(img, options={})
|
54
|
+
def wicked_pdf_image_tag(img, options = {})
|
45
55
|
image_tag wicked_pdf_asset_path(img), options
|
46
56
|
end
|
47
57
|
|
48
|
-
def wicked_pdf_javascript_src_tag(jsfile, options={})
|
58
|
+
def wicked_pdf_javascript_src_tag(jsfile, options = {})
|
49
59
|
jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
|
50
60
|
javascript_include_tag wicked_pdf_asset_path(jsfile), options
|
51
61
|
end
|
@@ -83,11 +93,16 @@ module WickedPdfHelper
|
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
86
|
-
#will prepend a http or default_protocol to a protocol
|
96
|
+
# will prepend a http or default_protocol to a protocol relative URL
|
97
|
+
# or when no protcol is set.
|
87
98
|
def set_protocol(source)
|
88
|
-
protocol = WickedPdf.config[:default_protocol] ||
|
89
|
-
|
90
|
-
|
99
|
+
protocol = WickedPdf.config[:default_protocol] || 'http'
|
100
|
+
if source[0, 2] == '//'
|
101
|
+
source = [protocol, ':', source].join
|
102
|
+
elsif source[0] != '/' && !source[0, 8].include?('://')
|
103
|
+
source = [protocol, '://', source].join
|
104
|
+
end
|
105
|
+
source
|
91
106
|
end
|
92
107
|
|
93
108
|
def precompiled_asset?(source)
|
@@ -95,7 +110,7 @@ module WickedPdfHelper
|
|
95
110
|
end
|
96
111
|
|
97
112
|
def read_asset(source)
|
98
|
-
if precompiled_asset?(source)
|
113
|
+
if precompiled_asset?(source)
|
99
114
|
if set_protocol(asset_path(source)) =~ URI_REGEXP
|
100
115
|
read_from_uri(source)
|
101
116
|
else
|
@@ -108,7 +123,7 @@ module WickedPdfHelper
|
|
108
123
|
|
109
124
|
def read_from_uri(source)
|
110
125
|
encoding = ':UTF-8' if RUBY_VERSION > '1.8'
|
111
|
-
asset = open(asset_pathname(source), "r#{encoding}") {|f| f.read }
|
126
|
+
asset = open(asset_pathname(source), "r#{encoding}") { |f| f.read }
|
112
127
|
asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
|
113
128
|
asset
|
114
129
|
end
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActionController
|
4
4
|
class Base
|
5
|
-
def render_to_string
|
5
|
+
def render_to_string(opts = {})
|
6
6
|
opts.to_s
|
7
7
|
end
|
8
8
|
end
|
@@ -14,13 +14,13 @@ class PdfHelperTest < ActionController::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def teardown
|
17
|
-
@ac=nil
|
17
|
+
@ac = nil
|
18
18
|
end
|
19
19
|
|
20
20
|
if Rails::VERSION::MAJOR == 2
|
21
|
-
test
|
22
|
-
options = @ac.send(
|
23
|
-
|
21
|
+
test 'should prerender header and footer :template options' do
|
22
|
+
options = @ac.send(:prerender_header_and_footer,
|
23
|
+
:header => { :html => { :template => 'hf.html.erb' } })
|
24
24
|
assert_match /^file:\/\/\/.*wicked_header_pdf.*\.html/, options[:header][:html][:url]
|
25
25
|
end
|
26
26
|
end
|
@@ -5,25 +5,52 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase
|
|
5
5
|
|
6
6
|
include WickedPdfHelper::Assets
|
7
7
|
|
8
|
-
if Rails::VERSION::MAJOR ==
|
9
|
-
test 'wicked_pdf_asset_path should return
|
8
|
+
if Rails::VERSION::MAJOR > 3 || (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0)
|
9
|
+
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server' do
|
10
10
|
expects(:asset_pathname => 'http://assets.domain.com/dummy.png')
|
11
11
|
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
12
12
|
end
|
13
13
|
|
14
|
-
test 'wicked_pdf_asset_path should return
|
14
|
+
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server using HTTPS' do
|
15
|
+
expects(:asset_path => 'https://assets.domain.com/dummy.png', 'precompiled_asset?' => true)
|
16
|
+
assert_equal 'https://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with relative urls' do
|
15
20
|
expects(:asset_path => '//assets.domain.com/dummy.png')
|
16
|
-
expects(
|
21
|
+
expects('precompiled_asset?' => true)
|
22
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with no protocol set' do
|
26
|
+
expects(:asset_path => 'assets.domain.com/dummy.png')
|
27
|
+
expects('precompiled_asset?' => true)
|
17
28
|
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
18
29
|
end
|
19
30
|
|
20
31
|
test 'wicked_pdf_asset_path should return a path when assets are precompiled' do
|
21
|
-
expects(
|
32
|
+
expects('precompiled_asset?' => false)
|
22
33
|
path = wicked_pdf_asset_path('application.css')
|
23
34
|
|
24
|
-
assert path.include?(
|
25
|
-
assert path.include?(
|
35
|
+
assert path.include?('/assets/stylesheets/application.css')
|
36
|
+
assert path.include?('file:///')
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'WickedPdfHelper::Assets::ASSET_URL_REGEX should match various URL data type formats' do
|
40
|
+
assert_match WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(\'/asset/stylesheets/application.css\');'
|
41
|
+
assert_match WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url("/asset/stylesheets/application.css");'
|
42
|
+
assert_match WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(/asset/stylesheets/application.css);'
|
43
|
+
assert_match WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(\'http://assets.domain.com/dummy.png\');'
|
44
|
+
assert_match WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url("http://assets.domain.com/dummy.png");'
|
45
|
+
assert_match WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(http://assets.domain.com/dummy.png);'
|
46
|
+
assert_no_match WickedPdfHelper::Assets::ASSET_URL_REGEX, '.url { \'http://assets.domain.com/dummy.png\' }'
|
26
47
|
end
|
27
|
-
end
|
28
48
|
|
49
|
+
test 'set_protocol should properly set the protocol when the asset is precompiled' do
|
50
|
+
assert_equal 'http://assets.domain.com/dummy.png', set_protocol('//assets.domain.com/dummy.png')
|
51
|
+
assert_equal '/assets.domain.com/dummy.png', set_protocol('/assets.domain.com/dummy.png')
|
52
|
+
assert_equal 'http://assets.domain.com/dummy.png', set_protocol('http://assets.domain.com/dummy.png')
|
53
|
+
assert_equal 'https://assets.domain.com/dummy.png', set_protocol('https://assets.domain.com/dummy.png')
|
54
|
+
end
|
55
|
+
end
|
29
56
|
end
|
@@ -9,12 +9,12 @@ class WickedPdfHelperTest < ActionView::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test 'wicked_pdf_image_tag should return the same as image_tag when passed a full path' do
|
12
|
-
assert_equal image_tag("file:///#{Rails.root.join('public','images','pdf')}"),
|
12
|
+
assert_equal image_tag("file:///#{Rails.root.join('public', 'images', 'pdf')}"),
|
13
13
|
wicked_pdf_image_tag('pdf')
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'wicked_pdf_javascript_src_tag should return the same as javascript_src_tag when passed a full path' do
|
17
|
-
assert_equal javascript_src_tag("file:///#{Rails.root.join('public','javascripts','pdf')}", {}),
|
17
|
+
assert_equal javascript_src_tag("file:///#{Rails.root.join('public', 'javascripts', 'pdf')}", {}),
|
18
18
|
wicked_pdf_javascript_src_tag('pdf')
|
19
19
|
end
|
20
20
|
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
# Configure Rails Environment
|
2
|
-
ENV[
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
|
+
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'mocha'
|
3
8
|
|
4
|
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
9
|
if Rails::VERSION::MAJOR == 2
|
6
|
-
require
|
10
|
+
require 'test_help'
|
7
11
|
else
|
8
|
-
require
|
12
|
+
require 'rails/test_help'
|
13
|
+
require 'mocha/test_unit'
|
9
14
|
end
|
10
15
|
|
11
|
-
require
|
16
|
+
require 'wicked_pdf'
|
12
17
|
|
13
18
|
Rails.backtrace_cleaner.remove_silencers!
|