forked from zapnap/retweet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
application.rb
38 lines (32 loc) · 911 Bytes
/
application.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'rubygems'
require 'sinatra'
require 'environment'
configure do
set :views, "#{File.dirname(__FILE__)}/views"
end
error do
e = request.env['sinatra.error']
Kernel.puts e.backtrace.join("\n")
'Application error'
end
helpers do
def highlight(text)
SiteConfig.search_keywords.each do |keyword|
text = text.gsub(/(#{keyword})/i, '<span class="highlight">\1</span>')
end
activate_links(text)
end
def activate_links(text)
text.gsub(/((https?:\/\/|www\.)([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/, '<a href="\1">\1</a>'). \
gsub(/@(\w+)/, '<a href="http://twitter.com/\1">@\1</a>')
end
def profile_link(user_name)
"<a href=\"http://twitter.com/#{user_name}\">#{user_name}</a>"
end
end
# root page
get '/' do
@statuses = Status.random(SiteConfig.status_length,
:limit => SiteConfig.status_length * 3)
haml :main
end