pdfkit 0.7.0 → 0.8.0

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a7e2a27521d1d1a34a809f5b3d2ce8db2b893ca
4
- data.tar.gz: e336025cf967c7a673e46c8b289aa5f80edc97ae
3
+ metadata.gz: d761c045627c5f9435b7ea06b44d5e23abbbcdd6
4
+ data.tar.gz: 9f55905b443cfb6532696bf373173fd55435be56
5
5
  SHA512:
6
- metadata.gz: 74ffa36e6a43b1d9b0e1b45d821a5974e0c58e651cb5bf5e13666dae61cdd19bb0626ec4133186777931df25db5b63899adcf6cdcafb550d691a4ec55935c91c
7
- data.tar.gz: 1aafe95aa04762e43484cb619c0572406156a309891a090e7021ad7fc27890a0d4f728d55e4f4efbeedfd42529ba051fc0ddfaa611cd7a7b47da9f63e523fed2
6
+ metadata.gz: 19210027b8208466fd91c6c3604b205739973e95ffb876feaecc6f0e0df76d2a78103dd2747c6f00e0d0af171da4235f31518f03da495fe5c9c638a804e3883d
7
+ data.tar.gz: 7a82596a5548c9ab3fb2557aef2aae5445f0dbae59196c436fd2c6846b2d6d9c1f51be0b6b85e4073c4da07bd160801d028601206ac04de2f81839c0b081dc5e
data/.travis.yml CHANGED
@@ -7,4 +7,6 @@ rvm:
7
7
  before_script:
8
8
  - "export DISPLAY=:99.0"
9
9
  - "sh -e /etc/init.d/xvfb start"
10
- - "sudo apt-get install wkhtmltopdf"
10
+ - "sudo apt-get -qq -y install fontconfig libxrender1"
11
+ - "wget http://downloads.sourceforge.net/project/wkhtmltopdf/archive/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb"
12
+ - "sudo dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ 2015-07-08
2
+ =================
3
+ * Bump to 0.7.1
4
+ * Support Cover and Table Of Contents options (thanks @nicpillinger)
5
+ * Fix repeatings keys with string values
6
+ * Fix caching bug (thanks @jocranford)
7
+ * Fix munging of relative paths (thanks @jocranford)
8
+ * Fix bug where nil values did not stay nil (thanks @tylerITP)
9
+
1
10
  2015-05-06
2
11
  =================
3
12
  * Bump to 0.7.0
data/Gemfile CHANGED
@@ -2,6 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
4
  gem 'activesupport', '~> 3.0'
5
+ gem 'simplecov', require: false
6
+ end
7
+
8
+ group :development, :test do
9
+ gem 'pry'
5
10
  end
6
11
 
7
12
  gemspec
data/README.md CHANGED
@@ -51,7 +51,7 @@ kit = PDFKit.new(url, cookie: {cookie_name: :cookie_value})
51
51
  kit = PDFKit.new(url, [:cookie, :cookie_name1] => :cookie_val1, [:cookie, :cookie_name2] => :cookie_val2)
52
52
  ```
53
53
  ## Configuration
54
- If you're on Windows or you installed wkhtmltopdf by hand to a location other than `/usr/local/bin` you will need to tell PDFKit where the binary is. You can configure PDFKit like so:
54
+ If you're on Windows or you would like to use a specific wkhtmltopdf you installed, you will need to tell PDFKit where the binary is. PDFKit will try to intelligently guess at the location of wkhtmltopdf by running the command `which wkhtmltopdf`. If you are on Windows, want to point PDFKit to a different binary, or are having trouble with getting PDFKit to find your binary, please manually configure the wkhtmltopdf location. You can configure PDFKit like so:
55
55
  ```ruby
56
56
  # config/initializers/pdfkit.rb
57
57
  PDFKit.configure do |config|
@@ -5,12 +5,12 @@ class PDFKit
5
5
  @options = options
6
6
  @conditions = conditions
7
7
  @render_pdf = false
8
+ @caching = @conditions.delete(:caching) { false }
8
9
  end
9
10
 
