Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Working :)

  • Loading branch information...
commit 229585453dc691922812c62f8a0a5cdeea445998 1 parent 3839635
Frederick Ros authored January 26, 2012
6  demo/static/index.html
@@ -5,11 +5,7 @@
5 5
     <link rel="stylesheet" href="css/twitsock.css">
6 6
   </head>
7 7
   <body>
8  
-    <h1> Here we are</h1>
9  
-    <div>
10  
-      <input id="search" type="text" placeholder="riviera.rb">
11  
-      <button id="go" type="submit">Go !</button>
12  
-    </div>
  8
+    <h1>Results</h1>
13 9
     <div id="tweets">
14 10
     </div>
15 11
     <script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
14  demo/static/scripts/twitsock.js
@@ -10,14 +10,21 @@ $(document).ready(function() {
10 10
       '</div>';
11 11
   }
12 12
 
  13
+  var get_regexp = function(search_term) {
  14
+    if (!regexs[search_term]) {
  15
+      regexs[search_term] = new RegExp("(" + search_term + ")", "gi");
  16
+    }
  17
+
  18
+    return regexs[search_term];
  19
+  }
  20
+
13 21
   var append_message = function(evt) {
14 22
     var record = $.parseJSON(evt.data);
15 23
     var user = record.name;
16  
-    var rx = regexs[record.search];
17 24
     var txt = record.tweet;
18  
-    var msg = txt.replace( rx, "<span class='highlight'>$1</span>");
  25
+    var msg = txt.replace( get_regexp(record.search), "<span class='highlight'>$1</span>");
19 26
     $('#tweets').prepend(generate_string(user, msg));
20  
-    if ( txt =~ /ruby/ ) {
  27
+    if ( txt.match(/ruby/) ) {
21 28
       $('body').addClass('roll');
22 29
     }
23 30
   }
@@ -25,7 +32,6 @@ $(document).ready(function() {
25 32
   $('#go').click(function() {
26 33
     var search_term = $('#search').val();
27 34
     console.log("About to launch search on " + search_term);
28  
-    regexs[search_term] = new RegExp("(" + search_term + ")", "gi");
29 35
 
30 36
     ws.send( 'search ' + search_term);
31 37
   });
18  demo/static/search.html
... ...
@@ -0,0 +1,18 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+  <head>
  4
+    <meta charset="UTF-8" />
  5
+    <link rel="stylesheet" href="css/twitsock.css">
  6
+  </head>
  7
+  <body>
  8
+    <h1> Here we are</h1>
  9
+    <div>
  10
+      <input id="search" type="text" placeholder="riviera.rb">
  11
+      <button id="go" type="submit">Go !</button>
  12
+    </div>
  13
+    <div id="tweets">
  14
+    </div>
  15
+    <script type="text/javascript" src="scripts/jquery-1.7.1.min.js"></script>
  16
+    <script type="text/javascript" src="scripts/twitsock.js"></script>
  17
+  </body>
  18
+</html>
19  demo/twitsock.rb
@@ -7,16 +7,12 @@
7 7
 require 'em-http-request'
8 8
 require 'json'
9 9
 
10  
-Encoding.default_internal = "UTF-8"
11  
-
12  
-# Twitter search:
13  
-#  curl -d 'track=freemobile' https://stream.twitter.com/1/statuses/filter.json -uUSER:PWD
14  
-#
15 10
 FIREHOSE = "https://stream.twitter.com/1/statuses/filter.json"
16  
-USER = "GoliathDemo"
17  
-PASS = "g0l14thd3m0"
  11
+USER = ""
  12
+PASS = ""
18 13
 
19 14
 class WebSocketEndPoint < Goliath::WebSocket
  15
+
20 16
   def on_open(env)
21 17
     # Join the channel
22 18
     env[:tbuffer] = ""
@@ -55,10 +51,15 @@ def on_close(env)
55 51
 
56 52
 class SiteIndex < Goliath::API
57 53
   def response(env)
  54
+    path = "static/"
  55
+    path += case env[Goliath::Request::REQUEST_PATH]
  56
+              when '/' then "index.html"
  57
+              when '/search' then "search.html"
  58
+            end
58 59
     [
59 60
       200,
60 61
       {"Content-Type"=>"text/html"},
61  
-      File.open(Goliath::Application.app_path("static/index.html"),File::RDONLY)
  62
+      File.open(Goliath::Application.app_path(path),File::RDONLY)
62 63
     ]
63 64
   end
64 65
 end
@@ -66,6 +67,8 @@ def response(env)
66 67
 class TwitSock < Goliath::API
67 68
   use Rack::Static, :urls => ['/scripts','/images','/css'], :root => Goliath::Application.app_path("static")
68 69
 
  70
+  get "/search", SiteIndex
  71
+
69 72
   get "/", SiteIndex
70 73
 
71 74
   map "/ws", WebSocketEndPoint

0 notes on commit 2295854

Please sign in to comment.
Something went wrong with that request. Please try again.