To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 9a / 9abb336c22d9a4a632ace300a7d6e28af42a8ed1.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2 KB)

1
module RFPDF
2
  module TemplateHandler
3

    
4
    class CompileSupport
5
      # extend ActiveSupport::Memoizable
6
      
7
      attr_reader :options
8

    
9
      def initialize(controller)
10
        @controller = controller
11
        @options = pull_options
12
        set_headers
13
      end
14

    
15
      def pull_options
16
        @controller.send :compute_rfpdf_options || {}
17
      end
18

    
19
      def set_headers
20
        set_pragma
21
        set_cache_control
22
        set_content_type
23
        set_disposition
24
      end
25

    
26
      # TODO: kept around from railspdf-- maybe not needed anymore? should check.
27
      def ie_request?
28
        @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
29
      end
30
      # memoize :ie_request?
31

    
32
      # added to make ie happy with ssl pdf's (per naisayer)
33
      def ssl_request?
34
        # @controller.request.env['SERVER_PROTOCOL'].downcase == "https"
35
        @controller.request.ssl?
36
      end
37
      # memoize :ssl_request?
38

    
39
      # TODO: kept around from railspdf-- maybe not needed anymore? should check.
40
      def set_pragma
41
        if ssl_request? && ie_request?
42
          @controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer)
43
        else
44
          @controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : ''
45
        end
46
      end
47

    
48
      # TODO: kept around from railspdf-- maybe not needed anymore? should check.
49
      def set_cache_control
50
        if ssl_request? && ie_request?
51
          @controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer)
52
        else
53
          @controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : ''
54
        end
55
      end
56

    
57
      def set_content_type
58
        @controller.response.content_type ||= Mime::PDF
59
      end
60

    
61
      def set_disposition
62
        inline = options[:inline] ? 'inline' : 'attachment'
63
        filename = options[:filename] ? "filename=#{options[:filename]}" : nil
64
        @controller.headers["Content-Disposition"] = [inline,filename].compact.join(';')
65
      end
66

    
67
    end
68

    
69
  end
70
end
71

    
72

    
73