Class: Rack::Iphone
- Inherits:
-
Object
- Object
- Rack::Iphone
- Defined in:
- lib/rack_iphone.rb
Constant Summary collapse
- CODE =
%{ <script type="text/javascript"> (function(){ var RESEND_REQUEST = {{RESEND}}; function isFullScreen(){ return navigator.userAgent.match(/WebKit.*Mobile/) && !navigator.userAgent.match(/Safari/); } if(isFullScreen()){ if(!document.cookie.match(/{{REGEX}}/)){ var storedValues = localStorage.getItem('__cookie__'); if(storedValues){ var values = storedValues.split(';'); for(var i=0; i < values.length; i++) document.cookie = values[i]; } document.cookie = '_cookieset_=1'; if(RESEND_REQUEST){ window.location.reload(); } } } })() </script> }
- COOKIE =
%{ <script type="text/javascript"> (function(){ var COOKIE = "{{COOKIE}}"; var lastCookie = null; setInterval(function(){ if(lastCookie != ''+COOKIE){ lastCookie = ''+COOKIE; localStorage.setItem('__cookie__', ''+COOKIE); } },1000); })() </script> }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Iphone
constructor
A new instance of Iphone.
Constructor Details
#initialize(app) ⇒ Iphone
Returns a new instance of Iphone.
48 49 50 |
# File 'lib/rack_iphone.rb', line 48 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rack_iphone.rb', line 52 def call(env) if iphone_web_app?(env) if new_session?(env) [200,{'Content-Length' => code(true).length.to_s, 'Content-Type' => 'text/html'}, code(true)] else status, headers, body = @app.call(env) # Put in patch code ## ## request = Rack::Request.new(env) response = Rack::Response.new([], status, headers) = String.new request..each_pair do |key,value| += "#{key}=#{value};" end body.each do |part| part.gsub!(/<\/head>/, "#{()}</head>") response.write(part) end response.finish end else @app.call(env) end end |