# HG changeset patch # User nanaya # Date 1474087265 -32400 # Node ID c5c095f6981ede77373020c3dce8cd816b2a47cc # Parent ff5557f9902cbd6aae0e6126f57c3f1ac697794f Expand the urls diff -r ff5557f9902c -r c5c095f6981e Gemfile --- a/Gemfile Thu Jul 28 07:08:52 2016 +0900 +++ b/Gemfile Sat Sep 17 13:41:05 2016 +0900 @@ -14,3 +14,5 @@ gem "puma", :require => false gem "unicorn", :require => false, :platforms => :ruby + +gem "embiggen" diff -r ff5557f9902c -r c5c095f6981e Gemfile.lock --- a/Gemfile.lock Thu Jul 28 07:08:52 2016 +0900 +++ b/Gemfile.lock Sat Sep 17 13:41:05 2016 +0900 @@ -27,6 +27,8 @@ dalli (2.7.6) domain_name (0.5.20160615) unf (>= 0.0.5, < 1.0.0) + embiggen (1.2.1) + addressable (~> 2.3) equalizer (0.0.10) erubis (2.7.0) faraday (0.9.2) @@ -118,6 +120,7 @@ actionpack (~> 5.0.0) actionview (~> 5.0.0) dalli + embiggen newrelic_rpm puma railties (~> 5.0.0) @@ -126,4 +129,4 @@ unicorn BUNDLED WITH - 1.11.2 + 1.12.5 diff -r ff5557f9902c -r c5c095f6981e app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb Thu Jul 28 07:08:52 2016 +0900 +++ b/app/helpers/application_helper.rb Sat Sep 17 13:41:05 2016 +0900 @@ -12,4 +12,12 @@ def atom_id(id) "tag:#{request.host_with_port},2005:#{id}" end + + def expand_url(text) + text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| + Rails.cache.fetch url, :expires_in => 1.hour do + " #{Embiggen::URI(url).expand} " + end + end + end end diff -r ff5557f9902c -r c5c095f6981e app/views/tweets/_tweet.html.erb --- a/app/views/tweets/_tweet.html.erb Thu Jul 28 07:08:52 2016 +0900 +++ b/app/views/tweets/_tweet.html.erb Sat Sep 17 13:41:05 2016 +0900 @@ -6,7 +6,7 @@ <%= render "tweet", :tweet => tweet.retweeted_status %> <% else%>

- <%= auto_link(tweet.text).gsub("\n", "
").html_safe %> + <%= auto_link(expand_url(tweet.text)).gsub("\n", "
").html_safe %>