pdfkit 0.4.0 → 0.4.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/README.md CHANGED
@@ -42,6 +42,10 @@ If you're on Windows or you installed wkhtmltopdf by hand to a location other th
42
42
  # config/initializers/pdfkit.rb
43
43
  PDFKit.configure do |config|
44
44
  config.wkhtmltopdf = '/path/to/wkhtmltopdf'
45
+ config.default_options = {
46
+ :page_size => 'Legal',
47
+ :print_media_type => true
48
+ }
45
49
  end
46
50
 
47
51
  ## Middleware
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -1,10 +1,18 @@
1
1
  class PDFKit
2
2
  class Configuration
3
- attr_accessor :meta_tag_prefix, :wkhtmltopdf
3
+ attr_accessor :meta_tag_prefix, :wkhtmltopdf, :default_options
4
4
 
5
5
  def initialize
6
6
  @meta_tag_prefix = 'pdfkit-'
7
7
  @wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'
8
+ @default_options = {
9
+ :disable_smart_shrinking => true,
10
+ :page_size => 'Letter',
11
+ :margin_top => '0.75in',
12
+ :margin_right => '0.75in',
13
+ :margin_bottom => '0.75in',
14
+ :margin_left => '0.75in'
15
+ }
8
16
  end
9
17
  end
10
18
 
@@ -23,11 +23,10 @@ class PDFKit
23
23
  body = pdf.to_pdf
24
24
 
25
25
  # Do not cache PDFs
26
- puts "DELETING CACHING"
27
26
  headers.delete('ETag')
28
27
  headers.delete('Cache-Control')
29
28
 
30
- headers["Content-Length"] = body.bytes.to_a.size.to_s
29
+ headers["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
31
30
  headers["Content-Type"] = "application/pdf"
32
31
 
33
32
  response = [body]
@@ -21,21 +21,9 @@ class PDFKit
21
21
  @source = Source.new(url_file_or_html)
22
22
 
23
23
  @stylesheets = []
24
-
25
- default_options = {
26
- :disable_smart_shrinking => true,
27
- :page_size => 'Letter',
28
- :margin_top => '0.75in',
29
- :margin_right => '0.75in',
30
- :margin_bottom => '0.75in',
31
- :margin_left => '0.75in'
32
- }
33
24
 
34
- @options = options.dup
35
- unless source.url?
36
- @options.merge! find_options_in_meta(url_file_or_html)
37
- end
38
- @options = normalize_options(default_options.merge(@options))
25
+ @options = normalize_options(PDFKit.configuration.default_options.merge(options))
26
+ @options.merge! find_options_in_meta(url_file_or_html) unless source.url?
39
27
 
40
28
  raise NoExecutableError.new unless File.exists?(PDFKit.configuration.wkhtmltopdf)
41
29
  end
@@ -130,7 +118,7 @@ class PDFKit
130
118
  when TrueClass
131
119
  nil
132
120
  else
133
- value
121
+ value.to_s
134
122
  end
135
123
  end
136
124
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pdfkit}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.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-07-16}
12
+ s.date = %q{2010-07-19}
13
13
  s.default_executable = %q{pdfkit}
14
14
  s.description = %q{Uses wkhtmltopdf to create PDFs using HTML}
15
15
  s.email = %q{jared@codewordstudios.com}
@@ -45,7 +45,7 @@ describe PDFKit do
45
45
  pdfkit = PDFKit.new('html', :page_size => 'Letter', :toc_l1_font_size => 12)
46
46
  pdfkit.command[0].should include('wkhtmltopdf')
47
47
  pdfkit.command[pdfkit.command.index('--page-size') + 1].should == 'Letter'
48
- pdfkit.command[pdfkit.command.index('--toc-l1-font-size') + 1].should == 12
48
+ pdfkit.command[pdfkit.command.index('--toc-l1-font-size') + 1].should == '12'
49
49
  end
50
50
 
51
51
  it "will not include default options it is told to omit" do
@@ -90,6 +90,18 @@ describe PDFKit do
90
90
  pdf[0...4].should == "%PDF" # PDF Signature at beginning of file
91
91
  end
92
92
 
93
+ it "should generate a PDF with a numerical parameter" do
94
+ pdfkit = PDFKit.new('html', :header_spacing => 1)
95
+ pdf = pdfkit.to_pdf
96
+ pdf[0...4].should == "%PDF" # PDF Signature at beginning of file
97
+ end
98
+
99
+ it "should generate a PDF with a symbol parameter" do
100
+ pdfkit = PDFKit.new('html', :page_size => :Letter)
101
+ pdf = pdfkit.to_pdf
102
+ pdf[0...4].should == "%PDF" # PDF Signature at beginning of file
103
+ end
104
+
93
105
  it "should have the stylesheet added to the head if it has one" do
94
106
  pdfkit = PDFKit.new("<html><head></head><body>Hai!</body></html>")
95
107
  css = File.join(SPEC_ROOT,'fixtures','example.css')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfkit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - jdpace
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-16 00:00:00 -04:00
18
+ date: 2010-07-19 00:00:00 -04:00
19
19
  default_executable: pdfkit
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency