prawn_rails 0.0.3 → 0.0.4

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.rdoc +30 -6
  2. data/Rakefile +1 -1
  3. data/lib/prawn_rails.rb +11 -0
  4. metadata +4 -4
data/README.rdoc CHANGED
@@ -1,8 +1,8 @@
1
- = Prawn Rails
1
+ = Prawn::Rails
2
2
 
3
- Prawn Rails provides a simple way of creating PDF views in Rails 3 using the prawn library.
3
+ Prawn::Rails provides a simple way of creating PDF views in Rails 3 using the prawn library.
4
4
 
5
- To use Prawn Rails simply add the line
5
+ To use Prawn::Rails simply add the line
6
6
 
7
7
  gem 'prawn_rails'
8
8
 
@@ -18,7 +18,7 @@ which will be used whenever the user requests a page with a 'pdf' extension
18
18
 
19
19
  == Usage
20
20
 
21
- prawn_rails is designed to provide only a very thin wrapper around Prawn itself. A prawn_rails view should consist of only a call to the function prawn_document and a block. This will create an instance of Prawn::Document and yield it to the block.
21
+ Prawn::Rails is designed to provide only a very thin wrapper around Prawn itself. A Prawn::Rails view should consist of only a call to the function prawn_document and a block. This will create an instance of Prawn::Document and yield it to the block.
22
22
  For a simple pdf view try:
23
23
 
24
24
  views/.../simple.pdf.prawn
@@ -47,7 +47,9 @@ views/.../index.pdf.prawn
47
47
 
48
48
  This will produce a pdf with Jane, John, and Jack all written on seperate lines.
49
49
 
50
- Notice we passed a hash into prawn_document. Any parameters placed in this hash will be passed to the constructor of Prawn::Document, with one exception. The renderer option will be removed before creating the document and can be used to override the class to be used for rendering with a subclass of Prawn::Document like so:
50
+ Notice we passed a hash into prawn_document. Any parameters placed in this hash will be passed to the constructor of Prawn::Document, with a few exceptions. The :renderer, :force_download, and :filename options will not be passed on, but instead will be used as described below.
51
+
52
+ The :renderer option will be removed before creating the document and can be used to override the class to be used for rendering with a subclass of Prawn::Document like so:
51
53
 
52
54
  views/.../override.pdf.prawn
53
55
 
@@ -69,13 +71,35 @@ application_helper.rb
69
71
 
70
72
  This would generate a canned report with just the lines Foo and Bar.
71
73
 
74
+ The :force_download option does makes the browser display a 'save as' dialog rather than attempting to display the content in browser (this is achieved by setting the Content-Dispoition header).
75
+ Note: due to problems with the Acrobat Reader plugin, this defaults to true if the :filename option is used.
76
+
77
+ views/.../saveas.pdf.prawn
78
+
79
+ prawn_document(:force_download=>true) do |pdf|
80
+ pdf.text "Hello World"
81
+ end
82
+
83
+ The above will cause a 'save as' dialog to appear, even in browsers with a PDF plugin.
84
+
85
+ Finally is the :filename option. This allows you to override the default filename to something other than the name of the action.
86
+ Note: You should include the .pdf extension in the filename. Prawn::Rails will not do this for you.
87
+
88
+ views/.../filename.pdf.prawn
89
+
90
+ prawn_document(:filename=>'Hello.pdf') do |pdf|
91
+ pdf.text "Hello World"
92
+ end
93
+
94
+ This will result in the user being promted to download a file named 'Hello.pdf'.
95
+
72
96
  == Gotchas
73
97
 
74
98
  The one major gotcha at this point is that layouts do not work. Do not attempt to make an app/views/layouts/application.pdf.prawn. All your pdf views will quit. This is something I hope to fix in a later release. In the meantime I recommend using custom classes like the one above to achieve a similair effect.
75
99
 
76
100
  == Examples
77
101
 
78
- For examples see: http://github.com/Volundr/prawn_rails_demo
102
+ For examples see: http://prawn-rails-demo.heroku.com
79
103
 
80
104
 
81
105
  Copyright (c) 2010 Walton Hoops, released under the MIT license
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ PKG_FILES = FileList[
13
13
 
14
14
  spec = Gem::Specification.new do |s|
15
15
  s.name = "prawn_rails"
16
- s.version = "0.0.3"
16
+ s.version = "0.0.4"
17
17
  s.author = "Walton Hoops"
18
18
  s.email = "me@waltonhoops.com"
19
19
  s.homepage = "http://github.com/Volundr/prawn-rails"
data/lib/prawn_rails.rb CHANGED
@@ -8,12 +8,23 @@ module Prawn
8
8
  module PrawnHelper
9
9
 
10
10
  def prawn_document(opts={})
11
+ download = opts.delete(:force_download)
12
+ filename = opts.delete(:filename)
11
13
  pdf = (opts.delete(:renderer) || Prawn::Document).new(opts)
12
14
  yield pdf if block_given?
13
15
 
16
+ disposition(download, filename) if (download || filename)
17
+
14
18
  pdf
15
19
  end
16
20
 
21
+ def disposition(download, filename)
22
+ download = true if (filename && download == nil)
23
+ disposition = download ? "attachment;" : "inline;"
24
+ disposition += " filename=#{filename}" if filename
25
+ headers["Content-Disposition"]=disposition
26
+ end
27
+
17
28
  end
18
29
 
19
30
  class TemplateHandler < ActionView::Template::Handler
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Walton Hoops
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-23 00:00:00 -06:00
18
+ date: 2010-11-02 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency