view app/helpers/application_helper.rb @ 174:d35dbc09bd83

Less double escaping for actual content Ends up rather confusing.
author nanaya <me@nanaya.pro>
date Thu, 09 Aug 2018 19:31:22 +0900
parents df4be896ab8b
children 52252ae4b580
line wrap: on
line source

module ApplicationHelper
  include Twitter::TwitterText::Autolink

  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