view app/views/tweets/_tweet.html.erb @ 172:df4be896ab8b

Improved escaping and truncating
author nanaya <me@nanaya.pro>
date Wed, 08 Aug 2018 20:37:29 +0900
parents 04ca6c4f11d0
children d35dbc09bd83
line wrap: on
line source

<% if tweet.retweeted_status.present? %>
  <p>
    <em>Retweeted:</em>
  </p>

  <%= render "tweet", :tweet => tweet.retweeted_status, :with_time => true %>
<% else%>
  <% if defined?(with_time) && with_time %>
    <p>
      <small>Originally tweeted at <%= tweet.created_at.to_s :rfc822 %></small>
    </p>
  <% end %>

  <p>
    <%# FIXME: Twitter gem doesn't support extended mode when writing this %>
    <%= auto_link(html_escape(expand_url(
          tweet.unescaped_text,
          tweet.attrs[:entities][:urls],
          tweet.attrs[:entities][:media]
        )))
        .gsub("\n", "<br />")
        .html_safe
      %>
  </p>

  <p>
    <%= link_to "https://twitter.com/#{tweet.user.screen_name}" do %>
      <%= image_tag tweet.user.profile_image_url_https.to_s, :alt => "profile image for #{tweet.user.name.printable}" %>
      <%= tweet.user.name.printable -%>
    <% end %>
  </p>

  <p>
    <% tweet.media.each_with_index do |media, i| %>
      <% if media.is_a? Twitter::Media::Photo %>
        <%= link_to "#{media.media_url_https}:orig" do %>
          <%= image_tag "#{media.media_url_https}:small", :alt => "attachment #{i + 1}" -%>
        <% end %>
      <% elsif media.is_a? Twitter::Media::Video %>
        <%= video_tag media.video_info.variants.map(&:url), width: '100%', controls: true %>
      <% end %>
    <% end %>
  </p>

  <% if tweet.quoted_status.present? %>
    <blockquote>
      <%= render "tweet", :tweet => tweet.quoted_status, :with_time => true %>
    </blockquote>
  <% end %>
<% end %>