10
11
  def call(env)
11
12
  @request = Rack::Request.new(env)
12
13
  @render_pdf = false
13
- @caching = @conditions.delete(:caching) { false }
14
14
 
15
15
  set_request_to_render_as_pdf(env) if render_as_pdf?
16
16
  status, headers, response = @app.call(env)
@@ -49,8 +49,8 @@ class PDFKit
49
49
 
50
50
  def translate_relative_paths(body, env)
51
51
  root = PDFKit.configuration.root_url || "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/"
52
- # Try out this regexp using rubular http://rubular.com/r/vmuGSkheuu
53
- body.gsub(/(href|src)=(['"])\/([^\/]([^\"']*|[^"']*))['"]/, "\\1=\\2#{root}\\3\\2")
52
+ # Try out this regexp using rubular http://rubular.com/r/hiAxBNX7KE
53
+ body.gsub(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2#{root}\\3\\2")
54
54
  end
55
55
 
56
56
  def translate_relative_protocols(body, env)
data/lib/pdfkit/pdfkit.rb CHANGED
@@ -82,6 +82,7 @@ class PDFKit
82
82
  # Pulled from:
83
83
  # https://github.com/wkhtmltopdf/wkhtmltopdf/blob/ebf9b6cfc4c58a31349fb94c568b254fac37b3d3/README_WKHTMLTOIMAGE#L27
84
84
  REPEATABLE_OPTIONS = %w[--allow --cookie --custom-header --post --post-file --run-script]
85
+ SPECIAL_OPTIONS = %w[cover toc]
85
86
 
86
87
  def find_options_in_meta(content)
87
88
  # Read file if content is a File
@@ -129,12 +130,13 @@ class PDFKit
129
130
  next if !value
130
131
 
131
132
  # The actual option for wkhtmltopdf
132
- normalized_key = "--#{normalize_arg key}"
133
+ normalized_key = normalize_arg key
134
+ normalized_key = "--#{normalized_key}" unless SPECIAL_OPTIONS.include?(normalized_key)
133
135
 
134
136
  # If the option is repeatable, attempt to normalize all values
135
137
  if REPEATABLE_OPTIONS.include? normalized_key
136
- normalize_repeatable_value(value) do |normalized_key_piece, normalized_value|
137
- normalized_options[[normalized_key, normalized_key_piece]] = normalized_value
138
+ normalize_repeatable_value(normalized_key, value) do |normalized_unique_key, normalized_value|
139
+ normalized_options[normalized_unique_key] = normalized_value
138
140
  end
139
141
  else # Otherwise, just normalize it like usual
140
142
  normalized_options[normalized_key] = normalize_value(value)
@@ -150,6 +152,8 @@ class PDFKit
150
152
 
151
153
  def normalize_value(value)
152
154
  case value
155
+ when nil
156
+ nil
153
157
  when TrueClass, 'true' #ie, ==true, see http://www.ruby-doc.org/core-1.9.3/TrueClass.html
154
158
  nil
155
159
  when Hash
@@ -161,14 +165,14 @@ class PDFKit
161
165
  end
162
166
  end
163
167
 
164
- def normalize_repeatable_value(value)
168
+ def normalize_repeatable_value(option_name, value)
165
169
  case value
166
170
  when Hash, Array
167
171
  value.each do |(key, val)|
168
- yield [normalize_value(key), normalize_value(val)]
172
+ yield [[option_name, normalize_value(key)], normalize_value(val)]
169
173
  end
170
174
  else
171
- [normalize_value(value), '']
175
+ yield [[option_name, normalize_value(value)], nil]
172
176
  end
173
177
  end
174
178
 
@@ -1,3 +1,3 @@
1
1
  class PDFKit
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe PDFKit::Configuration do
4
+ subject { PDFKit::Configuration.new }
5
+ describe "#wkhtmltopdf" do
6
+ it "can be configured" do
7
+ subject.wkhtmltopdf = '/my/bin/wkhtmltopdf'
8
+ expect(subject.wkhtmltopdf).to eql '/my/bin/wkhtmltopdf'
9
+ end
10
+
11
+ # This test documents existing functionality. Feel free to fix.
12
+ it "can be poorly configured" do
13
+ subject.wkhtmltopdf = 1234
14
+ expect(subject.wkhtmltopdf).to eql 1234
15
+ end
16
+
17
+ context "when not explicitly configured" do
18
+ it "detects the existance of bundler" do
19
+ # Test assumes bundler is installed in your test environment
20
+ expect(subject).to receive(:`).with('bundle exec which wkhtmltopdf').and_return('c:\windows\path.exe')
21
+ subject.wkhtmltopdf
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "#default_options" do
27
+ it "sets defaults for the command options" do
28
+ expect(subject.default_options[:disable_smart_shrinking]).to eql false
29
+ expect(subject.default_options[:quiet]).to eql true
30
+ expect(subject.default_options[:page_size]).to eql 'Letter'
31
+ expect(subject.default_options[:margin_top]).to eql '0.75in'
32
+ expect(subject.default_options[:margin_bottom]).to eql '0.75in'
33
+ expect(subject.default_options[:margin_right]).to eql '0.75in'
34
+ expect(subject.default_options[:margin_left]).to eql '0.75in'
35
+ expect(subject.default_options[:encoding]).to eql 'UTF-8'
36
+ end
37
+
38
+ it "allows additional options to be configured" do
39
+ subject.default_options = { quiet: false, is_awesome: true }
40
+ expect(subject.default_options[:quiet]).to eql false
41
+ expect(subject.default_options[:is_awesome]).to eql true
42
+ end
43
+ end
44
+
45
+ describe "#root_url" do
46
+ it "has no default" do
47
+ expect(subject.root_url).to be_nil
48
+ end
49
+
50
+ it "is configurable" do
51
+ subject.root_url = 'https://arbitrary.base_url.for/middleware'
52
+ expect(subject.root_url).to eql 'https://arbitrary.base_url.for/middleware'
53
+ end
54
+ end
55
+
56
+ describe "#meta_tag_prefix" do
57
+ it "defaults to 'pdfkit-'" do
58
+ expect(subject.meta_tag_prefix).to eql 'pdfkit-'
59
+ end
60
+
61
+ it "is configurable" do
62
+ subject.meta_tag_prefix = 'aDifferentPrefix-'
63
+ expect(subject.meta_tag_prefix).to eql 'aDifferentPrefix-'
64
+ end
65
+ end
66
+
67
+ describe "#verbose?" do
68
+ it "can be configured to true" do
69
+ subject.verbose = true
70
+ expect(subject.verbose?).to eql true
71
+ end
72
+
73
+ it "defaults to false" do
74
+ expect(subject.verbose?).to eql false
75
+ end
76
+
77
+ it "can be configured to false" do
78
+ subject.verbose = false
79
+ expect(subject.verbose?).to eql false
80
+ end
81
+ end
82
+
83
+ describe "#quiet?" do
84
+ it "can be configured to true" do
85
+ subject.verbose = false
86
+ expect(subject.quiet?).to eql true
87
+ end
88
+
89
+ it "defaults to true" do
90
+ expect(subject.quiet?).to eql true
91
+ end
92
+
93
+ it "can be configured to false" do
94
+ subject.verbose = true
95
+ expect(subject.quiet?).to eql false
96
+ end
97
+ end
98
+ end
@@ -343,6 +343,12 @@ describe PDFKit::Middleware do
343
343
  expect(body).to eq("<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>")
344
344
  end
345
345
 
346
+ it "should correctly parse multiple tags where first one is root url" do
347
+ @body = %{<a href='/'><img src='/logo.jpg' ></a>}
348
+ body = @pdf.send :translate_paths, @body, @env
349
+ body.should == "<a href='http://example.com/'><img src='http://example.com/logo.jpg' ></a>"
350
+ end
351
+
346
352
  it "should return the body even if there are no valid substitutions found" do
347
353
  @body = "NO MATCH"
348
354
  body = @pdf.send :translate_paths, @body, @env
data/spec/pdfkit_spec.rb CHANGED
@@ -2,7 +2,8 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe PDFKit do
5
- context "initialization" do
5
+ describe "initialization" do
6
+ # Source
6
7
  it "should accept HTML as the source" do
7
8
  pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
8
9
  expect(pdfkit.source).to be_html
@@ -22,36 +23,147 @@ describe PDFKit do
22
23
  expect(pdfkit.source.to_s).to eq(file_path)
23
24
  end
24
25
 
25
- it "should parse the options into a cmd line friedly format" do
26
+ # Options
27
+ ## options keys
28
+ it "drops options without values" do
29
+ pdfkit = PDFKit.new('html', :page_size => nil)
30
+ expect(pdfkit.options).not_to have_key('--page-size')
31
+ end
32
+
33
+ it "transforms keys into command-line arguments" do
26
34
  pdfkit = PDFKit.new('html', :page_size => 'Letter')
27
35
  expect(pdfkit.options).to have_key('--page-size')
28
36
  end
29
37
 
30
- it "should parse complex options into a cmd line friedly format" do
38
+ it "transforms complex keys into command-line arguments" do
31
39
  pdfkit = PDFKit.new('html', :replace => {'value' => 'something else'} )
32
40
  expect(pdfkit.options).to have_key('--replace')
33
41
  end
34
42
 
35
- it "should provide default options" do
43
+ it "drops options with false or falsey values" do
44
+ pdfkit = PDFKit.new('html', disable_smart_shrinking: false)
45
+ expect(pdfkit.options).not_to have_key('--disable-smart-shrinking')
46
+ end
47
+
48
+ ## options values
49
+ it "parses string option values into strings" do
50
+ pdfkit = PDFKit.new('html', :page_size => 'Letter')
51
+ expect(pdfkit.options['--page-size']).to eql 'Letter'
52
+ end
53
+
54
+ it "drops option values of 'true'" do
55
+ pdfkit = PDFKit.new('html', disable_smart_shrinking: true)
56
+ expect(pdfkit.options).to have_key('--disable-smart-shrinking')
57
+ expect(pdfkit.options['--disable-smart-shrinking']).to be_nil
58
+ end
59
+
60
+ it "parses unknown value formats by transforming them into strings" do
61
+ pdfkit = PDFKit.new('html', image_dpi: 300)
62
+ expect(pdfkit.options['--image-dpi']).to eql '300'
63
+ end
64
+
65
+ it "parses hash option values into an array" do
66
+ pdfkit = PDFKit.new('html', :replace => {'value' => 'something else'} )
67
+ expect(pdfkit.options['--replace']).to eql ['value', 'something else']
68
+ end
69
+
70
+ it "flattens hash options into the key" do
71
+ pdfkit = PDFKit.new('html', :cookie => {:cookie_name1 => :cookie_val1, :cookie_name2 => :cookie_val2})
72
+ expect(pdfkit.options).not_to have_key('--cookie')
73
+ expect(pdfkit.options[['--cookie', 'cookie_name1']]).to eql 'cookie_val1'
74
+ expect(pdfkit.options[['--cookie', 'cookie_name2']]).to eql 'cookie_val2'
75
+ end
76
+
77
+ it "parses array option values into a string" do
78
+ pdfkit = PDFKit.new('html', :replace => ['value', 'something else'] )
79
+ expect(pdfkit.options['--replace']).to eql ['value', 'something else']
80
+ end
81
+
82
+ it "flattens array options" do
83
+ pdfkit = PDFKit.new('html', :cookie => [[:cookie_name1, :cookie_val1], [:cookie_name2, :cookie_val2]])
84
+ expect(pdfkit.options).not_to have_key('--cookie')
85
+ expect(pdfkit.options[['--cookie', 'cookie_name1']]).to eql 'cookie_val1'
86
+ expect(pdfkit.options[['--cookie', 'cookie_name2']]).to eql 'cookie_val2'
87
+ end
88
+
89
+ ## default options
90
+ it "provides default options" do
36
91
  pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
37
92
  ['--margin-top', '--margin-right', '--margin-bottom', '--margin-left'].each do |option|
38
93
  expect(pdfkit.options).to have_key(option)
39
94
  end
40
95
  end
41
96
 
42
- it "should default to 'UTF-8' encoding" do
97
+ it "allows overriding default options" do
98
+ pdfkit = PDFKit.new('html', :page_size => 'A4')
99
+ expect(pdfkit.options['--page-size']).to eql 'A4'
100
+ end
101
+
102
+ it "defaults to 'UTF-8' encoding" do
43
103
  pdfkit = PDFKit.new('Captación')
44
104
  expect(pdfkit.options['--encoding']).to eq('UTF-8')
45
105
  end
46
106
 
47
- it "should not have any stylesheedt by default" do
107
+ it "handles repeatable values which are strings" do
108
+ pdfkit = PDFKit.new('html', allow: 'http://myapp.com')
109
+ expect(pdfkit.options).to have_key ['--allow', 'http://myapp.com']
110
+ expect(pdfkit.options[['--allow', 'http://myapp.com']]).to eql nil
111
+ end
112
+
113
+ it "handles repeatable values which are hashes" do
114
+ pdfkit = PDFKit.new('html', allow: { 'http://myapp.com' => nil, 'http://google.com' => nil })
115
+ expect(pdfkit.options).to have_key ['--allow', 'http://myapp.com']
116
+ expect(pdfkit.options).to have_key ['--allow', 'http://google.com']
117
+ expect(pdfkit.options[['--allow', 'http://myapp.com']]).to eql nil
118
+ expect(pdfkit.options[['--allow', 'http://google.com']]).to eql nil
119
+ end
120
+
121
+ it "handles repeatable values which are arrays" do
122
+ pdfkit = PDFKit.new('html', allow: ['http://myapp.com', 'http://google.com'])
123
+ expect(pdfkit.options).to have_key ['--allow', 'http://myapp.com']
124
+ expect(pdfkit.options).to have_key ['--allow', 'http://google.com']
125
+ expect(pdfkit.options[['--allow', 'http://myapp.com']]).to eql nil
126
+ expect(pdfkit.options[['--allow', 'http://google.com']]).to eql nil
127
+ end
128
+
129
+ # Stylesheets
130
+ it "has no stylesheet by default" do
48
131
  pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
49
132
  expect(pdfkit.stylesheets).to be_empty
50
133
  end
134
+
135
+ it "should not prepend cover with --" do
136
+ pdfkit = PDFKit.new('html', "cover" => 'http://google.com')
137
+ expect(pdfkit.options).to have_key('cover')
138
+ end
139
+
140
+ it "should not prepend toc with --" do
141
+ pdfkit = PDFKit.new('html', 'toc' => '')
142
+ expect(pdfkit.options).to have_key('toc')
143
+ end
144
+
145
+ it "should handle special params passed as symbols" do
146
+ pdfkit = PDFKit.new('html', {toc: true})
147
+ expect(pdfkit.options).to have_key('toc')
148
+ end
149
+ end
150
+
151
+ describe "#options" do
152
+ # #options is an attr_reader, but it doesn't really matter. See these two examples:
153
+ it "cannot be externally overwritten entirely" do
154
+ pdfkit = PDFKit.new('html', :page_size => 'A4')
155
+ expect{ pdfkit.options = {} }.to raise_error(NoMethodError)
156
+ end
157
+
158
+ it "has attributes that are externally mutable" do
159
+ pdfkit = PDFKit.new('html', :page_size => 'A4')
160
+ pdfkit.options['--page-size'] = 'Letter'
161
+ expect(pdfkit.options['--page-size']).to eql 'Letter'
162
+ end
51
163
  end
52
164
 
53
- context "command" do
54
- it "should contstruct the correct command" do
165
+ describe "#command" do
166
+ it "should construct the correct command" do
55
167
  pdfkit = PDFKit.new('html', :page_size => 'Letter', :toc_l1_font_size => 12, :replace => {'foo' => 'bar'})
56
168
  command = pdfkit.command
57
169
  expect(command).to include "wkhtmltopdf"
@@ -123,7 +235,7 @@ describe PDFKit do
123
235
  expect(pdfkit.command).to match /#{file_path} -$/
124
236
  end
125
237
 
126
- it "should specify the path for the ouput if a apth is given" do
238
+ it "should specify the path for the ouput if a path is given" do
127
239
  file_path = "/path/to/output.pdf"
128
240
  pdfkit = PDFKit.new("html")
129
241
  expect(pdfkit.command(file_path)).to match /#{file_path}$/
@@ -223,7 +335,7 @@ describe PDFKit do
223
335
  expect(pdfkit.command).not_to include '--quiet'
224
336
  end
225
337
 
226
- it "should use quiet option by defautl" do
338
+ it "should use quiet option by default" do
227
339
  pdfkit = PDFKit.new('html')
228
340
  expect(pdfkit.command).to include '--quiet'
229
341
  end
@@ -241,9 +353,22 @@ describe PDFKit do
241
353
  end
242
354
  end
243
355
 
356
+ it "should not use quiet option in verbose mode when option of quiet is configured" do
357
+ PDFKit.configure do |config|
358
+ config.verbose = true
359
+ config.default_options[:quiet] = true
360
+ end
361
+
362
+ pdfkit = PDFKit.new('html')
363
+ expect(pdfkit.command).not_to include '--quiet'
364
+
365
+ PDFKit.configure do |config|
366
+ config.verbose = false
367
+ end
368
+ end
244
369
  end
245
370
 
246
- context "#to_pdf" do
371
+ describe "#to_pdf" do
247
372
  it "should not read the contents of the pdf when saving it as a file" do
248
373
  file_path = "/my/file/path.pdf"
249
374
  pdfkit = PDFKit.new('html', :page_size => 'Letter')
@@ -252,7 +377,7 @@ describe PDFKit do
252
377
  expect(mock_pdf).to receive(:puts)
253
378
  expect(mock_pdf).not_to receive(:gets) # do no read the contents when given a file path
254
379
  expect(mock_pdf).to receive(:close_write)
255
-
380
+
256
381
 
257
382
  expect(IO).to receive(:popen) do |args, mode, &block|
258
383
  block.call(mock_pdf)
@@ -323,7 +448,7 @@ describe PDFKit do
323
448
  #NOTICE: This test is failed if use wkhtmltopdf-binary (0.9.9.1)
324
449
  it "should throw an error if it is unable to connect" do
325
450
  pdfkit = PDFKit.new("http://google.com/this-should-not-be-found/404.html")
326
- expect { pdfkit.to_pdf }.to raise_error /exitstatus=2/
451
+ expect { pdfkit.to_pdf }.to raise_error /exitstatus=1/
327
452
  end
328
453
 
329
454
  it "should not throw an error if it is unable to connect", pending: 'this test works for wkhtmltopdf-binary (0.9.9.1)' do
@@ -333,13 +458,13 @@ describe PDFKit do
333
458
  end
334
459
 
335
460
  it "should generate PDF if there are missing assets" do
336
- pdfkit = PDFKit.new("<html><body><img alt='' src='http://example.com/surely-it-doesnt-exist.gif' /></body></html>", ignore_load_errors: true)
461
+ pdfkit = PDFKit.new("<html><body><img alt='' src='http://example.com/surely-it-doesnt-exist.gif' /></body></html>")
337
462
  pdf = pdfkit.to_pdf
338
463
  expect(pdf[0...4]).to eq("%PDF") # PDF Signature at the beginning
339
464
  end
340
465
  end
341
466
 
342
- context "#to_file" do
467
+ describe "#to_file" do
343
468
  before do
344
469
  @file_path = File.join(SPEC_ROOT,'fixtures','test.pdf')
345
470
  File.delete(@file_path) if File.exist?(@file_path)
@@ -360,7 +485,7 @@ describe PDFKit do
360
485
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
361
486
  pdfkit = PDFKit.new(File.new(file_path))
362
487
  pdf_data = pdfkit.to_pdf
363
- file = pdfkit.to_file(@file_path)
488
+ pdfkit.to_file(@file_path)
364
489
  file_data = open(@file_path, 'rb') {|io| io.read }
365
490
  expect(pdf_data.size).to eq(file_data.size)
366
491
  end
data/spec/source_spec.rb CHANGED
@@ -1,18 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PDFKit::Source do
4
-
5
4
  describe "#url?" do
6
5
  it "should return true if passed a url like string" do
7
6
  source = PDFKit::Source.new('http://google.com')
8
7
  expect(source).to be_url
9
8
  end
10
-
9
+
11
10
  it "should return false if passed a file" do
12
11
  source = PDFKit::Source.new(File.new(__FILE__))
13
12
  expect(source).not_to be_url
14
13
  end
15
-
14
+
16
15
  it "should return false if passed HTML" do
17
16
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
18
17
  expect(source).not_to be_url
@@ -23,52 +22,52 @@ describe PDFKit::Source do
23
22
  expect(source).not_to be_url
24
23
  end
25
24
  end
26
-
25
+
27
26
  describe "#file?" do
28
27
  it "should return true if passed a file" do
29
28
  source = PDFKit::Source.new(::File.new(__FILE__))
30
29
  expect(source).to be_file
31
30
  end
32
-
31
+
33
32
  it "should return false if passed a url like string" do
34
33
  source = PDFKit::Source.new('http://google.com')
35
34
  expect(source).not_to be_file
36
35
  end
37
-
36
+
38
37
  it "should return false if passed HTML" do
39
38
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
40
39
  expect(source).not_to be_file
41
40
  end
42
41
  end
43
-
42
+
44
43
  describe "#html?" do
45
44
  it "should return true if passed HTML" do
46
45
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
47
46
  expect(source).to be_html
48
47
  end
49
-
48
+
50
49
  it "should return false if passed a file" do
51
50
  source = PDFKit::Source.new(::File.new(__FILE__))
52
51
  expect(source).not_to be_html
53
52
  end
54
-
53
+
55
54
  it "should return false if passed a url like string" do
56
55
  source = PDFKit::Source.new('http://google.com')
57
56
  expect(source).not_to be_html
58
57
  end
59
58
  end
60
-
59
+
61
60
  describe "#to_s" do
62
61
  it "should return the HTML if passed HTML" do
63
62
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
64
63
  expect(source.to_s).to eq('<blink>Oh Hai!</blink>')
65
64
  end
66
-
65
+
67
66
  it "should return a path if passed a file" do
68
67
  source = PDFKit::Source.new(::File.new(__FILE__))
69
68
  expect(source.to_s).to eq(__FILE__)
70
69
  end
71
-
70
+
72
71
  it "should return the url if passed a url like string" do
73
72
  source = PDFKit::Source.new('http://google.com')
74
73
  expect(source.to_s).to eq('http://google.com')
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  SPEC_ROOT = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift(SPEC_ROOT)
3
3
  $LOAD_PATH.unshift(File.join(SPEC_ROOT, '..', 'lib'))
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter 'spec/'
7
+ end
8
+
4
9
  require 'pdfkit'
5
10
  require 'rspec'
6
11
  require 'mocha'
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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Pace
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-11 00:00:00.000000000 Z
12
+ date: 2015-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -135,6 +135,7 @@ files:
135
135
  - lib/pdfkit/source.rb
136
136
  - lib/pdfkit/version.rb
137
137
  - pdfkit.gemspec
138
+ - spec/configuration_spec.rb
138
139
  - spec/fixtures/example.css
139
140
  - spec/fixtures/example.html
140
141
  - spec/fixtures/example_with_hex_symbol.css
@@ -166,6 +167,7 @@ signing_key:
166
167
  specification_version: 4
167
168
  summary: HTML+CSS -> PDF
168
169
  test_files:
170
+ - spec/configuration_spec.rb
169
171
  - spec/fixtures/example.css
170
172
  - spec/fixtures/example.html
171
173
  - spec/fixtures/example_with_hex_symbol.css