Skip to content

Commit

Permalink
Adding 'Recent conversation' to the archive page. Modified CSS.
Browse files Browse the repository at this point in the history
  • Loading branch information
gimite committed May 7, 2009
1 parent b2ec4e0 commit 1c96464
Show file tree
Hide file tree
Showing 12 changed files with 4,410 additions and 17 deletions.
17 changes: 17 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,17 @@
Distributed under Artistic License.

Authors:
Hiroshi Ichikawa <http://gimite.net/>:
Except below
NISHI Takao <zophos@koka-in.org> (Rica):
deborah/rica_gimite.rb
tateisu@juggler.jp (QuickIRC2):
www/app/views/home/client.html.erb
www/public/QI2Flash.swf
www/public/qi2.css
www/public/i/*
www/public/j/*
Sam Stephenson (prototype.js):
www/public/javascripts/prototype-1.6.0.3.js
John Resig (jQuery):
www/public/javascripts/jquery.js
39 changes: 30 additions & 9 deletions www/app/controllers/channel.rb
Expand Up @@ -4,6 +4,7 @@ def index(channel)
@channel = CGI.unescape(channel)
@title = "\##{@channel} - irc.gimite.net"
@client_url = "/client?utf8=" + CGI.escape("\##{@channel}")
@recent_url = "/channel/%s/recent" % CGI.escape(@channel)
date_strs = Dir[channel_dir(@channel) + "/*.txt"].
map(){ |s| s.slice(/(\d+)\.txt/, 1) }.
sort().reverse()
Expand All @@ -17,32 +18,52 @@ def index(channel)
render()
end

def log(channel, date)
def archive(channel, date)
@channel = CGI.unescape(channel)
@date_str = CGI.unescape(date)
@date = str_to_date(@date_str)
@date = str_to_date(CGI.unescape(date))
@prev_date = @date - 1
@prev_date_url = log_url(@channel, @prev_date)
@prev_date_url = archive_url(@channel, @prev_date)
@next_date = @date + 1
@next_date_url = @next_date > Date.today ? nil : log_url(@channel, @next_date)
@next_date_url = @next_date > Date.today ? nil : archive_url(@channel, @next_date)
@title = "%s - \#%s - irc.gimite.net" % [@date.strftime("%Y/%m/%d"), @channel]
@channel_url = "/channel/" + CGI.escape(@channel)
log_path = "%s/%s.txt" % [channel_dir(@channel), @date_str]
path = archive_path(@channel, @date)
@log = []
if File.exist?(log_path)
File.foreach(log_path) do |line|
if File.exist?(path)
File.foreach(path) do |line|
@log.push(IRCMessage.new(@channel, line))
end
end
render()
end

def recent(channel)
@channel = CGI.unescape(channel)
path = archive_path(@channel, Date.today)
if File.exist?(path)
@log =
File.readlines(path).
map(){ |s| IRCMessage.new(@channel, s) }.
select(){ |m| m.body }
else
@log = []
end
max_log = 10
pos = [0, @log.size - max_log].max
@log = (0...max_log).map(){ |i| @log[pos + i] }
render(:recent, :layout => false)
end

private

def log_url(channel, date)
def archive_url(channel, date)
"/channel/%s/archive/%s" % [CGI.escape(channel), date_to_str(date)]
end

def archive_path(channel, date)
return "%s/%s.txt" % [channel_dir(channel), date_to_str(date)]
end

def channel_dir(channel)
return "../deborah/gimite.net/log/%s" % CGI.escape("\##{@channel}")
end
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions www/app/views/channel/index.html.erb
Expand Up @@ -6,6 +6,12 @@

<p>LimeChatなどのIRCクライアントを使う場合は、ホスト名 irc.gimite.net 、ポート番号 6667 、<b>文字コード UTF-8</b> で接続して、チャンネル #<%=h @channel %> に入ってください。</p>

<h2>最近の会話</h2>

<p id="recent"><br><br><br><br><br><br><br><br><br><br></p>

<p>※20秒ごとに更新</p>

<h2>過去ログ</h2>

<p>
Expand All @@ -19,3 +25,20 @@
または、LimeChatなどのIRCクライアントを使って RDeborah をinviteしてください。
<% end %>
</p>

<script type="text/javascript">

function updateRecent() {
var url = "<%=h @recent_url %>?nocache=" + new Date().getTime();
new Ajax.Updater("recent", url, {
method: "get",
onFailure: function(req) {
if (window.console) console.error(req);
}
});
}

setInterval(updateRecent, 20000);
updateRecent();

</script>
8 changes: 8 additions & 0 deletions www/app/views/channel/recent.html.erb
@@ -0,0 +1,8 @@
<% for message in @log %>
<% if message %>
<span class="time"><%=h message.time_str %></span>
<span class="from"><%=h message.from_str %></span>
<span class="<%=h message.body_class %>"><%=h message.body %></span>
<% end %>
<br>
<% end %>
1 change: 1 addition & 0 deletions www/app/views/layout/application.html.erb
Expand Up @@ -4,6 +4,7 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><%=h @title %></title>
<link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" src="/javascripts/prototype-1.6.0.3.js"></script>
</head>
<body>
<%#= message[:notice] %>
Expand Down
4 changes: 2 additions & 2 deletions www/config/environments/development.rb
Expand Up @@ -9,7 +9,7 @@
c[:log_level] = :debug

c[:log_stream] = STDOUT
#c[:log_file] = nil
c[:log_file] = nil
# Or redirect logging into a file:
c[:log_file] = Merb.root / "log" / "development.log"
#c[:log_file] = Merb.root / "log" / "development.log"
}
2 changes: 1 addition & 1 deletion www/config/environments/production.rb
Expand Up @@ -2,7 +2,7 @@
Merb::Config.use { |c|
c[:exception_details] = false
c[:reload_classes] = false
c[:log_level] = :error
c[:log_level] = :debug

c[:log_file] = Merb.root / "log" / "production.log"
# or redirect logger using IO handle
Expand Down
3 changes: 2 additions & 1 deletion www/config/router.rb
Expand Up @@ -36,7 +36,8 @@
match('/').to(:controller => 'home', :action =>'index')
match('/client').to(:controller => 'home', :action =>'client')
match('/channel/:channel').to(:controller => 'channel', :action =>'index')
match('/channel/:channel/archive/:date').to(:controller => 'channel', :action =>'log')
match('/channel/:channel/archive/:date').to(:controller => 'channel', :action =>'archive')
match('/channel/:channel/recent').to(:controller => 'channel', :action =>'recent')

# This is the default route for /:controller/:action/:id
# This is fine for most cases. If you're heavily using resource-based
Expand Down

0 comments on commit 1c96464

Please sign in to comment.