annotate app/helpers/application_helper.rb @ 102:f4805ac41656

Fix title
author nanaya <me@myconan.net>
date Fri, 23 Sep 2016 23:10:54 +0900
parents c5c095f6981e
children 1251b3d6ec5d
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
15
207917e41964 Add tweets~
edogawaconan <me@myconan.net>
parents: 0
diff changeset
2 include Twitter::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)
0c8a8b390145 Now with epic caching
nanaya <me@myconan.net>
parents: 82
diff changeset
13 "tag:#{request.host_with_port},2005:#{id}"
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
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
16 def expand_url(text)
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
17 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
18 Rails.cache.fetch url, :expires_in => 1.hour do
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
19 " #{Embiggen::URI(url).expand} "
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
20 end
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
21 end
c5c095f6981e Expand the urls
nanaya <me@myconan.net>
parents: 94
diff changeset
22 end
0
a1c9fadc0904 Initial.
edogawaconan <me@myconan.net>
parents:
diff changeset
23 end