diff app/helpers/application_helper.rb @ 98:c5c095f6981e

Expand the urls
author nanaya <me@myconan.net>
date Sat, 17 Sep 2016 13:41:05 +0900
parents 0c8a8b390145
children 1251b3d6ec5d
line wrap: on
line diff
--- 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