wkhtml 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe WkHtml::ToImage::Converter do
4
+ let(:html_content) {'<html><bod>My Test</body></html>'}
5
+
6
+ it "can create" do
7
+ settings = WkHtml::ToImage::GlobalSettings.new()
8
+ expect(WkHtml::ToImage::Converter.create(settings, nil)).not_to be_nil
9
+ end
10
+
11
+ it "cannot use new" do
12
+ expect{WkHtml::ToImage::Converter.new()}.to raise_error(NoMethodError)
13
+ end
14
+
15
+ it "should raise when create missing settings" do
16
+ expect{WkHtml::ToImage::Converter.create('', nil)}.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it "can convert html" do
20
+ settings = WkHtml::ToImage::GlobalSettings.new()
21
+ settings['fmt'] = 'jpeg'
22
+ converter = WkHtml::ToImage::Converter.create(settings, html_content)
23
+ expect(converter.convert).to be true
24
+ end
25
+
26
+ it "can convert external" do
27
+ settings = WkHtml::ToImage::GlobalSettings.new()
28
+ settings['in'] = 'http://example.com/'
29
+ settings['fmt'] = 'jpeg'
30
+ converter = WkHtml::ToImage::Converter.create(settings, nil)
31
+ expect(converter.convert).to be true
32
+ end
33
+
34
+ it "should not allow multiple converts" do
35
+ settings = WkHtml::ToImage::GlobalSettings.new()
36
+ settings['fmt'] = 'jpeg'
37
+ converter = WkHtml::ToImage::Converter.create(settings, html_content)
38
+ expect(converter.convert).to be true
39
+ expect{converter.convert}.to raise_error(RuntimeError)
40
+ end
41
+
42
+ it "should freeze settings after convert" do
43
+ settings = WkHtml::ToImage::GlobalSettings.new()
44
+ converter = WkHtml::ToImage::Converter.create(settings, nil)
45
+ converter.convert
46
+ expect(settings.frozen?).to be true
47
+ end
48
+
49
+ it "can get http error code" do
50
+ settings = WkHtml::ToImage::GlobalSettings.new()
51
+ settings['in'] = 'http://example.com/'
52
+ settings['fmt'] = 'jpeg'
53
+ converter = WkHtml::ToImage::Converter.create(settings, nil)
54
+ converter.convert()
55
+ expect(converter.http_error_code).to be_nil
56
+ end
57
+
58
+ it "can get output" do
59
+ settings = WkHtml::ToImage::GlobalSettings.new()
60
+ settings['in'] = 'http://example.com/'
61
+ settings['fmt'] = 'jpeg'
62
+ converter = WkHtml::ToImage::Converter.create(settings, nil)
63
+ converter.convert()
64
+ output = converter.get_output().encode!(Encoding::BINARY)[0..3]
65
+ expect(output).to start_with("\xFF\xD8\xFF\xE0".force_encoding(Encoding::BINARY)) #JPEG
66
+ end
67
+
68
+ it "raises when converting on thread" do
69
+ settings = WkHtml::ToImage::GlobalSettings.new()
70
+ settings['fmt'] = 'jpeg'
71
+ converter = WkHtml::ToImage::Converter.create(settings, html_content)
72
+
73
+ expect do
74
+ Thread.new{ converter.convert() }.join()
75
+ end.to raise_error(RuntimeError)
76
+ end
77
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'support/to_x_settings'
3
+ require 'support/settings'
4
+
5
+ RSpec.describe WkHtml::ToImage::GlobalSettings do
6
+ include_examples 'to_x_settings', 'transparent'
7
+ include_examples 'settings', 'transparent'
8
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe WkHtml::ToPdf::Converter do
4
+ let(:html_content) {'<html><bod>My Test</body></html>'}
5
+
6
+ it "can create" do
7
+ settings = WkHtml::ToPdf::GlobalSettings.new()
8
+ expect(WkHtml::ToPdf::Converter.create(settings)).not_to be_nil
9
+ end
10
+
11
+ it "cannot use new" do
12
+ expect{WkHtml::ToPdf::Converter.new()}.to raise_error(NoMethodError)
13
+ end
14
+
15
+ it "should raise when create missing settings" do
16
+ expect{WkHtml::ToPdf::Converter.create('')}.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it "can add object nil" do
20
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
21
+ expect(converter.add_object(WkHtml::ToPdf::ObjectSettings.new(), nil)).to be_nil
22
+ end
23
+
24
+ it "should raise when add object missing settings" do
25
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
26
+ expect{converter.add_object('', nil)}.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "can add object html" do
30
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
31
+ expect(converter.add_object(WkHtml::ToPdf::ObjectSettings.new(), html_content)).to eq(html_content)
32
+ end
33
+
34
+ it "can convert html" do
35
+ settings = WkHtml::ToPdf::GlobalSettings.new()
36
+ converter = WkHtml::ToPdf::Converter.create(settings)
37
+ converter.add_object(WkHtml::ToPdf::ObjectSettings.new(), html_content)
38
+ expect(converter.convert).to be true
39
+ end
40
+
41
+ it "can convert external" do
42
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
43
+ settings = WkHtml::ToPdf::ObjectSettings.new()
44
+ settings['page'] = 'http://example.com/'
45
+ converter.add_object(settings, nil)
46
+ expect(converter.convert).to be true
47
+ end
48
+
49
+ it "should raise when no object added" do
50
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
51
+ expect{converter.convert}.to raise_error(RuntimeError)
52
+ end
53
+
54
+ it "should not allow multiple converts" do
55
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
56
+ converter.add_object(WkHtml::ToPdf::ObjectSettings.new(), html_content)
57
+ converter.convert()
58
+ expect{converter.convert}.to raise_error(RuntimeError)
59
+ end
60
+
61
+ it "should freeze settings after convert" do
62
+ settings = WkHtml::ToPdf::ObjectSettings.new()
63
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
64
+ converter.add_object(settings, html_content)
65
+ converter.convert
66
+ expect(settings.frozen?).to be true
67
+ end
68
+
69
+ it "can get http error code" do
70
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
71
+ settings = WkHtml::ToPdf::ObjectSettings.new()
72
+ settings['page'] = 'http://example.com/'
73
+ converter.add_object(settings, nil)
74
+ converter.convert()
75
+ expect(converter.http_error_code).to be_nil
76
+ end
77
+
78
+ it "can get output" do
79
+ converter = WkHtml::ToPdf::Converter.create(WkHtml::ToPdf::GlobalSettings.new())
80
+ settings = WkHtml::ToPdf::ObjectSettings.new()
81
+ settings['page'] = 'http://example.com/'
82
+ converter.add_object(settings, nil)
83
+ converter.convert()
84
+ output = converter.get_output()
85
+ expect(output).to_not be_nil
86
+ expect(output).to start_with('%PDF-')
87
+ end
88
+
89
+ it "raises when converting on thread" do
90
+ settings = WkHtml::ToPdf::GlobalSettings.new()
91
+ converter = WkHtml::ToPdf::Converter.create(settings)
92
+ converter.add_object(WkHtml::ToPdf::ObjectSettings.new(), html_content)
93
+
94
+ expect do
95
+ Thread.new{ converter.convert() }.join()
96
+ end.to raise_error(RuntimeError)
97
+ end
98
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'support/to_x_settings'
3
+ require 'support/settings'
4
+
5
+ RSpec.describe WkHtml::ToPdf::GlobalSettings do
6
+ include_examples 'to_x_settings', 'useCompression'
7
+ include_examples 'settings', 'useCompression'
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'support/to_x_settings'
3
+ require 'support/settings'
4
+
5
+ RSpec.describe WkHtml::ToPdf::ObjectSettings do
6
+ include_examples 'to_x_settings', 'useExternalLinks'
7
+ include_examples 'settings', 'useExternalLinks'
8
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe WkHtml::ToPdf do
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe WkHtml do
4
+ it "has a library version" do
5
+ expect(WkHtml::LIBRARY_VERSION).not_to be_nil
6
+ end
7
+ end
@@ -0,0 +1,73 @@
1
+ #Arguments are type and time
2
+ type, time, in_file, out_file = ARGV
3
+ type ||= :pdf
4
+ type = type.to_sym()
5
+ time ||= 10
6
+ time = time.to_i()
7
+ in_file = nil if !in_file.nil?() && in_file.empty?()
8
+ out_file = nil if !out_file.nil?() && out_file.empty?()
9
+
10
+ puts "Testing #{type}"
11
+ puts "Running for #{time} minutes"
12
+
13
+ pid = fork do
14
+ $stop_loop = false
15
+ Signal.trap('INT') do
16
+ puts 'Interrupt'
17
+ $stop_loop = true
18
+ end
19
+
20
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
+ require 'wkhtml'
22
+
23
+ converter = WkHtml::Converter.new("<html><body>#{'Test' * 100_000}</body></html>")
24
+
25
+ puts 'Running GC'
26
+ while !$stop_loop
27
+ GC.start()
28
+ sleep 0.1
29
+ end
30
+ $stop_loop = false
31
+
32
+ #puts ObjectSpace.count_objects
33
+
34
+ puts 'Running tests'
35
+ while !$stop_loop
36
+ if out_file.nil?()
37
+ converter.__send__(:"to_#{type}")
38
+ else
39
+ converter.to_file(out_file, type)
40
+ end
41
+ GC.start()
42
+ sleep 1
43
+ end
44
+ $stop_loop = false
45
+
46
+ puts 'Running GC'
47
+ while !$stop_loop
48
+ GC.start()
49
+ sleep 0.1
50
+ end
51
+
52
+ #puts ObjectSpace.count_objects
53
+
54
+ Kernel.exit(0)
55
+ end
56
+
57
+ #Give some time for initial reading
58
+ sleep 10
59
+ old_size = `ps -o rss -p #{pid}`.tap{|o| puts o}.strip.split.last.to_i
60
+ Process.kill('INT', pid)
61
+
62
+ time.times do |i|
63
+ new_size = `ps -o rss -p #{pid}`.tap{|o| puts o}.strip.split.last.to_i
64
+ puts "Difference after #{i} minutes is #{new_size - old_size}"
65
+ sleep 60
66
+ end
67
+
68
+ #Take final reading
69
+ Process.kill('INT', pid)
70
+ sleep 10
71
+ new_size = `ps -o rss -p #{pid}`.strip.split.last.to_i
72
+ puts "Difference after #{time} minutes is #{new_size - old_size}"
73
+ Process.kill('INT', pid)
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wkhtml/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "wkhtml"
8
+ gem.version = WkHtml::VERSION
9
+ gem.authors = ["carsonreinke"]
10
+ gem.email = ["carson@reinke.co"]
11
+ gem.description = %q{Ruby bindings for wkhtmltopdf and wkhtmltoimage}
12
+ gem.summary = %q{Ruby bindings for wkhtmltox}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.extensions << 'ext/wkhtml/extconf.rb'
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rake-compiler'
23
+ gem.add_development_dependency 'rspec'
24
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wkhtml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - carsonreinke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake-compiler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Ruby bindings for wkhtmltopdf and wkhtmltoimage
63
+ email:
64
+ - carson@reinke.co
65
+ executables: []
66
+ extensions:
67
+ - ext/wkhtml/extconf.rb
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - .travis.yml
73
+ - .travis_setup.sh
74
+ - Gemfile
75
+ - LICENSE
76
+ - README.md
77
+ - Rakefile
78
+ - ext/wkhtml/extconf.rb
79
+ - ext/wkhtml/wkhtml.c
80
+ - ext/wkhtml/wkhtml.h
81
+ - lib/wkhtml.rb
82
+ - lib/wkhtml/common_settings.rb
83
+ - lib/wkhtml/converter.rb
84
+ - lib/wkhtml/header_settings.rb
85
+ - lib/wkhtml/load_settings.rb
86
+ - lib/wkhtml/settings.rb
87
+ - lib/wkhtml/to_image/global_settings.rb
88
+ - lib/wkhtml/to_pdf/global_settings.rb
89
+ - lib/wkhtml/to_pdf/object_settings.rb
90
+ - lib/wkhtml/version.rb
91
+ - lib/wkhtml/web_settings.rb
92
+ - spec/spec_helper.rb
93
+ - spec/support/format.rb
94
+ - spec/support/settings.rb
95
+ - spec/support/test.html
96
+ - spec/support/to_x_settings.rb
97
+ - spec/wkhtml/converter_spec.rb
98
+ - spec/wkhtml/to_image_converter_spec.rb
99
+ - spec/wkhtml/to_image_global_settings_spec.rb
100
+ - spec/wkhtml/to_pdf_converter_spec.rb
101
+ - spec/wkhtml/to_pdf_global_settings_spec.rb
102
+ - spec/wkhtml/to_pdf_object_settings_spec.rb
103
+ - spec/wkhtml/to_pdf_spec.rb
104
+ - spec/wkhtml_spec.rb
105
+ - test/leaktest.rb
106
+ - wkhtml.gemspec
107
+ homepage: ''
108
+ licenses: []
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: -2874937389960958071
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -2874937389960958071
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.24
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Ruby bindings for wkhtmltox
137
+ test_files:
138
+ - spec/spec_helper.rb
139
+ - spec/support/format.rb
140
+ - spec/support/settings.rb
141
+ - spec/support/test.html
142
+ - spec/support/to_x_settings.rb
143
+ - spec/wkhtml/converter_spec.rb
144
+ - spec/wkhtml/to_image_converter_spec.rb
145
+ - spec/wkhtml/to_image_global_settings_spec.rb
146
+ - spec/wkhtml/to_pdf_converter_spec.rb
147
+ - spec/wkhtml/to_pdf_global_settings_spec.rb
148
+ - spec/wkhtml/to_pdf_object_settings_spec.rb
149
+ - spec/wkhtml/to_pdf_spec.rb
150
+ - spec/wkhtml_spec.rb
151
+ - test/leaktest.rb