Browse files

update to work with latest sinatra + chrome

  • Loading branch information...
1 parent 64a0692 commit dec0afcca3823770ced586fd6a8daed3917c055f @igrigorik committed Jun 3, 2011
Showing with 17 additions and 16 deletions.
  1. +4 −4 jobserver.rb
  2. +1 −1 views/done.erb
  3. +10 −9 views/layout.erb
  4. +1 −1 views/map.erb
  5. +1 −1 views/reduce.erb
View
8 jobserver.rb
@@ -6,7 +6,7 @@
# 2) Client executes javascript map/reduce jobs via JavaScript
# 3) Client emits (POST) intermediate results back to job server
# 4) Client is redirected to next available job (map or reduce)
-#
+#
require "rubygems"
require "sinatra"
@@ -23,9 +23,9 @@
redirect "/done"
end
-get "/map/*" do erb :map, :file => params[:splat].first; end
-get "/reduce" do erb :reduce, :data => options.reduce_jobs; end
-get "/done" do erb :done, :answer => options.result; end
+get "/map/*" do erb :map, :locals => {:file => params[:splat].first}; end
+get "/reduce" do erb :reduce, :locals => {:data => options.reduce_jobs}; end
+get "/done" do erb :done, :locals => {:answer => options.result}; end
post "/emit/:phase" do
case params[:phase]
View
2 views/done.erb
@@ -1,4 +1,4 @@
-<%= options[:answer] %>
+<%= answer %>
<!-- Another client could be doing the final reduce, poll to see result -->
<meta http-equiv="refresh" content="2" />
View
19 views/layout.erb
@@ -1,6 +1,6 @@
<html>
<head>
- <script type="text/javascript">
+ <script type="text/javascript" defer>
function map() {
var words = document.body.innerHTML.split(/\n|\s/).length;
@@ -10,7 +10,7 @@
function reduce() {
var sum = 0;
var docs = document.body.innerHTML.split(/\n/);
- for each (num in docs) { sum+= parseInt(num) > 0 ? parseInt(num) : 0 }
+ for (num in docs) { sum += ((parseInt(num) > 0) ? parseInt(num) : 0) }
emit('finalize', {'sum': sum});
}
@@ -20,21 +20,22 @@
myForm.action = "/emit/"+phase;
for (var k in data) {
- var myInput = document.createElement("input") ;
- myInput.setAttribute("name", k) ;
+ var myInput = document.createElement("input");
+ myInput.setAttribute("name", k);
myInput.setAttribute("value", data[k]);
- myForm.appendChild(myInput) ;
+ myForm.appendChild(myInput);
}
- document.body.appendChild(myForm) ;
- myForm.submit() ;
- document.body.removeChild(myForm) ;
+ document.body.appendChild(myForm);
+ myForm.submit();
+ document.body.removeChild(myForm);
}
+ window.onload = function(){ <%= "#{@execute}();" if @execute %> };
</script>
</head>
- <body onload="<%= "#{@execute}();" if @execute %>">
+ <body>
<%= yield %>
</body>
</html>
View
2 views/map.erb
@@ -1,2 +1,2 @@
<% @execute = "map" %>
-<%= File.open(options[:file], "r").readlines.join %>
+<%= IO.read(file).strip %>
View
2 views/reduce.erb
@@ -1,2 +1,2 @@
<% @execute = "reduce" %>
-<%= options[:data].join("\n") %>
+<%= data.join("\n") %>

0 comments on commit dec0afc

Please sign in to comment.