-
-
Save guilhermechapiewski/91290 to your computer and use it in GitHub Desktop.
Integrity auto-refresher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "integrity" | |
class Refresher | |
JS = <<-EOS | |
<script type="text/javascript"> | |
//<![CDATA[ | |
setTimeout('location.reload()', %s * 1000) | |
//]]> | |
</script> | |
EOS | |
def initialize(app, interval) | |
@app = app | |
@interval = interval | |
end | |
def call(env) | |
response = @app.call(env) | |
return response unless env["PATH_INFO"] == "/" | |
body = ""; response.last.each { |s| body << s } | |
body.gsub!(/<\/head>/, (JS % @interval) + "\n</head>") | |
response[1]["Content-Length"] = body.size.to_s | |
[response.first, response[1], [body]] | |
end | |
end | |
Integrity.new | |
DataMapper.auto_migrate! | |
use Refresher, 5 | |
run Integrity::App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment