hyper-smart-kit 0.0.1
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 +7 -0
- data/hyper-smart-kit.gemspec +11 -0
- data/wicked_pdf-2.8.2/CHANGELOG.md +254 -0
- data/wicked_pdf-2.8.2/Gemfile +3 -0
- data/wicked_pdf-2.8.2/LICENSE.txt +22 -0
- data/wicked_pdf-2.8.2/README.md +504 -0
- data/wicked_pdf-2.8.2/Rakefile +58 -0
- data/wicked_pdf-2.8.2/gemfiles/5.0.gemfile +8 -0
- data/wicked_pdf-2.8.2/gemfiles/5.1.gemfile +8 -0
- data/wicked_pdf-2.8.2/gemfiles/5.2.gemfile +9 -0
- data/wicked_pdf-2.8.2/gemfiles/6.0.gemfile +10 -0
- data/wicked_pdf-2.8.2/gemfiles/6.1.gemfile +11 -0
- data/wicked_pdf-2.8.2/gemfiles/7.0.gemfile +11 -0
- data/wicked_pdf-2.8.2/generators/wicked_pdf/templates/wicked_pdf.rb +30 -0
- data/wicked_pdf-2.8.2/generators/wicked_pdf/wicked_pdf_generator.rb +7 -0
- data/wicked_pdf-2.8.2/init.rb +2 -0
- data/wicked_pdf-2.8.2/lib/generators/wicked_pdf_generator.rb +155 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/binary.rb +65 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/middleware.rb +92 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/option_parser.rb +230 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/pdf_helper.rb +128 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/progress.rb +33 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/railtie.rb +17 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/tempfile.rb +43 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/version.rb +3 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/wicked_pdf_helper/assets.rb +332 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf/wicked_pdf_helper.rb +36 -0
- data/wicked_pdf-2.8.2/lib/wicked_pdf.rb +132 -0
- data/wicked_pdf-2.8.2/test/fixtures/database.yml +4 -0
- data/wicked_pdf-2.8.2/test/fixtures/document_with_long_line.html +16 -0
- data/wicked_pdf-2.8.2/test/fixtures/manifest.js +3 -0
- data/wicked_pdf-2.8.2/test/fixtures/subdirectory/nested.js +1 -0
- data/wicked_pdf-2.8.2/test/fixtures/wicked.css +1 -0
- data/wicked_pdf-2.8.2/test/fixtures/wicked.js +1 -0
- data/wicked_pdf-2.8.2/test/functional/pdf_helper_test.rb +96 -0
- data/wicked_pdf-2.8.2/test/functional/wicked_pdf_helper_assets_test.rb +252 -0
- data/wicked_pdf-2.8.2/test/functional/wicked_pdf_helper_test.rb +28 -0
- data/wicked_pdf-2.8.2/test/test_helper.rb +40 -0
- data/wicked_pdf-2.8.2/test/unit/wicked_pdf_binary_test.rb +26 -0
- data/wicked_pdf-2.8.2/test/unit/wicked_pdf_option_parser_test.rb +133 -0
- data/wicked_pdf-2.8.2/test/unit/wicked_pdf_test.rb +100 -0
- data/wicked_pdf-2.8.2/test/unit/wkhtmltopdf_location_test.rb +48 -0
- data/wicked_pdf-2.8.2/wicked_pdf.gemspec +42 -0
- metadata +82 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# wkhtml2pdf Ruby interface
|
|
2
|
+
# http://wkhtmltopdf.org/
|
|
3
|
+
|
|
4
|
+
require 'logger'
|
|
5
|
+
require 'digest/md5'
|
|
6
|
+
require 'rbconfig'
|
|
7
|
+
require 'open3'
|
|
8
|
+
require 'ostruct'
|
|
9
|
+
|
|
10
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
|
11
|
+
require 'active_support/core_ext/object/blank'
|
|
12
|
+
|
|
13
|
+
require 'wicked_pdf/version'
|
|
14
|
+
require 'wicked_pdf/railtie'
|
|
15
|
+
require 'wicked_pdf/option_parser'
|
|
16
|
+
require 'wicked_pdf/tempfile'
|
|
17
|
+
require 'wicked_pdf/binary'
|
|
18
|
+
require 'wicked_pdf/middleware'
|
|
19
|
+
require 'wicked_pdf/progress'
|
|
20
|
+
|
|
21
|
+
class WickedPdf
|
|
22
|
+
DEFAULT_BINARY_VERSION = Gem::Version.new('0.9.9')
|
|
23
|
+
@@config = {}
|
|
24
|
+
cattr_accessor :config, :silence_deprecations
|
|
25
|
+
|
|
26
|
+
include Progress
|
|
27
|
+
|
|
28
|
+
def self.config=(config)
|
|
29
|
+
::Kernel.warn 'WickedPdf.config= is deprecated and will be removed in future versions. Use WickedPdf.configure instead.' unless @@silence_deprecations
|
|
30
|
+
|
|
31
|
+
@@config = config
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.configure
|
|
35
|
+
config = OpenStruct.new(@@config)
|
|
36
|
+
yield config
|
|
37
|
+
|
|
38
|
+
@@config.merge! config.to_h
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.clear_config
|
|
42
|
+
@@config = {}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def initialize(wkhtmltopdf_binary_path = nil)
|
|
46
|
+
@binary = Binary.new(wkhtmltopdf_binary_path, DEFAULT_BINARY_VERSION)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def binary_version
|
|
50
|
+
@binary.version
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def pdf_from_html_file(filepath, options = {})
|
|
54
|
+
pdf_from_url("file:///#{filepath}", options)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def pdf_from_string(string, options = {})
|
|
58
|
+
options = options.dup
|
|
59
|
+
options.merge!(WickedPdf.config) { |_key, option, _config| option }
|
|
60
|
+
string_file = WickedPdf::Tempfile.new('wicked_pdf.html', options[:temp_path])
|
|
61
|
+
string_file.write_in_chunks(string)
|
|
62
|
+
pdf_from_html_file(string_file.path, options)
|
|
63
|
+
ensure
|
|
64
|
+
if options[:delete_temporary_files] && string_file
|
|
65
|
+
string_file.close!
|
|
66
|
+
elsif string_file
|
|
67
|
+
string_file.close
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
|
|
72
|
+
# merge in global config options
|
|
73
|
+
options.merge!(WickedPdf.config) { |_key, option, _config| option }
|
|
74
|
+
generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
|
|
75
|
+
command = [@binary.path]
|
|
76
|
+
command.unshift(@binary.xvfb_run_path) if options[:use_xvfb]
|
|
77
|
+
command += option_parser.parse(options)
|
|
78
|
+
command << url
|
|
79
|
+
command << generated_pdf_file.path.to_s
|
|
80
|
+
|
|
81
|
+
print_command(command.inspect) if in_development_mode?
|
|
82
|
+
|
|
83
|
+
if track_progress?(options)
|
|
84
|
+
invoke_with_progress(command, options)
|
|
85
|
+
else
|
|
86
|
+
_out, err, status = Open3.capture3(*command)
|
|
87
|
+
err = [status.to_s, err].join("\n") if !err.empty? || !status.success?
|
|
88
|
+
end
|
|
89
|
+
if options[:return_file]
|
|
90
|
+
return_file = options.delete(:return_file)
|
|
91
|
+
return generated_pdf_file
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
pdf = generated_pdf_file.read_in_chunks
|
|
95
|
+
|
|
96
|
+
raise "Error generating PDF\n Command Error: #{err}" if options[:raise_on_all_errors] && !err.empty?
|
|
97
|
+
raise "PDF could not be generated!\n Command Error: #{err}" if pdf && pdf.rstrip.empty?
|
|
98
|
+
|
|
99
|
+
pdf
|
|
100
|
+
rescue StandardError => e
|
|
101
|
+
raise "Failed to execute:\n#{command}\nError: #{e}"
|
|
102
|
+
ensure
|
|
103
|
+
clean_temp_files
|
|
104
|
+
generated_pdf_file.close! if generated_pdf_file && !return_file
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def in_development_mode?
|
|
110
|
+
return Rails.env == 'development' if defined?(Rails.env)
|
|
111
|
+
|
|
112
|
+
RAILS_ENV == 'development' if defined?(RAILS_ENV)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def on_windows?
|
|
116
|
+
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def print_command(cmd)
|
|
120
|
+
Rails.logger.debug '[wicked_pdf]: ' + cmd
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def option_parser
|
|
124
|
+
@option_parser ||= OptionParser.new(binary_version)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def clean_temp_files
|
|
128
|
+
return unless option_parser.hf_tempfiles.present?
|
|
129
|
+
|
|
130
|
+
option_parser.hf_tempfiles.each { |file| File.delete(file) }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
4
|
+
<body>
|
|
5
|
+
<div>
|
|
6
|
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
7
|
+
</div>
|
|
8
|
+
</body>
|
|
9
|
+
</html>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Nested js
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* Wicked styles */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Wicked js
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module ActionController
|
|
4
|
+
class Base
|
|
5
|
+
def render_to_string(opts = {})
|
|
6
|
+
opts.to_s
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.alias_method_chain(_target, _feature); end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ActionControllerMock
|
|
14
|
+
class Base
|
|
15
|
+
def render(_)
|
|
16
|
+
[:base]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def render_to_string; end
|
|
20
|
+
|
|
21
|
+
def self.after_action(_); end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class PdfHelperTest < ActionController::TestCase
|
|
26
|
+
module SomePatch
|
|
27
|
+
def render(_)
|
|
28
|
+
super.tap do |s|
|
|
29
|
+
s << :patched
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def setup
|
|
35
|
+
@ac = ActionController::Base.new
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def teardown
|
|
39
|
+
@ac = nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'should prerender header and footer :template options' do
|
|
43
|
+
options = @ac.send(:prerender_header_and_footer,
|
|
44
|
+
:header => { :html => { :template => 'hf.html.erb' } })
|
|
45
|
+
assert_match %r{^file:\/\/\/.*wicked_header_pdf.*\.html}, options[:header][:html][:url]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'should not interfere with already prepended patches' do
|
|
49
|
+
# Emulate railtie
|
|
50
|
+
if Rails::VERSION::MAJOR >= 5
|
|
51
|
+
# this spec tests the following:
|
|
52
|
+
# if another gem prepends a render method to ActionController::Base
|
|
53
|
+
# before wicked_pdf does, does calling render trigger an infinite loop?
|
|
54
|
+
# this spec fails with 6392bea1fe3a41682dfd7c20fd9c179b5a758f59 because PdfHelper
|
|
55
|
+
# aliases the render method prepended by the other gem to render_without_pdf, then
|
|
56
|
+
# base_evals its own definition of render, which calls render_with_pdf -> render_without_pdf.
|
|
57
|
+
# If the other gem uses the prepend inhertinance pattern (calling super instead of aliasing),
|
|
58
|
+
# when it calls super it calls the base_eval'd version of render instead of going up the
|
|
59
|
+
# inheritance chain, causing an infinite loop.
|
|
60
|
+
|
|
61
|
+
# This fiddling with consts is required to get around the fact that PdfHelper checks
|
|
62
|
+
# that it is being prepended to ActionController::Base
|
|
63
|
+
OriginalBase = ActionController::Base
|
|
64
|
+
ActionController.send(:remove_const, :Base)
|
|
65
|
+
ActionController.const_set(:Base, ActionControllerMock::Base)
|
|
66
|
+
|
|
67
|
+
# Emulate another gem being loaded before wicked
|
|
68
|
+
ActionController::Base.prepend(SomePatch)
|
|
69
|
+
ActionController::Base.prepend(::WickedPdf::PdfHelper)
|
|
70
|
+
|
|
71
|
+
begin
|
|
72
|
+
# test that wicked's render method is actually called
|
|
73
|
+
ac = ActionController::Base.new
|
|
74
|
+
ac.expects(:render_with_wicked_pdf)
|
|
75
|
+
ac.render(:cats)
|
|
76
|
+
|
|
77
|
+
# test that calling render does not trigger infinite loop
|
|
78
|
+
ac = ActionController::Base.new
|
|
79
|
+
assert_equal %i[base patched], ac.render(:cats)
|
|
80
|
+
rescue SystemStackError
|
|
81
|
+
assert_equal true, false # force spec failure
|
|
82
|
+
ensure
|
|
83
|
+
ActionController.send(:remove_const, :Base)
|
|
84
|
+
ActionController.const_set(:Base, OriginalBase)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
test 'should call after_action instead of after_filter when able' do
|
|
90
|
+
ActionController::Base.expects(:after_filter).with(:clean_temp_files).never
|
|
91
|
+
ActionController::Base.expects(:after_action).with(:clean_temp_files).once
|
|
92
|
+
ActionController::Base.class_eval do
|
|
93
|
+
include ::WickedPdf::PdfHelper
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'action_view/test_case'
|
|
3
|
+
|
|
4
|
+
class WickedPdfHelperAssetsTest < ActionView::TestCase
|
|
5
|
+
include WickedPdf::WickedPdfHelper::Assets
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
@saved_config = WickedPdf.config
|
|
9
|
+
WickedPdf.config = {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
teardown do
|
|
13
|
+
WickedPdf.config = @saved_config
|
|
14
|
+
|
|
15
|
+
# @see freerange/mocha#331
|
|
16
|
+
Rails.application.unstub(:assets)
|
|
17
|
+
Rails.application.unstub(:assets_manifest)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if Rails::VERSION::MAJOR > 3 || (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0)
|
|
21
|
+
test 'wicked_pdf_asset_base64 returns a base64 encoded asset' do
|
|
22
|
+
assert_match %r{data:text\/css;base64,.+}, wicked_pdf_asset_base64('wicked.css')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'wicked_pdf_asset_base64 works without file extension when using sprockets' do
|
|
26
|
+
assert_match %r{data:application\/javascript;base64,.+}, wicked_pdf_asset_base64('wicked')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'wicked_pdf_asset_base64 works with nested files and without file extension when using sprockets' do
|
|
30
|
+
assert_match %r{data:application\/javascript;base64,.+}, wicked_pdf_asset_base64('subdirectory/nested')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'wicked_pdf_asset_base64 works without file extension when using asset manifest' do
|
|
34
|
+
stub_manifest = OpenStruct.new(
|
|
35
|
+
:dir => Rails.root.join('app/assets'),
|
|
36
|
+
:assets => { 'wicked.css' => 'stylesheets/wicked.css', 'wicked.js' => 'javascripts/wicked.js' }
|
|
37
|
+
)
|
|
38
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
39
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
40
|
+
|
|
41
|
+
assert_match %r{data:text\/css;base64,.+}, wicked_pdf_asset_base64('wicked')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test 'wicked_pdf_asset_base64 works with nested files and without file extension when using asset manifest' do
|
|
45
|
+
stub_manifest = OpenStruct.new(
|
|
46
|
+
:dir => Rails.root.join('app/assets'),
|
|
47
|
+
:assets => { 'subdirectory/nested.js' => 'javascripts/subdirectory/nested.js' }
|
|
48
|
+
)
|
|
49
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
50
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
51
|
+
|
|
52
|
+
assert_match %r{data:text\/javascript;base64,.+}, wicked_pdf_asset_base64('subdirectory/nested')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
|
|
56
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
57
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n\n</style>",
|
|
58
|
+
wicked_pdf_stylesheet_link_tag('wicked')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'wicked_pdf_stylesheet_link_tag should work without file extension when using sprockets' do
|
|
62
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
63
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n\n</style>",
|
|
64
|
+
wicked_pdf_stylesheet_link_tag('wicked')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
test 'wicked_pdf_stylesheet_link_tag should work without file extension when using asset manifest' do
|
|
68
|
+
stub_manifest = OpenStruct.new(
|
|
69
|
+
:dir => Rails.root.join('app/assets'),
|
|
70
|
+
:assets => { 'wicked.css' => 'stylesheets/wicked.css', 'wicked.js' => 'javascripts/wicked.js' }
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
74
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
75
|
+
|
|
76
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n</style>",
|
|
77
|
+
wicked_pdf_stylesheet_link_tag('wicked')
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
test 'wicked_pdf_stylesheet_link_tag should raise if the stylesheet is not available and config is set' do
|
|
81
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
82
|
+
WickedPdf.config[:raise_on_missing_assets] = true
|
|
83
|
+
assert_raise WickedPdf::WickedPdfHelper::Assets::MissingLocalAsset do
|
|
84
|
+
wicked_pdf_stylesheet_link_tag('non_existent')
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
test 'wicked_pdf_stylesheet_link_tag should return empty if the stylesheet is not available' do
|
|
89
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
90
|
+
assert_equal "<style type='text/css'></style>",
|
|
91
|
+
wicked_pdf_stylesheet_link_tag('non_existent')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
test 'wicked_pdf_stylesheet_link_tag should raise if the absolute path stylesheet is not available and config is set' do
|
|
95
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
96
|
+
WickedPdf.config[:raise_on_missing_assets] = true
|
|
97
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
98
|
+
assert_raise WickedPdf::WickedPdfHelper::Assets::MissingLocalAsset do
|
|
99
|
+
wicked_pdf_stylesheet_link_tag('/non_existent')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
test 'wicked_pdf_stylesheet_link_tag should return empty if the absolute path stylesheet is not available' do
|
|
104
|
+
Rails.configuration.assets.expects(:compile => true).twice
|
|
105
|
+
assert_equal "<style type='text/css'></style>",
|
|
106
|
+
wicked_pdf_stylesheet_link_tag('/non_existent')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in when assets are remote' do
|
|
110
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 200, :body => '/* Wicked styles */')
|
|
111
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
112
|
+
assert_equal "<style type='text/css'>/* Wicked styles */</style>",
|
|
113
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in when assets are remote and using asset manifest' do
|
|
117
|
+
stub_manifest = OpenStruct.new(
|
|
118
|
+
:dir => Rails.root.join('app/assets'),
|
|
119
|
+
:assets => { 'wicked.css' => 'stylesheets/wicked.css', 'wicked.js' => 'javascripts/wicked.js' }
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
Rails.application.stubs(:assets).returns(nil)
|
|
123
|
+
Rails.application.stubs(:assets_manifest).returns(stub_manifest)
|
|
124
|
+
|
|
125
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 200, :body => '/* Wicked styles */')
|
|
126
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
127
|
+
assert_equal "<style type='text/css'>/* Wicked styles */</style>",
|
|
128
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
test 'wicked_pdf_stylesheet_link_tag should raise if remote assets are not available and config is set' do
|
|
132
|
+
WickedPdf.config[:raise_on_missing_assets] = true
|
|
133
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 404, :body => 'File not found')
|
|
134
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
135
|
+
assert_raise WickedPdf::WickedPdfHelper::Assets::MissingRemoteAsset do
|
|
136
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
test 'wicked_pdf_stylesheet_link_tag should return empty if remote assets are not available' do
|
|
141
|
+
stub_request(:get, 'https://www.example.com/wicked.css').to_return(:status => 404, :body => 'File not found')
|
|
142
|
+
expects(:precompiled_or_absolute_asset? => true).twice
|
|
143
|
+
assert_equal "<style type='text/css'></style>",
|
|
144
|
+
wicked_pdf_stylesheet_link_tag('https://www.example.com/wicked.css')
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
test 'wicked_pdf_image_tag should return the same as image_tag when passed a full path' do
|
|
148
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
149
|
+
assert_equal image_tag("file:///#{Rails.root.join('public', 'pdf')}"),
|
|
150
|
+
wicked_pdf_image_tag('pdf')
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
test 'wicked_pdf_javascript_include_tag should inline the javascripts passed in' do
|
|
154
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
155
|
+
assert_equal "<script type='text/javascript'>// Wicked js\n;\n</script>",
|
|
156
|
+
wicked_pdf_javascript_include_tag('wicked')
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server' do
|
|
160
|
+
expects(:asset_pathname => 'http://assets.domain.com/dummy.png')
|
|
161
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
test 'wicked_pdf_asset_path should return a url when assets are served by an asset server using HTTPS' do
|
|
165
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
166
|
+
expects(:asset_path => 'https://assets.domain.com/dummy.png')
|
|
167
|
+
assert_equal 'https://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test 'wicked_pdf_asset_path should return a url with a protocol when assets are served by an asset server with relative urls' do
|
|
171
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
172
|
+
expects(:asset_path => '//assets.domain.com/dummy.png')
|
|
173
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
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
|
|
177
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
178
|
+
expects(:asset_path => 'assets.domain.com/dummy.png')
|
|
179
|
+
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
test 'wicked_pdf_asset_path should return a path' do
|
|
183
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
184
|
+
path = wicked_pdf_asset_path('application.css')
|
|
185
|
+
|
|
186
|
+
assert path.include?('/app/assets/stylesheets/application.css')
|
|
187
|
+
assert path.include?('file:///')
|
|
188
|
+
|
|
189
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
190
|
+
expects(:asset_path => '/assets/application-6fba03f13d6ff1553477dba03475c4b9b02542e9fb8913bd63c258f4de5b48d9.css')
|
|
191
|
+
path = wicked_pdf_asset_path('application.css')
|
|
192
|
+
|
|
193
|
+
assert path.include?('/public/assets/application-6fba03f13d6ff1553477dba03475c4b9b02542e9fb8913bd63c258f4de5b48d9.css')
|
|
194
|
+
assert path.include?('file:///')
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# This assets does not exists so probably it doesn't matter what is
|
|
198
|
+
# returned, but lets ensure that returned value is the same when assets
|
|
199
|
+
# are precompiled and when they are not
|
|
200
|
+
test 'wicked_pdf_asset_path should return a path when asset does not exist' do
|
|
201
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
202
|
+
path = wicked_pdf_asset_path('missing.png')
|
|
203
|
+
|
|
204
|
+
assert path.include?('/public/missing.png')
|
|
205
|
+
assert path.include?('file:///')
|
|
206
|
+
|
|
207
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
208
|
+
expects(:asset_path => '/missing.png')
|
|
209
|
+
path = wicked_pdf_asset_path('missing.png')
|
|
210
|
+
|
|
211
|
+
assert path.include?('/public/missing.png')
|
|
212
|
+
assert path.include?('file:///')
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
test 'wicked_pdf_asset_path should return a url when asset is url' do
|
|
216
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
217
|
+
expects(:asset_path => 'http://example.com/rails.png')
|
|
218
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('http://example.com/rails.png')
|
|
219
|
+
|
|
220
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
221
|
+
expects(:asset_path => 'http://example.com/rails.png')
|
|
222
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('http://example.com/rails.png')
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
test 'wicked_pdf_asset_path should return a url when asset is url without protocol' do
|
|
226
|
+
Rails.configuration.assets.expects(:compile => true)
|
|
227
|
+
expects(:asset_path => '//example.com/rails.png')
|
|
228
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('//example.com/rails.png')
|
|
229
|
+
|
|
230
|
+
Rails.configuration.assets.expects(:compile => false)
|
|
231
|
+
expects(:asset_path => '//example.com/rails.png')
|
|
232
|
+
assert_equal 'http://example.com/rails.png', wicked_pdf_asset_path('//example.com/rails.png')
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
test 'WickedPdfHelper::Assets::ASSET_URL_REGEX should match various URL data type formats' do
|
|
236
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(\'/asset/stylesheets/application.css\');'
|
|
237
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url("/asset/stylesheets/application.css");'
|
|
238
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(/asset/stylesheets/application.css);'
|
|
239
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(\'http://assets.domain.com/dummy.png\');'
|
|
240
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url("http://assets.domain.com/dummy.png");'
|
|
241
|
+
assert_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, 'url(http://assets.domain.com/dummy.png);'
|
|
242
|
+
assert_no_match WickedPdf::WickedPdfHelper::Assets::ASSET_URL_REGEX, '.url { \'http://assets.domain.com/dummy.png\' }'
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
test 'prepend_protocol should properly set the protocol when the asset is precompiled' do
|
|
246
|
+
assert_equal 'http://assets.domain.com/dummy.png', prepend_protocol('//assets.domain.com/dummy.png')
|
|
247
|
+
assert_equal '/assets.domain.com/dummy.png', prepend_protocol('/assets.domain.com/dummy.png')
|
|
248
|
+
assert_equal 'http://assets.domain.com/dummy.png', prepend_protocol('http://assets.domain.com/dummy.png')
|
|
249
|
+
assert_equal 'https://assets.domain.com/dummy.png', prepend_protocol('https://assets.domain.com/dummy.png')
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'action_view/test_case'
|
|
3
|
+
|
|
4
|
+
class WickedPdfHelperTest < ActionView::TestCase
|
|
5
|
+
include WickedPdf::WickedPdfHelper
|
|
6
|
+
|
|
7
|
+
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
|
|
8
|
+
assert_equal "<style type='text/css'>/* Wicked styles */\n</style>",
|
|
9
|
+
wicked_pdf_stylesheet_link_tag('../../../fixtures/wicked')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'wicked_pdf_image_tag should return the same as image_tag when passed a full path' do
|
|
13
|
+
assert_equal image_tag("file:///#{Rails.root.join('public', 'images', 'pdf')}"),
|
|
14
|
+
wicked_pdf_image_tag('pdf')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if Rails::VERSION::MAJOR == 2
|
|
18
|
+
test 'wicked_pdf_javascript_src_tag should return the same as javascript_src_tag when passed a full path' do
|
|
19
|
+
assert_equal javascript_src_tag("file:///#{Rails.root.join('public', 'javascripts', 'pdf')}", {}),
|
|
20
|
+
wicked_pdf_javascript_src_tag('pdf')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test 'wicked_pdf_include_tag should return many wicked_pdf_javascript_src_tags' do
|
|
25
|
+
assert_equal [wicked_pdf_javascript_src_tag('foo'), wicked_pdf_javascript_src_tag('bar')].join("\n"),
|
|
26
|
+
wicked_pdf_javascript_include_tag('foo', 'bar')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
|
5
|
+
|
|
6
|
+
require 'test/unit'
|
|
7
|
+
require 'mocha'
|
|
8
|
+
require 'rails/test_help'
|
|
9
|
+
require 'mocha/test_unit'
|
|
10
|
+
require 'webmock/minitest'
|
|
11
|
+
|
|
12
|
+
require 'wicked_pdf'
|
|
13
|
+
|
|
14
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
15
|
+
WickedPdf.silence_deprecations = true
|
|
16
|
+
|
|
17
|
+
if (assets_dir = Rails.root.join('app/assets')) && File.directory?(assets_dir)
|
|
18
|
+
# Copy CSS file
|
|
19
|
+
destination = assets_dir.join('stylesheets/wicked.css')
|
|
20
|
+
source = File.read('test/fixtures/wicked.css')
|
|
21
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
22
|
+
|
|
23
|
+
# Copy JS file
|
|
24
|
+
js_dir = assets_dir.join('javascripts')
|
|
25
|
+
Dir.mkdir(js_dir) unless File.directory?(js_dir)
|
|
26
|
+
destination = js_dir.join('wicked.js')
|
|
27
|
+
source = File.read('test/fixtures/wicked.js')
|
|
28
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
29
|
+
|
|
30
|
+
Dir.mkdir(js_dir.join('subdirectory')) unless File.directory?(js_dir.join('subdirectory'))
|
|
31
|
+
destination = js_dir.join('subdirectory/nested.js')
|
|
32
|
+
source = File.read('test/fixtures/subdirectory/nested.js')
|
|
33
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
34
|
+
|
|
35
|
+
config_dir = assets_dir.join('config')
|
|
36
|
+
Dir.mkdir(config_dir) unless File.directory?(config_dir)
|
|
37
|
+
source = File.read('test/fixtures/manifest.js')
|
|
38
|
+
destination = config_dir.join('manifest.js')
|
|
39
|
+
File.open(destination, 'w') { |f| f.write(source) }
|
|
40
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class WickedPdfBinaryTest < ActiveSupport::TestCase
|
|
4
|
+
test 'should extract old wkhtmltopdf version' do
|
|
5
|
+
version_info_sample = "Name:\n wkhtmltopdf 0.9.9\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
|
|
6
|
+
assert_equal WickedPdf::DEFAULT_BINARY_VERSION, binary.parse_version_string(version_info_sample)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test 'should extract new wkhtmltopdf version' do
|
|
10
|
+
version_info_sample = "Name:\n wkhtmltopdf 0.11.0 rc2\n\nLicense:\n Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.\n\n\n\n License LGPLv3+: GNU Lesser General Public License version 3 or later\n <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to\n change and redistribute it. There is NO WARRANTY, to the extent permitted by\n law.\n\nAuthors:\n Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by\n Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and\n Mario Silva."
|
|
11
|
+
assert_equal Gem::Version.new('0.11.0'), binary.parse_version_string(version_info_sample)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'should extract wkhtmltopdf version with nondigit symbols' do
|
|
15
|
+
version_info_sample = "Name:\n wkhtmltopdf 0.10.4b\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
|
|
16
|
+
assert_equal Gem::Version.new('0.10.4b'), binary.parse_version_string(version_info_sample)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'should fallback to default version on parse error' do
|
|
20
|
+
assert_equal WickedPdf::DEFAULT_BINARY_VERSION, binary.parse_version_string('')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def binary(path = nil)
|
|
24
|
+
WickedPdf::Binary.new(path)
|
|
25
|
+
end
|
|
26
|
+
end
|