Created
November 10, 2010 04:59
-
-
Save wireframe/670377 to your computer and use it in GitHub Desktop.
use cramp to render layout immediately and use javascript to update placeholders
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
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