Skip to content

Instantly share code, notes, and snippets.

@sr
Created April 7, 2009 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sr/91275 to your computer and use it in GitHub Desktop.
Save sr/91275 to your computer and use it in GitHub Desktop.
Hax integrity to refresh the page
#!/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