wicked_pdf 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/pdf_helper.rb +9 -3
  2. data/lib/wicked_pdf_helper.rb +12 -3
  3. metadata +63 -52
data/lib/pdf_helper.rb CHANGED
@@ -55,7 +55,9 @@ module PdfHelper
55
55
  end
56
56
 
57
57
  def make_pdf(options = {})
58
- html_string = render_to_string(:template => options[:template], :file => options[:file], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers])
58
+ render_opts = {:template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers]}
59
+ render_opts.merge!(:file => options[:file]) if options[:file]
60
+ html_string = render_to_string(render_opts)
59
61
  options = prerender_header_and_footer(options)
60
62
  w = WickedPdf.new(options[:wkhtmltopdf])
61
63
  w.pdf_from_string(html_string, options)
@@ -67,7 +69,9 @@ module PdfHelper
67
69
  options[:template] ||= File.join(controller_path, action_name)
68
70
  options[:disposition] ||= "inline"
69
71
  if options[:show_as_html]
70
- render :template => options[:template], :file => options[:file], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => "text/html"
72
+ render_opts = {:template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => "text/html"}
73
+ render_opts.merge!(:file => options[:file]) if options[:file]
74
+ render(render_opts)
71
75
  else
72
76
  pdf_content = make_pdf(options)
73
77
  File.open(options[:save_to_file], 'wb') {|file| file << pdf_content } if options[:save_to_file]
@@ -83,7 +87,9 @@ module PdfHelper
83
87
  @hf_tempfiles = [] if ! defined?(@hf_tempfiles)
84
88
  @hf_tempfiles.push( tf=WickedPdfTempfile.new("wicked_#{hf}_pdf.html") )
85
89
  options[hf][:html][:layout] ||= options[:layout]
86
- tf.write render_to_string(:template => options[hf][:html][:template], :file => options[hf][:html][:file], :layout => options[hf][:html][:layout], :locals => options[hf][:html][:locals], :formats => options[hf][:html][:formats], :handlers => options[hf][:html][:handlers])
90
+ render_opts = {:template => options[hf][:html][:template], :file => options[hf][:html][:file], :layout => options[hf][:html][:layout], :locals => options[hf][:html][:locals], :formats => options[hf][:html][:formats], :handlers => options[hf][:html][:handlers]}
91
+ render_opts.merge!({:file => options[hf][:html][:file]}) if options[:file]
92
+ tf.write render_to_string(render_opts)
87
93
  tf.flush
88
94
  options[hf][:html].delete(:template)
89
95
  options[hf][:html][:url] = "file:///#{tf.path}"
@@ -3,10 +3,15 @@ module WickedPdfHelper
3
3
  String === Rails.root ? Pathname.new(Rails.root) : Rails.root
4
4
  end
5
5
 
6
+ def self.add_extension(filename, extension)
7
+ (File.extname(filename.to_s)[1..-1] == extension) ? filename : "#{filename}.#{extension}"
8
+ end
9
+
6
10
  def wicked_pdf_stylesheet_link_tag(*sources)
7
11
  css_dir = WickedPdfHelper.root_path.join('public', 'stylesheets')
8
12
  css_text = sources.collect { |source|
9
- "<style type='text/css'>#{File.read(css_dir.join(source+'.css'))}</style>"
13
+ source = WickedPdfHelper.add_extension(source, 'css')
14
+ "<style type='text/css'>#{File.read(css_dir.join(source))}</style>"
10
15
  }.join("\n")
11
16
  css_text.respond_to?(:html_safe) ? css_text.html_safe : css_text
12
17
  end
@@ -16,6 +21,7 @@ module WickedPdfHelper
16
21
  end
17
22
 
18
23
  def wicked_pdf_javascript_src_tag(jsfile, options={})
24
+ jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
19
25
  javascript_src_tag "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}", options
20
26
  end
21
27
 
@@ -27,7 +33,8 @@ module WickedPdfHelper
27
33
  module Assets
28
34
  def wicked_pdf_stylesheet_link_tag(*sources)
29
35
  sources.collect { |source|
30
- "<style type='text/css'>#{read_asset(source+".css")}</style>"
36
+ source = WickedPdfHelper.add_extension(source, 'css')
37
+ "<style type='text/css'>#{read_asset(source)}</style>"
31
38
  }.join("\n").html_safe
32
39
  end
33
40
 
@@ -36,12 +43,14 @@ module WickedPdfHelper
36
43
  end
37
44
 
38
45
  def wicked_pdf_javascript_src_tag(jsfile, options={})
46
+ jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
39
47
  javascript_include_tag "file:///#{asset_pathname(jsfile).to_s}", options
40
48
  end
41
49
 
42
50
  def wicked_pdf_javascript_include_tag(*sources)
43
51
  sources.collect { |source|
44
- "<script type='text/javascript'>#{read_asset(source+".js")}</script>"
52
+ source = WickedPdfHelper.add_extension(source, 'js')
53
+ "<script type='text/javascript'>#{read_asset(source)}</script>"
45
54
  }.join("\n").html_safe
46
55
  end
47
56
 
metadata CHANGED
@@ -1,62 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wicked_pdf
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 2
10
+ version: 0.9.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Miles Z. Sterret
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-01-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
31
35
  name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- description: ! 'Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file
47
- to a user from HTML.
48
-
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: |
49
+ Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
49
50
  In other words, rather than dealing with a PDF generation DSL of some sort,
51
+ you simply write an HTML view as you would normally, and let Wicked take care of the hard stuff.
50
52
 
51
- you simply write an HTML view as you would normally, and let Wicked take care of
52
- the hard stuff.
53
-
54
- '
55
53
  email: miles.sterrett@gmail.com
56
54
  executables: []
55
+
57
56
  extensions: []
57
+
58
58
  extra_rdoc_files: []
59
- files:
59
+
60
+ files:
60
61
  - README.md
61
62
  - Rakefile
62
63
  - MIT-LICENSE
@@ -77,26 +78,36 @@ files:
77
78
  - generators/wicked_pdf/wicked_pdf_generator.rb
78
79
  homepage: https://github.com/mileszs/wicked_pdf
79
80
  licenses: []
81
+
80
82
  post_install_message:
81
83
  rdoc_options: []
82
- require_paths:
84
+
85
+ require_paths:
83
86
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
85
88
  none: false
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
97
  none: false
92
- requirements:
93
- - - ! '>='
94
- - !ruby/object:Gem::Version
95
- version: '0'
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
96
105
  requirements: []
106
+
97
107
  rubyforge_project:
98
- rubygems_version: 1.8.24
108
+ rubygems_version: 1.8.21
99
109
  signing_key:
100
110
  specification_version: 3
101
111
  summary: PDF generator (from HTML) plugin for Ruby on Rails
102
112
  test_files: []
113
+