view app/helpers/application_helper.rb @ 171:90db232f39e7

Remove unused variable
author nanaya <me@nanaya.pro>
date Wed, 08 Aug 2018 20:19:51 +0900
parents 05ce14af003a
children df4be896ab8b
line wrap: on
line source

module ApplicationHelper
  include Twitter::TwitterText::Autolink

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

  def atom_id(id)
    "tag:#{request.host},2005:#{id}"
  end

  def expand_url(text, *urls)
    urls.flatten!

    urls = urls.reduce({}) do |result, u|
      if u.try(:[], :url)
        result[u[:url]] = u[:expanded_url]
      end

      result
    end

    text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url|
      urls[url] || url
    end
  end
end