changeset 98:c5c095f6981e

Expand the urls
author nanaya <me@myconan.net>
date Sat, 17 Sep 2016 13:41:05 +0900
parents ff5557f9902c
children 56fd4829e599
files Gemfile Gemfile.lock app/helpers/application_helper.rb app/views/tweets/_tweet.html.erb
diffstat 4 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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"
--- 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
--- 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
--- 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%>
   <p>
-    <%= auto_link(tweet.text).gsub("\n", "<br>").html_safe %>
+    <%= auto_link(expand_url(tweet.text)).gsub("\n", "<br>").html_safe %>
   </p>
 
   <p>