pdfkit 0.5.2 → 0.5.3

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.

@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source :gemcutter
2
2
 
3
- gemspec
3
+ gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pdfkit (0.5.2)
4
+ pdfkit (0.5.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -12,6 +12,7 @@ GEM
12
12
  rack (1.3.0)
13
13
  rack-test (0.6.0)
14
14
  rack (>= 1.0)
15
+ rake (0.9.2)
15
16
  rspec (2.2.0)
16
17
  rspec-core (~> 2.2)
17
18
  rspec-expectations (~> 2.2)
@@ -20,6 +21,7 @@ GEM
20
21
  rspec-expectations (2.6.0)
21
22
  diff-lcs (~> 1.1.2)
22
23
  rspec-mocks (2.6.0)
24
+ wkhtmltopdf-binary (0.9.5.3)
23
25
 
24
26
  PLATFORMS
25
27
  ruby
@@ -29,4 +31,6 @@ DEPENDENCIES
29
31
  mocha (>= 0.9.10)
30
32
  pdfkit!
31
33
  rack-test (>= 0.5.6)
34
+ rake (~> 0.9.2)
32
35
  rspec (~> 2.2.0)
36
+ wkhtmltopdf-binary (~> 0.9.5)
@@ -4,7 +4,7 @@ Install wkhtmltopdf:
4
4
 
5
5
  1. Install by hand (recomended):
6
6
 
7
- https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
7
+ https://github.com/pdfkit/PDFKit/wiki/Installing-WKHTMLTOPDF
8
8
 
9
9
  2. Try using the wkhtmltopdf-binary gem (mac + linux i386)
10
10
 
data/README.md CHANGED
@@ -12,7 +12,7 @@ Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antia
12
12
 
13
13
  1. Install by hand (recommended):
14
14
 
15
- <https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF>
15
+ <https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF>
16
16
 
17
17
  2. Try using the wkhtmltopdf-binary gem (mac + linux i386)
18
18
 
@@ -27,7 +27,7 @@ Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antia
27
27
  kit = PDFKit.new(html, :page_size => 'Letter')
28
28
  kit.stylesheets << '/path/to/css/file'
29
29
 
30
- # Git an inline PDF
30
+ # Get an inline PDF
31
31
  pdf = kit.to_pdf
32
32
 
33
33
  # Save the PDF to a file
@@ -88,6 +88,12 @@ PDFKit comes with a middleware that allows users to get a PDF view of any page o
88
88
  config.middleware.use PDFKit::Middleware, {}, :only => '/public'
89
89
  config.middleware.use PDFKit::Middleware, {}, :only => ['/invoice', '/public']
90
90
 
91
+ # conditions can be regexps (either one or an array)
92
+ config.middleware.use PDFKit::Middleware, {}, :except => [%r[^/prawn], %r[^/secret]]
93
+
94
+ # conditions can be strings (either one or an array)
95
+ config.middleware.use PDFKit::Middleware, {}, :except => ['/secret']
96
+
91
97
  ## Troubleshooting
92
98
 
93
99
  * **Single thread issue:** In development environments it is common to run a
@@ -101,6 +107,14 @@ PDFKit comes with a middleware that allows users to get a PDF view of any page o
101
107
  around this issue you may want to run a server with multiple workers
102
108
  like Passenger or try to embed your resources within your HTML to
103
109
  avoid extra HTTP requests.
110
+
111
+ Example solution (rails / bundler), add unicorn to the development
112
+ group in your Gemfile `gem 'unicorn'` then run `bundle`. Next, add a
113
+ file `config/unicorn.conf` with
114
+
115
+ worker_processes 3
116
+
117
+ Then to run the app `unicorn_rails -c config/unicorn.conf` (from rails_root)
104
118
 
105
119
  * **Resources aren't included in the PDF:** Images, CSS, or JavaScript
106
120
  does not seem to be downloading correctly in the PDF. This is due
@@ -112,8 +126,8 @@ PDFKit comes with a middleware that allows users to get a PDF view of any page o
112
126
  root_url configuration may be what you are looking for change your
113
127
  asset host.
114
128
 
115
- ## TODO
116
- - add amd64 support in --install-wkhtmltopdf
129
+ * **Mangled output in the browser:** Be sure that your HTTP response
130
+ headers specify "Content-Type: application/pdf"
117
131
 
118
132
  ## Note on Patches/Pull Requests
119
133
 
@@ -58,6 +58,17 @@ class PDFKit
58
58
  @request.path[0, pattern.length] == pattern
59
59
  end
60
60
  end
61
+ elsif request_path_is_pdf && @conditions[:except]
62
+ rules = [@conditions[:except]].flatten
63
+ rules.map do |pattern|
64
+ if pattern.is_a?(Regexp)
65
+ return false if @request.path =~ pattern
66
+ else
67
+ return false if @request.path[0, pattern.length] == pattern
68
+ end
69
+ end
70
+
71
+ return true
61
72
  else
62
73
  request_path_is_pdf
63
74
  end
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  class PDFKit
2
4
 
3
5
  class NoExecutableError < StandardError
@@ -42,7 +44,7 @@ class PDFKit
42
44
 
43
45
  args << (path || '-') # Write to file or stdout
44
46
 
45
- args.map {|arg| %Q{"#{arg.gsub('"', '\"')}"}}
47
+ args.map {|arg| %Q{"#{arg.shellescape}"}}
46
48
  end
47
49
 
48
50
  def executable
@@ -1,3 +1,3 @@
1
1
  class PDFKit
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -20,9 +20,10 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  # Developmnet Dependencies
23
+ s.add_development_dependency(%q<rake>, ["~>0.9.2"])
23
24
  s.add_development_dependency(%q<rspec>, ["~> 2.2.0"])
24
25
  s.add_development_dependency(%q<mocha>, [">= 0.9.10"])
25
26
  s.add_development_dependency(%q<rack-test>, [">= 0.5.6"])
26
27
  s.add_development_dependency(%q<activesupport>, [">= 3.0.8"])
28
+ s.add_development_dependency(%q<wkhtmltopdf-binary>, ["~> 0.9.5"])
27
29
  end
28
-
@@ -106,6 +106,94 @@ describe PDFKit::Middleware do
106
106
  end # string
107
107
 
108
108
  end
109
+
110
+ describe ":except" do
111
+
112
+ describe "regex" do
113
+ describe "one" do
114
+ before { mock_app({}, :except => %r[^/secret]) }
115
+
116
+ context "matching" do
117
+ specify do
118
+ get 'http://www.example.org/public/test.pdf'
119
+ last_response.headers["Content-Type"].should == "application/pdf"
120
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
121
+ end
122
+ end
123
+
124
+ context "not matching" do
125
+ specify do
126
+ get 'http://www.example.org/secret/test.pdf'
127
+ last_response.headers["Content-Type"].should == "text/html"
128
+ last_response.body.should == "Hello world!"
129
+ end
130
+ end
131
+ end # one regex
132
+
133
+ describe "multiple" do
134
+ before { mock_app({}, :except => [%r[^/prawn], %r[^/secret]]) }
135
+
136
+ context "matching" do
137
+ specify do
138
+ get 'http://www.example.org/public/test.pdf'
139
+ last_response.headers["Content-Type"].should == "application/pdf"
140
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
141
+ end
142
+ end
143
+
144
+ context "not matching" do
145
+ specify do
146
+ get 'http://www.example.org/secret/test.pdf'
147
+ last_response.headers["Content-Type"].should == "text/html"
148
+ last_response.body.should == "Hello world!"
149
+ end
150
+ end
151
+ end # multiple regex
152
+ end # regex
153
+
154
+ describe "string" do
155
+ describe "one" do
156
+ before { mock_app({}, :except => '/secret') }
157
+
158
+ context "matching" do
159
+ specify do
160
+ get 'http://www.example.org/public/test.pdf'
161
+ last_response.headers["Content-Type"].should == "application/pdf"
162
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
163
+ end
164
+ end
165
+
166
+ context "not matching" do
167
+ specify do
168
+ get 'http://www.example.org/secret/test.pdf'
169
+ last_response.headers["Content-Type"].should == "text/html"
170
+ last_response.body.should == "Hello world!"
171
+ end
172
+ end
173
+ end # one string
174
+
175
+ describe "multiple" do
176
+ before { mock_app({}, :except => ['/prawn', '/secret']) }
177
+
178
+ context "matching" do
179
+ specify do
180
+ get 'http://www.example.org/public/test.pdf'
181
+ last_response.headers["Content-Type"].should == "application/pdf"
182
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
183
+ end
184
+ end
185
+
186
+ context "not matching" do
187
+ specify do
188
+ get 'http://www.example.org/secret/test.pdf'
189
+ last_response.headers["Content-Type"].should == "text/html"
190
+ last_response.body.should == "Hello world!"
191
+ end
192
+ end
193
+ end # multiple string
194
+ end # string
195
+
196
+ end
109
197
  end
110
198
 
111
199
  describe "remove .pdf from PATH_INFO and REQUEST_URI" do
@@ -67,7 +67,12 @@ describe PDFKit do
67
67
 
68
68
  it "should encapsulate string arguments in quotes" do
69
69
  pdfkit = PDFKit.new('html', :header_center => "foo [page]")
70
- pdfkit.command[pdfkit.command.index('"--header-center"') + 1].should == '"foo [page]"'
70
+ pdfkit.command[pdfkit.command.index('"--header-center"') + 1].should == '"foo\ \[page\]"'
71
+ end
72
+
73
+ it "should sanitize string arguments" do
74
+ pdfkit = PDFKit.new('html', :header_center => "$(ls)")
75
+ pdfkit.command[pdfkit.command.index('"--header-center"') + 1].should == '"\$\(ls\)"'
71
76
  end
72
77
 
73
78
  it "read the source from stdin if it is html" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,27 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-02 00:00:00.000000000Z
13
+ date: 2013-02-21 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.9.2
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: rspec
17
- requirement: &2152731540 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
18
34
  none: false
19
35
  requirements:
20
36
  - - ~>
@@ -22,10 +38,15 @@ dependencies:
22
38
  version: 2.2.0
23
39
  type: :development
24
40
  prerelease: false
25
- version_requirements: *2152731540
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.0
26
47
  - !ruby/object:Gem::Dependency
27
48
  name: mocha
28
- requirement: &2152731020 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
29
50
  none: false
30
51
  requirements:
31
52
  - - ! '>='
@@ -33,10 +54,15 @@ dependencies:
33
54
  version: 0.9.10
34
55
  type: :development
35
56
  prerelease: false
36
- version_requirements: *2152731020
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.9.10
37
63
  - !ruby/object:Gem::Dependency
38
64
  name: rack-test
39
- requirement: &2152730540 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
40
66
  none: false
41
67
  requirements:
42
68
  - - ! '>='
@@ -44,10 +70,15 @@ dependencies:
44
70
  version: 0.5.6
45
71
  type: :development
46
72
  prerelease: false
47
- version_requirements: *2152730540
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.5.6
48
79
  - !ruby/object:Gem::Dependency
49
80
  name: activesupport
50
- requirement: &2152730060 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
51
82
  none: false
52
83
  requirements:
53
84
  - - ! '>='
@@ -55,7 +86,28 @@ dependencies:
55
86
  version: 3.0.8
56
87
  type: :development
57
88
  prerelease: false
58
- version_requirements: *2152730060
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 3.0.8
95
+ - !ruby/object:Gem::Dependency
96
+ name: wkhtmltopdf-binary
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.5
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.5
59
111
  description: Uses wkhtmltopdf to create PDFs using HTML
60
112
  email:
61
113
  - jared@codewordstudios.com
@@ -66,6 +118,7 @@ files:
66
118
  - .document
67
119
  - .gitignore
68
120
  - .rspec
121
+ - .travis.yml
69
122
  - Gemfile
70
123
  - Gemfile.lock
71
124
  - History.md
@@ -106,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
159
  version: '0'
107
160
  requirements: []
108
161
  rubyforge_project: pdfkit
109
- rubygems_version: 1.8.5
162
+ rubygems_version: 1.8.24
110
163
  signing_key:
111
164
  specification_version: 3
112
165
  summary: HTML+CSS -> PDF