annotate app/helpers/application_helper.rb @ 170:05ce14af003a

port can't be part of the id
author nanaya <me@nanaya.pro>
date Wed, 08 Aug 2018 20:19:41 +0900
parents 950849c40d42
children 90db232f39e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a1c9fadc0904 Initial.
edogawaconan <me@myconan.net>
parents:
diff changeset
1 module ApplicationHelper
150
950849c40d42 Update all the things, including rails 5.2
nanaya <me@nanaya.pro>
parents: 103
diff changeset
2 include Twitter::TwitterText::Autolink
80
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
3
82
f91e2d00f03f Reduce title length limit
nanaya <me@myconan.net>
parents: 80
diff changeset
4 def ellipsize(text, limit = 30)
80
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
5 if text.length <= limit
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
6 text
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
7 else
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
8 "#{text.first(limit)}..."
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
9 end
448a368f7344 More useful title?
nanaya <me@myconan.net>
parents: 15
diff changeset
10 end
94
0c8a8b390145 Now with epic caching
nanaya <me@myconan.net>
parents: 82
diff changeset
11
0c8a8b390145 Now with epic caching
nanaya <me@myconan.net>
parents: 82
diff changeset
12 def atom_id(id)
170
05ce14af003a port can't be part of the id
nanaya <me@nanaya.pro>
parents: 150
diff changeset
13 "tag:#{request.host},2005:#{id}"
94
0c8a8b390145 Now with epic caching
nanaya <me@myconan.net>
parents: 82
diff changeset
14 end
98
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
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
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
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
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
30 end
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
31 end
0
a1c9fadc0904 Initial.
edogawaconan <me@myconan.net>
parents:
diff changeset
32 end