Skip to content

Instantly share code, notes, and snippets.

@wireframe
Created November 10, 2010 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wireframe/670377 to your computer and use it in GitHub Desktop.
Save wireframe/670377 to your computer and use it in GitHub Desktop.
use cramp to render layout immediately and use javascript to update placeholders
require 'rubygems'
require 'cramp/controller'
class WelcomeAction < Cramp::Controller::Action
periodic_timer :send_updates, :every => 3
def start
@counter = 0
render ["<html><body><h1 id='placeholder'>Content goes here</h1>", "\n"]
render ["<div>testing</div>" * 200, "\n"]
end
def send_updates
render ["<script type='text/javascript'>document.getElementById('placeholder').innerHTML = '#{@counter}';</script>", "\n"]
@counter +=1
if @counter == 3
render ['</body></html>', "\n"]
finish
end
end
end
Rack::Handler::Thin.run WelcomeAction, :Port => 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment