comparison app/helpers/application_helper.rb @ 103:1251b3d6ec5d

Use included url data instead of expanding using embiggen
author nanaya <me@myconan.net>
date Mon, 26 Sep 2016 02:39:40 +0900
parents c5c095f6981e
children 950849c40d42
comparison
equal deleted inserted replaced
102:f4805ac41656 103:1251b3d6ec5d
11 11
12 def atom_id(id) 12 def atom_id(id)
13 "tag:#{request.host_with_port},2005:#{id}" 13 "tag:#{request.host_with_port},2005:#{id}"
14 end 14 end
15 15
16 def expand_url(text) 16 def expand_url(text, *urls)
17 urls.flatten!
18
19 urls = urls.reduce({}) do |result, u|
20 if u.try(:[], :url)
21 result[u[:url]] = u[:expanded_url]
22 @any = 1
23 end
24
25 result
26 end
27
17 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| 28 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
18 Rails.cache.fetch url, :expires_in => 1.hour do 29 urls[url] || url
19 " #{Embiggen::URI(url).expand} "
20 end
21 end 30 end
22 end 31 end
23 end 32 end