pdfkit 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pdfkit might be problematic. Click here for more details.
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/pdfkit/pdfkit.rb +6 -3
- data/pdfkit.gemspec +6 -7
- data/spec/PDFKit_spec.rb +117 -0
- data/spec/spec_helper.rb +4 -0
- metadata +17 -7
- data/bin/pdfkit.rb +0 -2
data/Rakefile
CHANGED
@@ -20,7 +20,6 @@ begin
|
|
20
20
|
"README.md",
|
21
21
|
"Rakefile",
|
22
22
|
"VERSION",
|
23
|
-
"bin/pdfkit.rb",
|
24
23
|
"bin/wkhtmltopdf-linux-i386-0-9-9",
|
25
24
|
"bin/wkhtmltopdf-osx-i386-0-9-9",
|
26
25
|
"bin/wkhtmltopdf-proxy",
|
@@ -44,10 +43,10 @@ rescue LoadError
|
|
44
43
|
end
|
45
44
|
|
46
45
|
require 'rspec/core/rake_task'
|
47
|
-
|
46
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
48
47
|
end
|
49
48
|
|
50
|
-
|
49
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
51
50
|
spec.rcov = true
|
52
51
|
end
|
53
52
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/pdfkit/pdfkit.rb
CHANGED
@@ -30,12 +30,11 @@ class PDFKit
|
|
30
30
|
}
|
31
31
|
@options = normalize_options(options.reverse_merge(default_options))
|
32
32
|
|
33
|
-
|
34
|
-
raise NoExecutableError.new if @cmd.blank?
|
33
|
+
raise NoExecutableError.new if wkhtmltopdf.blank?
|
35
34
|
end
|
36
35
|
|
37
36
|
def command
|
38
|
-
args = [
|
37
|
+
args = [wkhtmltopdf]
|
39
38
|
args += @options.to_a.flatten.compact
|
40
39
|
args << '--quiet'
|
41
40
|
|
@@ -66,6 +65,10 @@ class PDFKit
|
|
66
65
|
|
67
66
|
protected
|
68
67
|
|
68
|
+
def wkhtmltopdf
|
69
|
+
@wkhtmltopdf ||= `which wkhtmltopdf-proxy`.chomp
|
70
|
+
end
|
71
|
+
|
69
72
|
def style_tag_for(stylesheet)
|
70
73
|
"<style>#{File.read(stylesheet)}</style>"
|
71
74
|
end
|
data/pdfkit.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pdfkit}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["jdpace"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-15}
|
13
13
|
s.description = %q{Uses wkhtmltopdf to create PDFs using HTML}
|
14
14
|
s.email = %q{jared@codewordstudios.com}
|
15
|
-
s.executables = ["
|
15
|
+
s.executables = ["wkhtmltopdf-linux-i386-0-9-9", "wkhtmltopdf-osx-i386-0-9-9", "wkhtmltopdf-proxy"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
18
|
"README.md"
|
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
-
"bin/pdfkit.rb",
|
28
27
|
"bin/wkhtmltopdf-linux-i386-0-9-9",
|
29
28
|
"bin/wkhtmltopdf-osx-i386-0-9-9",
|
30
29
|
"bin/wkhtmltopdf-proxy",
|
@@ -43,10 +42,10 @@ Gem::Specification.new do |s|
|
|
43
42
|
s.homepage = %q{http://github.com/jdpace/PDFKit}
|
44
43
|
s.rdoc_options = ["--charset=UTF-8"]
|
45
44
|
s.require_paths = ["lib"]
|
46
|
-
s.rubygems_version = %q{1.3.
|
45
|
+
s.rubygems_version = %q{1.3.7}
|
47
46
|
s.summary = %q{HTML+CSS -> PDF}
|
48
47
|
s.test_files = [
|
49
|
-
"spec/
|
48
|
+
"spec/PDFKit_spec.rb",
|
50
49
|
"spec/source_spec.rb",
|
51
50
|
"spec/spec_helper.rb"
|
52
51
|
]
|
@@ -55,7 +54,7 @@ Gem::Specification.new do |s|
|
|
55
54
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
55
|
s.specification_version = 3
|
57
56
|
|
58
|
-
if Gem::Version.new(Gem::
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
58
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
60
59
|
s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.8"])
|
61
60
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
data/spec/PDFKit_spec.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe PDFKit do
|
4
|
+
|
5
|
+
context "initialization" do
|
6
|
+
it "should accept HTML as the source" do
|
7
|
+
pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
|
8
|
+
pdfkit.source.should be_html
|
9
|
+
pdfkit.source.to_s.should == '<h1>Oh Hai</h1>'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should accept a URL as the source" do
|
13
|
+
pdfkit = PDFKit.new('http://google.com')
|
14
|
+
pdfkit.source.should be_url
|
15
|
+
pdfkit.source.to_s.should == 'http://google.com'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept a File as the source" do
|
19
|
+
file_path = File.join(SPEC_ROOT,'fixtures','example.html')
|
20
|
+
pdfkit = PDFKit.new(File.new(file_path))
|
21
|
+
pdfkit.source.should be_file
|
22
|
+
pdfkit.source.to_s.should == file_path
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse the options into a cmd line friedly format" do
|
26
|
+
pdfkit = PDFKit.new('html', :page_size => 'Letter')
|
27
|
+
pdfkit.options.should have_key('--page-size')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should provide default options" do
|
31
|
+
pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
|
32
|
+
['--disable-smart-shrinking', '--margin-top', '--margin-right', '--margin-bottom', '--margin-left'].each do |option|
|
33
|
+
pdfkit.options.should have_key(option)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not have any stylesheedt by default" do
|
38
|
+
pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
|
39
|
+
pdfkit.stylesheets.should be_empty
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "command" do
|
44
|
+
it "should contstruct the correct command" do
|
45
|
+
pdfkit = PDFKit.new('html', :page_size => 'Letter')
|
46
|
+
pdfkit.command.should include('wkhtmltopdf')
|
47
|
+
pdfkit.command.should include('--page-size Letter')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "read the source from stdin if it is html" do
|
51
|
+
pdfkit = PDFKit.new('html')
|
52
|
+
pdfkit.command.should match(/ - -$/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "specify the URL to the source if it is a url" do
|
56
|
+
pdfkit = PDFKit.new('http://google.com')
|
57
|
+
pdfkit.command.should match(/ http:\/\/google\.com -$/)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should specify the path to the source if it is a file" do
|
61
|
+
file_path = File.join(SPEC_ROOT,'fixtures','example.html')
|
62
|
+
pdfkit = PDFKit.new(File.new(file_path))
|
63
|
+
pdfkit.command.should match(/ #{file_path} -$/)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "#to_pdf" do
|
68
|
+
it "should generate a PDF of the HTML" do
|
69
|
+
pdfkit = PDFKit.new('html', :page_size => 'Letter')
|
70
|
+
pdf = pdfkit.to_pdf
|
71
|
+
pdf.should match(/^%PDF/) # PDF Signature at beginning of file
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have the stylesheet added to the head if it has one" do
|
75
|
+
pdfkit = PDFKit.new("<html><head></head><body>Hai!</body></html>")
|
76
|
+
css = File.join(SPEC_ROOT,'fixtures','example.css')
|
77
|
+
pdfkit.stylesheets << css
|
78
|
+
pdfkit.to_pdf
|
79
|
+
pdfkit.source.to_s.should include("<style>#{File.read(css)}</style>")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should prepend style tags if the HTML doesn't have a head tag" do
|
83
|
+
pdfkit = PDFKit.new("<html><body>Hai!</body></html>")
|
84
|
+
css = File.join(SPEC_ROOT,'fixtures','example.css')
|
85
|
+
pdfkit.stylesheets << css
|
86
|
+
pdfkit.to_pdf
|
87
|
+
pdfkit.source.to_s.should include("<style>#{File.read(css)}</style><html>")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should throw an error if the source is not html and stylesheets have been added" do
|
91
|
+
pdfkit = PDFKit.new('http://google.com')
|
92
|
+
css = File.join(SPEC_ROOT,'fixtures','example.css')
|
93
|
+
pdfkit.stylesheets << css
|
94
|
+
lambda { pdfkit.to_pdf }.should raise_error(PDFKit::ImproperSourceError)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "#to_file" do
|
99
|
+
before do
|
100
|
+
@file_path = File.join(SPEC_ROOT,'fixtures','test.pdf')
|
101
|
+
File.delete(@file_path) if File.exist?(@file_path)
|
102
|
+
end
|
103
|
+
|
104
|
+
after do
|
105
|
+
File.delete(@file_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should create a file with the PDF as content" do
|
109
|
+
pdfkit = PDFKit.new('html', :page_size => 'Letter')
|
110
|
+
pdfkit.expects(:to_pdf).returns('PDF')
|
111
|
+
file = pdfkit.to_file(@file_path)
|
112
|
+
file.should be_instance_of(File)
|
113
|
+
File.read(file.path).should == 'PDF'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdfkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- jdpace
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-15 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activesupport
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -33,9 +36,11 @@ dependencies:
|
|
33
36
|
name: rspec
|
34
37
|
prerelease: false
|
35
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ~>
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 62196467
|
39
44
|
segments:
|
40
45
|
- 2
|
41
46
|
- 0
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: mocha
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
55
62
|
segments:
|
56
63
|
- 0
|
57
64
|
version: "0"
|
@@ -60,7 +67,6 @@ dependencies:
|
|
60
67
|
description: Uses wkhtmltopdf to create PDFs using HTML
|
61
68
|
email: jared@codewordstudios.com
|
62
69
|
executables:
|
63
|
-
- pdfkit.rb
|
64
70
|
- wkhtmltopdf-linux-i386-0-9-9
|
65
71
|
- wkhtmltopdf-osx-i386-0-9-9
|
66
72
|
- wkhtmltopdf-proxy
|
@@ -76,7 +82,6 @@ files:
|
|
76
82
|
- README.md
|
77
83
|
- Rakefile
|
78
84
|
- VERSION
|
79
|
-
- bin/pdfkit.rb
|
80
85
|
- bin/wkhtmltopdf-linux-i386-0-9-9
|
81
86
|
- bin/wkhtmltopdf-osx-i386-0-9-9
|
82
87
|
- bin/wkhtmltopdf-proxy
|
@@ -91,6 +96,7 @@ files:
|
|
91
96
|
- spec/source_spec.rb
|
92
97
|
- spec/spec.opts
|
93
98
|
- spec/spec_helper.rb
|
99
|
+
- spec/PDFKit_spec.rb
|
94
100
|
has_rdoc: true
|
95
101
|
homepage: http://github.com/jdpace/PDFKit
|
96
102
|
licenses: []
|
@@ -101,27 +107,31 @@ rdoc_options:
|
|
101
107
|
require_paths:
|
102
108
|
- lib
|
103
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
104
111
|
requirements:
|
105
112
|
- - ">="
|
106
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
107
115
|
segments:
|
108
116
|
- 0
|
109
117
|
version: "0"
|
110
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
111
120
|
requirements:
|
112
121
|
- - ">="
|
113
122
|
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
114
124
|
segments:
|
115
125
|
- 0
|
116
126
|
version: "0"
|
117
127
|
requirements: []
|
118
128
|
|
119
129
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.3.
|
130
|
+
rubygems_version: 1.3.7
|
121
131
|
signing_key:
|
122
132
|
specification_version: 3
|
123
133
|
summary: HTML+CSS -> PDF
|
124
134
|
test_files:
|
125
|
-
- spec/
|
135
|
+
- spec/PDFKit_spec.rb
|
126
136
|
- spec/source_spec.rb
|
127
137
|
- spec/spec_helper.rb
|
data/bin/pdfkit.rb
DELETED