Created
November 16, 2010 06:08
-
-
Save dgb/701504 to your computer and use it in GitHub Desktop.
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 'sinatra' | |
get '/' do | |
<<-EOS | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>FizzBuzz</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
window.addEvent('domready', function(){ | |
var FizzBuzz = new Class({ | |
Implements: Options, | |
initialize:function(options){ | |
this.position = 0; | |
this.limit = 100; | |
this.setOptions(options); | |
this.element = this.options.element; | |
this.request = new Request(this.options.request); | |
this.request.addEvent('success', function(response){ | |
new Element('div', { | |
text:response | |
}).inject(this.element); | |
if(this.position < this.limit) this.run(); | |
}.bind(this)); | |
}, | |
run:function(){ | |
this.position++; | |
this.request.send({ | |
data:{ | |
x:this.position | |
} | |
}); | |
return this; | |
}, | |
}); | |
var fizzBuzz = new FizzBuzz({ | |
element:$('fizzbuzz'), | |
request:{ | |
url:'/', | |
method:'post' | |
} | |
}).run(); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="fizzbuzz"></div> | |
</body> | |
</html> | |
EOS | |
end | |
post '/' do | |
x = params[:x].to_i | |
if x % 15 == 0 | |
"FizzBuzz" | |
elsif x % 5 == 0 | |
"Buzz" | |
elsif x % 3 == 0 | |
"Fizz" | |
else | |
x.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment