view app/helpers/application_helper.rb @ 231:01f3a7e073c3

Remove unsupported namespace syntax Leftover from redis-rails.
author nanaya <me@nanaya.net>
date Mon, 16 Jan 2023 16:23:29 +0900
parents 12287b32fbda
children 7a773720d81f
line wrap: on
line source

module ApplicationHelper
  include Twitter::TwitterText::Autolink

  def atom_id(id)
    "tag:rsstweet@nanaya.pro,2014:#{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

  def status_url(tweet)
    status_url_base tweet.user.screen_name, tweet.id
  end

  def status_url_base(screen_name, tweet_id)
    "https://twitter.com/#{screen_name.presence || '_'}/status/#{tweet_id}"
  end
end