blob: f54a537ca46faf99f6c0904fda5552a02a50278c (
plain)
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
39
40
41
42
43
44
45
46
47
48
49
|
module ApplicationHelper
def logged_in?; session[:user_id] && session[:account] end
def include_user?; !!params[:include_user] end
def format_time(dt)
dt.to_time.localtime("+09:00").strftime("%Y-%m-%d %H:%M:%S")
end
def format_days_ago(dt)
"#{(DateTime.now.utc - dt.to_datetime).to_i}d ago"
end
def format_tweet_text(text)
ret = text.gsub(/<([a-z]+?):(.+?)(?::(.+?))?>/) do
case $1
when "mention"
screen_name = CGI.unescape($2)
link_to("@#{screen_name}", "/#{screen_name}")
when "url"
display = CGI.unescape($3)
expanded_url = CGI.unescape($2)
link_to(display, expanded_url)
when "hashtag"
hashtag = CGI.unescape($2)
link_to("##{hashtag}", "https://twitter.com/search?q=#{CGI.escape("##{hashtag}")}")
when "symbol"
symbol = CGI.unescape($2)
link_to("##{symbol}", "https://twitter.com/search?q=#{CGI.escape("$#{symbol}")}")
else
$&
end
end
ret.gsub!(/\r\n|\r|\n/, "<br />")
return ret
end
alias format_source_text format_tweet_text
def twitter_status_url(tweet)
"https://twitter.com/#{tweet.user.screen_name}/status/#{tweet.id}"
end
def twitter_user_url(screen_name)
"https://twitter.com/#{screen_name}"
end
# utf8, form
def utf8_enforcer_tag; raw "" end
end
|