Class: Rack::ChromeFrame
- Inherits:
-
Object
- Object
- Rack::ChromeFrame
- Defined in:
- lib/rack/chrome_frame.rb
Instance Method Summary collapse
- #body_with_chrome_frame(response) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ ChromeFrame
constructor
A new instance of ChromeFrame.
Constructor Details
#initialize(app, options = {}) ⇒ ChromeFrame
4 5 6 |
# File 'lib/rack/chrome_frame.rb', line 4 def initialize(app, ={}) @app = app end |
Instance Method Details
#body_with_chrome_frame(response) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rack/chrome_frame.rb', line 19 def body_with_chrome_frame(response) body_to_string = response.body.to_s head = " <meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\">\n HEAD\n \n bod = <<-BOD\n <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js\"></script>\n <div id=\"cf-placeholder\"></div>\n <script>CFInstall.check({node: \"cf-placeholder\"});</script>\n BOD\n\n body_to_string.gsub!(/<\\/head>/, head + \"\\n</head>\")\n body_to_string.gsub!(/<\\/body>/, bod + \"\\n</body>\")\n [body_to_string]\nend\n" |
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rack/chrome_frame.rb', line 8 def call(env) status, headers, response = @app.call(env) if env['HTTP_USER_AGENT'] =~ /MSIE/ && headers['Content-Type'] =~ /text\/html/ response.body = body_with_chrome_frame(response) headers.merge("Content-Length" => response.body.length.to_s) end [status, headers, response] end |