Skip to content

Commit

Permalink
Moved talk_with helper to partial
Browse files Browse the repository at this point in the history
  • Loading branch information
alfanick committed Dec 29, 2008
1 parent f6d3702 commit 79ef1fc
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/controllers/channels.rb
Expand Up @@ -12,8 +12,8 @@ def show(server, name)

raise NotFound unless @channel

@first_date = Channel.messages.first.created_at
@last_date = Channel.messages.last.created_at
@first_date = Message.first(:channel_id => @channel.id).created_at
@last_date = Message.first(:channel_id => @channel.id, :order => [:created_at.desc]).created_at

display @channel
end
Expand Down
29 changes: 0 additions & 29 deletions app/helpers/messages_helper.rb
Expand Up @@ -37,35 +37,6 @@ def raw_message(message)
"#{time} *** #{message.content}\n"
end
end

def talk_with (message, n=5, rev=false)
Merb::Cache[:default].fetch("#{message.id}_#{n}_#{rev}_talk", :interval => Time.now.to_i / Merb::Config[:cache]["intervals"]["talk_with"]) do
str = '<div class="irc talk">'
ur = link_to(message.channel.name, url(:show_channel, message.channel.server_host, message.channel.name[1..-1]))
sur = link_to(message.channel.server.name, url(:channels, message.channel.server_host, 1))
str << "<h2>#{ur}</h2> <em class=\"server\">#{sur}</em> "
ms = message.with_surroundings(n, false)
ms.reverse! if rev
str << "<em class=\"date\">#{ms.first.created_at}</em><br/>"
str << read_more(message, false)
str << '<ol>'
ms.each do |msg|
c = msg.class.name.downcase
cid = c + "_#{msg.id}"
if msg == message
str << "<li class=\"result #{c}\" id=\"#{cid}\"><strong>" << format_message(msg) << "</strong></li>\n"
else
str << "<li class=\"#{c}\" id=\"#{cid}\">" << format_message(msg) << "</li>\n"
end
end
str << '</ol>'
str << "<em class=\"date\">#{ms.last.created_at}</em><br/>"
str << read_more(message)
str << "</div>\n"

str
end
end

def read_more (message, down=true)
b = 10
Expand Down
2 changes: 1 addition & 1 deletion app/views/channels/show.html.haml
Expand Up @@ -5,7 +5,7 @@

%h3 Latest messages
#results.irc
= talk_with(@channel.messages.first(:event => :message, :order => [:created_at.desc]), 10, true)
= partial 'messages/talk', :message => @channel.messages.first(:event => :message, :order => [:created_at.desc]), :n => 10, :reversed => true

%h3 Archive
%ol.archive
Expand Down
2 changes: 1 addition & 1 deletion app/views/guys/show.html.haml
Expand Up @@ -7,4 +7,4 @@
%h3 Latest messages
#results.irc
- @guy.messages.all(:event => :message, :limit => 5, :order => [:created_at.desc]).each do |message|
= talk_with(message, 1)
= partial 'messages/talk', :message => message, :n => 1, :reversed => false
24 changes: 24 additions & 0 deletions app/views/messages/_talk.html.haml
@@ -0,0 +1,24 @@
.irc.talk
%h2= link_to(message.channel.name, url(:show_channel, message.channel.server_host, message.channel.name[1..-1]))
%em.server= link_to(message.channel.server.name, url(:channels, message.channel.server_host, 1))

- surroundings = message.with_surroundings(n, false)
- surroundings.reverse! if reversed

%em.date= surroundings.first.created_at
%br/

= read_more(message, false)

%ol
- surroundings.each do |msg|
- if msg == message
%li[msg]{ :class => :result }
%strong= format_message msg
- else
%li[msg]= format_message msg

%em.date= surroundings.last.created_at
%br/

= read_more(message, true)
2 changes: 1 addition & 1 deletion app/views/messages/index.html.haml
@@ -1,7 +1,7 @@
#results.irc
- if not @messages.empty?
- for message in @messages
= talk_with(message, 3)
= partial 'messages/talk', :message => message, :n => 3, :reversed => false
- else
- if params.include? :page and params[:page].to_i > 1
%p.result.error= "No more search results... Back to %s." % link_to('previous page', url(:search, :query => params[:query], :page => params[:page].to_i-1))
Expand Down
3 changes: 1 addition & 2 deletions app/views/messages/show.html.haml
Expand Up @@ -2,5 +2,4 @@
#results.irc
- c = params['count'].to_i
- b = params['bcount'].to_i
= talk_with(@message, -b..c)

= partial 'messages/talk', :message => @message, :n => -b..c, :reversed => false

0 comments on commit 79ef1fc

Please sign in to comment.