Class: Prawnto::CompileSupport
- Inherits:
-
Object
- Object
- Prawnto::CompileSupport
- Defined in:
- lib/prawnto/compile_support.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #called_from_mailer? ⇒ Boolean
- #called_from_view_spec? ⇒ Boolean
- #ie_request? ⇒ Boolean
-
#initialize(controller) ⇒ CompileSupport
constructor
A new instance of CompileSupport.
- #pull_options ⇒ Object
-
#set_cache_control ⇒ Object
TODO: kept around from railspdf– maybe not needed anymore? should check.
- #set_content_type ⇒ Object
- #set_disposition ⇒ Object
- #set_headers ⇒ Object
- #set_other_headers_for_ie_ssl ⇒ Object
-
#set_pragma ⇒ Object
TODO: kept around from railspdf– maybe not needed anymore? should check.
- #ssl_request? ⇒ Boolean
Constructor Details
#initialize(controller) ⇒ CompileSupport
Returns a new instance of CompileSupport.
5 6 7 8 9 |
# File 'lib/prawnto/compile_support.rb', line 5 def initialize(controller) @controller = controller @options = set_headers end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/prawnto/compile_support.rb', line 3 def @options end |
Instance Method Details
#called_from_mailer? ⇒ Boolean
25 26 27 |
# File 'lib/prawnto/compile_support.rb', line 25 def called_from_mailer? defined?(ActionMailer) && defined?(ActionMailer::Base) && @controller.is_a?(ActionMailer::Base) end |
#called_from_view_spec? ⇒ Boolean
29 30 31 |
# File 'lib/prawnto/compile_support.rb', line 29 def called_from_view_spec? defined?(ActionView::TestCase) && defined?(ActionView::TestCase::TestController) && @controller.is_a?(ActionView::TestCase::TestController) end |
#ie_request? ⇒ Boolean
33 34 35 |
# File 'lib/prawnto/compile_support.rb', line 33 def ie_request? @controller.request.env['HTTP_USER_AGENT'] =~ /msie/i end |
#pull_options ⇒ Object
11 12 13 |
# File 'lib/prawnto/compile_support.rb', line 11 def @controller.send :compute_prawnto_options || {} end |
#set_cache_control ⇒ Object
TODO: kept around from railspdf– maybe not needed anymore? should check.
59 60 61 62 63 64 65 |
# File 'lib/prawnto/compile_support.rb', line 59 def set_cache_control if ssl_request? && ie_request? @controller.headers['Cache-Control'] = 'maxage=1' # added to make ie ssl pdfs work (per naisayer) else @controller.headers['Cache-Control'] ||= ie_request? ? 'no-cache, must-revalidate' : '' end end |
#set_content_type ⇒ Object
67 68 69 |
# File 'lib/prawnto/compile_support.rb', line 67 def set_content_type @controller.response.content_type ||= Mime[:pdf] end |
#set_disposition ⇒ Object
71 72 73 74 75 |
# File 'lib/prawnto/compile_support.rb', line 71 def set_disposition inline = [:inline] ? 'inline' : 'attachment' filename = [:filename] ? "filename=\"#{[:filename]}\"" : nil @controller.headers["Content-Disposition"] = [inline,filename].compact.join(';') end |
#set_headers ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/prawnto/compile_support.rb', line 15 def set_headers if not called_from_view_spec? and not called_from_mailer? set_pragma set_cache_control set_content_type set_disposition set_other_headers_for_ie_ssl end end |
#set_other_headers_for_ie_ssl ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/prawnto/compile_support.rb', line 41 def set_other_headers_for_ie_ssl return unless ssl_request? && ie_request? @controller.headers['Content-Description'] = 'File Transfer' @controller.headers['Content-Transfer-Encoding'] = 'binary' @controller.headers['Expires'] = '0' end |
#set_pragma ⇒ Object
TODO: kept around from railspdf– maybe not needed anymore? should check.
50 51 52 53 54 55 56 |
# File 'lib/prawnto/compile_support.rb', line 50 def set_pragma if ssl_request? && ie_request? @controller.headers['Pragma'] = 'public' # added to make ie ssl pdfs work (per naisayer) else @controller.headers['Pragma'] ||= ie_request? ? 'no-cache' : '' end end |
#ssl_request? ⇒ Boolean
37 38 39 |
# File 'lib/prawnto/compile_support.rb', line 37 def ssl_request? @controller.request.ssl? end |