Mercurial > hg > soundsoftware-site
annotate .svn/pristine/9a/9abb336c22d9a4a632ace300a7d6e28af42a8ed1.svn-base @ 1327:287f201c2802 redmine-2.2-integration
Add italic
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Wed, 19 Jun 2013 20:56:22 +0100 |
parents | cbb26bc654de |
children |
rev | line source |
---|---|
Chris@909 | 1 module RFPDF |
Chris@909 | 2 module TemplateHandler |
Chris@909 | 3 |
Chris@909 | 4 class CompileSupport |
Chris@909 | 5 # extend ActiveSupport::Memoizable |
Chris@909 | 6 |
Chris@909 | 7 attr_reader :options |
Chris@909 | 8 |
Chris@909 | 9 def initialize(controller) |
Chris@909 | 10 @controller = controller |
Chris@909 | 11 @options = pull_options |
Chris@909 | 12 set_headers |
Chris@909 | 13 end |
Chris@909 | 14 |
Chris@909 | 15 def pull_options |
Chris@909 | 16 @controller.send :compute_rfpdf_options || {} |
Chris@909 | 17 end |
Chris@909 | 18 |
Chris@909 | 19 def set_headers |
Chris@909 | 20 set_pragma |
Chris@909 | 21 set_cache_control |
Chris@909 | 22 set_content_type |
Chris@909 | 23 set_disposition |
Chris@909 | 24 end |
Chris@909 | 25 |
Chris@909 | 26 # TODO: kept around from railspdf-- maybe not needed anymore? should check. |
Chris@909 | 27 def ie_request? |
Chris@909 | 28 @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i |
Chris@909 | 29 end |
Chris@909 | 30 # memoize :ie_request? |
Chris@909 | 31 |
Chris@909 | 32 # added to make ie happy with ssl pdf's (per naisayer) |
Chris@909 | 33 def ssl_request? |
Chris@909 | 34 # @controller.request.env['SERVER_PROTOCOL'].downcase == "https" |
Chris@909 | 35 @controller.request.ssl? |
Chris@909 | 36 end |
Chris@909 | 37 # memoize :ssl_request? |
Chris@909 | 38 |
Chris@909 | 39 # TODO: kept around from railspdf-- maybe not needed anymore? should check. |
Chris@909 | 40 def set_pragma |
Chris@909 | 41 if ssl_request? && ie_request? |
Chris@909 | 42 @controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer) |
Chris@909 | 43 else |
Chris@909 | 44 @controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : '' |
Chris@909 | 45 end |
Chris@909 | 46 end |
Chris@909 | 47 |
Chris@909 | 48 # TODO: kept around from railspdf-- maybe not needed anymore? should check. |
Chris@909 | 49 def set_cache_control |
Chris@909 | 50 if ssl_request? && ie_request? |
Chris@909 | 51 @controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer) |
Chris@909 | 52 else |
Chris@909 | 53 @controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : '' |
Chris@909 | 54 end |
Chris@909 | 55 end |
Chris@909 | 56 |
Chris@909 | 57 def set_content_type |
Chris@909 | 58 @controller.response.content_type ||= Mime::PDF |
Chris@909 | 59 end |
Chris@909 | 60 |
Chris@909 | 61 def set_disposition |
Chris@909 | 62 inline = options[:inline] ? 'inline' : 'attachment' |
Chris@909 | 63 filename = options[:filename] ? "filename=#{options[:filename]}" : nil |
Chris@909 | 64 @controller.headers["Content-Disposition"] = [inline,filename].compact.join(';') |
Chris@909 | 65 end |
Chris@909 | 66 |
Chris@909 | 67 end |
Chris@909 | 68 |
Chris@909 | 69 end |
Chris@909 | 70 end |
Chris@909 | 71 |
Chris@909 | 72 |
Chris@909 | 73 |