wicked_pdf 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +1 -0
  2. data/lib/pdf_helper.rb +7 -4
  3. data/lib/wicked_pdf.rb +13 -15
  4. metadata +4 -4
data/README.md CHANGED
@@ -48,6 +48,7 @@ Next:
48
48
  :save_to_file => Rails.root.join('pdfs', "#{filename}.pdf"),
49
49
  :save_only => false, # depends on :save_to_file being set first
50
50
  :proxy => 'TEXT',
51
+ :basic_auth => false # when true username & password are automatically sent from session
51
52
  :username => 'TEXT',
52
53
  :password => 'TEXT',
53
54
  :cover => 'URL',
@@ -13,7 +13,7 @@ module PdfHelper
13
13
  def render_with_wicked_pdf(options = nil, *args, &block)
14
14
  if options.is_a?(Hash) && options.has_key?(:pdf)
15
15
  log_pdf_creation
16
- options[:basic_auth] = set_basic_auth
16
+ options[:basic_auth] = set_basic_auth(options)
17
17
  make_and_send_pdf(options.delete(:pdf), (WickedPdf.config || {}).merge(options))
18
18
  else
19
19
  render_without_wicked_pdf(options, *args, &block)
@@ -23,7 +23,7 @@ module PdfHelper
23
23
  def render_to_string_with_wicked_pdf(options = nil, *args, &block)
24
24
  if options.is_a?(Hash) && options.has_key?(:pdf)
25
25
  log_pdf_creation
26
- options[:basic_auth] = set_basic_auth
26
+ options[:basic_auth] = set_basic_auth(options)
27
27
  options.delete :pdf
28
28
  make_pdf((WickedPdf.config || {}).merge(options))
29
29
  else
@@ -37,8 +37,11 @@ module PdfHelper
37
37
  logger.info '*'*15 + 'WICKED' + '*'*15
38
38
  end
39
39
 
40
- def set_basic_auth
41
- request.env["HTTP_AUTHORIZATION"].split(" ").last if request.env["HTTP_AUTHORIZATION"]
40
+ def set_basic_auth(options={})
41
+ options[:basic_auth] ||= WickedPdf.config.fetch(:basic_auth){ false }
42
+ if options[:basic_auth] && request.env["HTTP_AUTHORIZATION"]
43
+ request.env["HTTP_AUTHORIZATION"].split(" ").last
44
+ end
42
45
  end
43
46
 
44
47
  def clean_temp_files
@@ -23,22 +23,20 @@ class WickedPdf
23
23
  end
24
24
 
25
25
  def pdf_from_string(string, options={})
26
- command_for_stdin_stdout = "#{@exe_path} #{parse_options(options)} -q - - " # -q for no errors on stdout
27
- p "*"*15 + command_for_stdin_stdout + "*"*15 unless defined?(Rails) and Rails.env != 'development'
28
- pdf, err = begin
29
- Open3.popen3(command_for_stdin_stdout) do |stdin, stdout, stderr|
30
- stdin.binmode
31
- stdout.binmode
32
- stderr.binmode
33
- stdin.write(string)
34
- stdin.close
35
- [stdout.read, stderr.read]
36
- end
37
- rescue Exception => e
38
- raise "Failed to execute #{@exe_path}: #{e}"
26
+ command = "#{@exe_path} #{parse_options(options)} -q - - " # -q for no errors on stdout
27
+ p "*"*15 + command + "*"*15 unless defined?(Rails) and Rails.env != 'development'
28
+ pdf, err = Open3.popen3(command) do |stdin, stdout, stderr|
29
+ stdin.binmode
30
+ stdout.binmode
31
+ stderr.binmode
32
+ stdin.write(string)
33
+ stdin.close
34
+ [stdout.read, stderr.read]
39
35
  end
40
- raise "PDF could not be generated!\n#{err}" if pdf and pdf.length == 0
36
+ raise "PDF could not be generated!" if pdf and pdf.rstrip.length == 0
41
37
  pdf
38
+ rescue Exception => e
39
+ raise "Failed to execute:\n#{command}\nError: #{e}"
42
40
  end
43
41
 
44
42
  private
@@ -59,7 +57,7 @@ class WickedPdf
59
57
  def parse_basic_auth(options)
60
58
  if options[:basic_auth]
61
59
  user, passwd = Base64.decode64(options[:basic_auth]).split(":")
62
- "--username #{user} --password #{passwd} "
60
+ "--username '#{user}' --password '#{passwd}'"
63
61
  else
64
62
  ""
65
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wicked_pdf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Miles Z. Sterret
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-10 00:00:00 -04:00
18
+ date: 2011-07-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21