view 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
line wrap: on
line source

module ApplicationHelper
  include Twitter::Autolink

  def ellipsize(text, limit = 30)
    if text.length <= limit
      text
    else
      "#{text.first(limit)}..."
    end
  end

  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