Mercurial > rsstweet
annotate app/helpers/application_helper.rb @ 117:e3067b426b70
Improved style
author | nanaya <me@myconan.net> |
---|---|
date | Sun, 12 Feb 2017 17:20:58 +0900 |
parents | 1251b3d6ec5d |
children | 950849c40d42 |
rev | line source |
---|---|
0 | 1 module ApplicationHelper |
15 | 2 include Twitter::Autolink |
80 | 3 |
82 | 4 def ellipsize(text, limit = 30) |
80 | 5 if text.length <= limit |
6 text | |
7 else | |
8 "#{text.first(limit)}..." | |
9 end | |
10 end | |
94 | 11 |
12 def atom_id(id) | |
13 "tag:#{request.host_with_port},2005:#{id}" | |
14 end | |
98 | 15 |
103
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
16 def expand_url(text, *urls) |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
17 urls.flatten! |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
18 |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
19 urls = urls.reduce({}) do |result, u| |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
20 if u.try(:[], :url) |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
21 result[u[:url]] = u[:expanded_url] |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
22 @any = 1 |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
23 end |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
24 |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
25 result |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
26 end |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
27 |
98 | 28 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| |
103
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
29 urls[url] || url |
98 | 30 end |
31 end | |
0 | 32 end |