Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for Ruby 1.9.1 and Google AJAX Search API (insert your …

…key in layout.erb & go)
  • Loading branch information...
commit 791b3227ea673244198c4030cc86f220584cef5c 1 parent ab993ca
Ole Christian Rynning authored committed
View
27 irclogger.rb
@@ -3,6 +3,23 @@
Dir[File.dirname(__FILE__) + '/vendor/*/lib'].each { |d| $:.unshift d }
$:.unshift File.dirname(__FILE__) + '/lib'
+## Rack 0.9.1 fix ##############
+require 'rack/file'
+class Rack::File
+ MIME_TYPES = Hash.new { |hash, key|
+ Rack::Mime::MIME_TYPES[".#{key}"] }
+end
+
+## Ruby 1.9.1 fixes
+if RUBY_VERSION > '1.9'
+ ## String#each needs to be aliased
+ class String
+ alias_method :each, :each_line
+ end
+
+ ## Ruby 1.9.1 also works best with thin
+ require 'thin'
+end
require 'sinatra'
require 'date'
@@ -39,16 +56,16 @@ def info?
## Web ##########################
get '/' do
- @channels = DB["SELECT channel FROM irclog GROUP BY channel"].inject([]) { |arr, row|
+ @channels = DB["SELECT channel FROM irclog GROUP BY channel"].inject([]) { |arr, row|
arr << row[:channel] if (row[:channel] =~ /^#/ && row[:channel] != "#datamapper http://datamapper.")
- arr
+ arr
}
erb :index
end
-get '/:channel' do
- redirect "/#{param[:channel]}/"
+get '/:channel' do
+ redirect "/#{params[:channel]}/"
end
get '/:channel/' do
@@ -87,7 +104,7 @@ def info?
end
## Monkey Patching #############
-class Fixnum
+class Fixnum
def minutes
self * 60
end
View
8 lib/helpers.rb
@@ -1,9 +1,11 @@
module IRCLogger
module Helpers
- def relative_day(day)
+ def relative_day(day)
case day
- when "today": Date.today.strftime("%Y-%m-%d")
- when "yesterday": (Date.today - 1).strftime("%Y-%m-%d")
+ when "today"
+ Date.today.strftime("%Y-%m-%d")
+ when "yesterday"
+ (Date.today - 1).strftime("%Y-%m-%d")
else Date.today.strftime("%Y-%m-%d")
end
end
View
21 public/styles.css
@@ -87,3 +87,24 @@ div.time {
color: #594F4F;
text-decoration: none;
}
+
+/* Google Custom Search */
+#searchControl {
+ margin-top: 15px;
+ background-color: #ddd;
+ color: black;
+ font-family: Arial, sans-serif;
+ font-size: 13px;
+}
+
+/* Highlight -siteSearch in results area */
+
+/* bold the section header */
+.gsc-resultsRoot-siteSearch .gsc-title {
+ font-weight : bold;
+}
+
+.gsc-resultsRoot-siteSearch .gsc-keeper {
+ background-image : url('http://www.google.com/uds/css/darkgrey_check.gif');
+ font-weight : bold;
+}
View
41 views/layout.erb
@@ -3,10 +3,43 @@
<title>IRC Logs <%= "For #{@channel} on #{@date.to_s}" if @channel %></title>
<link rel="stylesheet" href="/styles.css" />
<link rel="stylesheet" href="/jquery-ui-1.7.custom.css" />
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/jquery-ui.min.js"></script>
- <script src="/actions.js"></script>
+ <link rel="stylesheet" href="http://www.google.com/uds/css/gsearch_darkgrey.css" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/jquery-ui.min.js"></script>
+ <script src="/actions.js"></script>
+ <script src="http://www.google.com/jsapi?key=ABQIAAAAxIPe_Hqn9UpeceoqlzxTEhQXPjdTLTrPJWH-F2sc2QUCP_uGzBTD6d_hb1OQjUAGLiLr--aKo38HvA" type="text/javascript"></script>
+ <script type="text/javascript">
+ //<![CDATA[
+
+ google.load('search', '1');
+ function OnLoad() {
+ var searchControl = new google.search.SearchControl();
+ <% if @channel %>
+ var channelSearch = new google.search.WebSearch();
+ channelSearch.setUserDefinedLabel("<%= @channel %>");
+ channelSearch.setSiteRestriction("http://irclogger.com/<%= @channel %>");
+ channelSearch.setUserDefinedClassSuffix("siteSearch");
+ searchControl.addSearcher(channelSearch);
+ <% end %>
+
+ //var localSearch = new google.search.LocalSearch();
+ //searchControl.addSearcher(localSearch);
+
+ var siteSearch = new google.search.WebSearch();
+ siteSearch.setUserDefinedLabel("irclogger");
+ siteSearch.setSiteRestriction("irclogger.com");
+ siteSearch.setUserDefinedClassSuffix("siteSearch");
+ searchControl.addSearcher(siteSearch);
+
+ searchControl.draw(document.getElementById("searchControl"));
+ searchControl.execute("Cucumber");
+ }
+
+ google.setOnLoadCallback(OnLoad, true);
+
+ //]]>
+ </script>
</head>
<body>
View
7 views/log.erb
@@ -24,6 +24,7 @@
<li><a href="<%= url %>"><%= url %></a></li>
<% end %>
</ul>
+ <div id="searchControl">Loading...</div>
</div>
<div id="log">
@@ -37,13 +38,13 @@
<% last_time = message.timestamp %>
<% last_nick = "" %>
<% end %>
-
+
<!-- Write out the message line -->
<div class="message">
<% unless (message.nick.blank? || message.nick == last_nick) then %>
<div class="real nick <%= (message.nick[0..0] == "*") ? "me" : "" %> <%= message.message_type %>">
<span class="nick"><%= message.nick %></span>
- <a class="permalink" href="#<%= message.timestamp %>" name="<%= message.timestamp %>">#</a>
+ <a class="permalink" href="#<%= message.timestamp %>" name="<%= message.timestamp %>">#</a>
</div>
<% else %>
<div class="nick"></div>
@@ -52,7 +53,7 @@
<%= auto_link_urls(h message.line) %>
</div>
</div>
-
+
<% last_nick = message.nick %>
<% end %>
</ol>
Please sign in to comment.
Something went wrong with that request. Please try again.