Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some refactoring.

  • Loading branch information...
commit 7e06df6efe08dbbf32acf148eed77cd3a24bf76c 1 parent 11c6cb8
@whitequark authored
View
8 lib/irclogger/viewer.rb
@@ -40,7 +40,7 @@ class Viewer < Sinatra::Base
end
get '/:channel/search' do
- @channel = "##{params[:channel].gsub '.', '#'}"
+ @channel = parse_channel(params[:channel])
@limit = 300
if params[:q].length >= 3
@@ -58,7 +58,7 @@ class Viewer < Sinatra::Base
get '/:channel/stream', provides: 'text/event-stream' do
response['X-Accel-Buffering'] = 'no'
- channel = "##{params[:channel].gsub '.', '#'}"
+ channel = parse_channel(params[:channel])
last_message_id = env['HTTP_LAST_EVENT_ID'] || params['last_id']
last_messages = Message.recent_for_channel(channel, last_message_id.to_i)
@@ -90,7 +90,7 @@ class Viewer < Sinatra::Base
end
get '/:channel/:date?' do
- @channel = "##{params[:channel].gsub '.', '#'}"
+ @channel = parse_channel(params[:channel])
@date = Date.parse(params[:date]) rescue nil
if @date
@@ -103,7 +103,7 @@ class Viewer < Sinatra::Base
haml :channel
else
- redirect "/#{params[:channel]}/#{Time.now.gmtime.to_date}"
+ redirect channel_url(@channel, Time.now.gmtime.to_date)
end
end
end
View
12 lib/irclogger/viewer_helpers.rb
@@ -4,8 +4,12 @@ module IrcLogger
module ViewerHelpers
include Rack::Utils
- def channel(name)
- name[1..-1].gsub '#', '.'
+ def channel_url(channel, postfix=nil)
+ "/#{channel[1..-1].gsub('#', '.')}/#{postfix}"
+ end
+
+ def parse_channel(channel)
+ "##{channel.gsub('.', '#')}"
end
def nick_class(nick)
@@ -74,7 +78,7 @@ def calendar(channel, date=nil, links=true)
current = "current" if date && date.to_s == d
if Message.check_by_channel_and_date(channel, Date.parse(d))
- %Q{<a class="#{current}" href="/#{channel channel}/#{d}">#{$1}</a>}
+ %Q{<a class="#{current}" href="#{channel_url channel, d}">#{$1}</a>}
else
$1
end
@@ -88,7 +92,7 @@ def calendar(channel, date=nil, links=true)
if links
link_if = ->(date, text) do
if Message.check_by_channel_and_month(channel, date)
- %Q{<a href="/#{channel channel}/#{date}">#{text}</a>}
+ %Q{<a href="#{channel_url channel, date}">#{text}</a>}
else
text
end
View
2  views/_message.haml
@@ -4,7 +4,7 @@
- time = Time.at(message.timestamp).gmtime
- if dates
- %a.timeref{href: "/#{channel @channel}/#{time.to_date}##{message.id}"}
+ %a.timeref{href: channel_url(@channel, "#{time.to_date}##{message.id}")}
%time{timestamp: time.iso8601}><= time.strftime("%Y-%m-%d %H:%M")
- else
%a.timestamp{href: "##{message.id}"}
View
2  views/_messages.haml
@@ -1,4 +1,4 @@
-%div{:class => "log-messages with-panel"}
+%div{class: "log-messages with-panel"}
- if @topic
= haml :_message, locals: { message: @topic, dates: true }
View
12 views/channel.haml
@@ -1,19 +1,19 @@
%section#log{class: 'without-noise', data: { channel: @channel }}
%aside#log-panel
- %label{:for => 'filter'}
+ %label{for: 'filter'}
Filter:
%input#filter
- %span.clear-input#clear_filter{:style => 'display:none'}
+ %span.clear-input#clear_filter{style: 'display:none'}
- %label{:for => 'show_noise'}
+ %label{for: 'show_noise'}
Show join/leave messages:
- %input#show_noise{:type => 'checkbox'}
+ %input#show_noise{type: 'checkbox'}
- if @is_today
- last_id = @messages.last.id if @messages.any?
%a{href: '#', id: 'live_logging', style: 'display: none',
- data: { channel: channel(@channel),
+ data: { channel: channel_url(@channel),
lastId: last_id,
autostart: true }} Live updates
- = haml :_messages, locals: { :messages => @messages, :dates => false }
+ = haml :_messages, locals: { messages: @messages, dates: false }
View
34 views/layout.haml
@@ -9,18 +9,18 @@
= " — "
irc logs at whitequark.org
- %meta{:charset => "utf-8"}
- %link{:rel => "stylesheet", :href => "/style.css"}
- %link{:rel => "shortcut icon", :href => "/favicon.png"}
+ %meta{charset: "utf-8"}
+ %link{rel: "stylesheet", href: "/style.css"}
+ %link{rel: "shortcut icon", href: "/favicon.png"}
- if @channel
- %meta{:name => 'description', :content => "channel #{@channel} IRC chat logs"}
+ %meta{name: 'description', content: "channel #{@channel} IRC chat logs"}
- if @messages && @messages.empty?
- %meta{:name => 'robots', :content => 'noindex'}
+ %meta{name: 'robots', content: 'noindex'}
- %script{:src => "https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"}
- %script{:src => "/jquery.ba-hashchange.min.js"}
- %script{:src => "/application.js"}
+ %script{src: "https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"}
+ %script{src: "/jquery.ba-hashchange.min.js"}
+ %script{src: "/application.js"}
%body
%section#channels
@@ -30,20 +30,20 @@
- if @channel
%section#options
- %a{:href => '#', :id => 'clear_selection'}> Clear selection
- %form{:action => "/#{channel @channel}/search"}
- %input{:placeholder => 'Enter keywords', :id => 'search-box', :name => 'q', :value => params[:q]}
- %input{:type => 'submit', :value => 'Search'}
- %a{:href => '/help/search'}
+ %a{href: '#', id: 'clear_selection'}> Clear selection
+ %form{action: channel_url(@channel, 'search')}
+ %input{placeholder: 'Enter keywords', id: 'search-box', name: 'q', value: params[:q]}
+ %input{type: 'submit', value: 'Search'}
+ %a{href: '/help/search'}
?
%ul
- %li{:class => "#{"current" unless @channel}"}
- %a{:href => '/'} Console
+ %li{class: "#{"current" unless @channel}"}
+ %a{href: '/'} Console
- @channels.each do |channel|
- %li{:class => "#{"current" if channel == @channel}"}
- %a{:href => "/#{channel(channel)}/"}= channel
+ %li{class: "#{"current" if channel == @channel}"}
+ %a{href: channel_url(channel)}= channel
= yield
View
2  views/search.haml
@@ -11,7 +11,7 @@
- if page == (params[:page] || 1).to_i
%span.current= page
- else
- %a{:href => "/#{params[:channel]}/search?q=#{params[:q]}&page=#{page}"}= page
+ %a{href: channel_url(@channel, "search?q=#{params[:q]}&page=#{page}")}= page
- if params[:q].length < 3
Please sign in to comment.
Something went wrong with that request. Please try again.