Simplify the way the embed view is created (#1590)
* Add coverage for embedded status view * Refactor embed view to eliminate @external_links variable
This commit is contained in:
parent
b352a8e5d4
commit
dd1ae3b109
5 changed files with 25 additions and 7 deletions
|
@ -27,8 +27,6 @@ class StreamEntriesController < ApplicationController
|
||||||
|
|
||||||
def embed
|
def embed
|
||||||
response.headers['X-Frame-Options'] = 'ALLOWALL'
|
response.headers['X-Frame-Options'] = 'ALLOWALL'
|
||||||
@external_links = true
|
|
||||||
|
|
||||||
return gone if @stream_entry.activity.nil?
|
return gone if @stream_entry.activity.nil?
|
||||||
|
|
||||||
render layout: 'embedded'
|
render layout: 'embedded'
|
||||||
|
|
|
@ -5,8 +5,12 @@ module StreamEntriesHelper
|
||||||
account.display_name.blank? ? account.username : account.display_name
|
account.display_name.blank? ? account.username : account.display_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stream_link_target
|
||||||
|
embedded_view? ? '_blank' : nil
|
||||||
|
end
|
||||||
|
|
||||||
def acct(account)
|
def acct(account)
|
||||||
"@#{account.acct}#{@external_links && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
|
"@#{account.acct}#{embedded_view? && account.local? ? "@#{Rails.configuration.x.local_domain}" : ''}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def entry_classes(status, is_predecessor, is_successor, include_threads)
|
def entry_classes(status, is_predecessor, is_successor, include_threads)
|
||||||
|
@ -30,4 +34,10 @@ module StreamEntriesHelper
|
||||||
|
|
||||||
rtl_size / ltr_size > 0.3
|
rtl_size / ltr_size > 0.3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def embedded_view?
|
||||||
|
params[:controller] == 'stream_entries' && params[:action] == 'embed'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.detailed-status.light
|
.detailed-status.light
|
||||||
= link_to TagManager.instance.url_for(status.account), class: 'detailed-status__display-name p-author h-card', target: @external_links ? '_blank' : nil, rel: 'noopener' do
|
= link_to TagManager.instance.url_for(status.account), class: 'detailed-status__display-name p-author h-card', target: stream_link_target, rel: 'noopener' do
|
||||||
%div
|
%div
|
||||||
%div.avatar
|
%div.avatar
|
||||||
= image_tag status.account.avatar.url(:original), width: 48, height: 48, alt: '', class: 'u-photo'
|
= image_tag status.account.avatar.url(:original), width: 48, height: 48, alt: '', class: 'u-photo'
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
%div.detailed-status__meta
|
%div.detailed-status__meta
|
||||||
%data.dt-published{ value: status.created_at.to_time.iso8601 }
|
%data.dt-published{ value: status.created_at.to_time.iso8601 }
|
||||||
= link_to TagManager.instance.url_for(status), class: 'detailed-status__datetime u-url u-uid', target: @external_links ? '_blank' : nil, rel: 'noopener' do
|
= link_to TagManager.instance.url_for(status), class: 'detailed-status__datetime u-url u-uid', target: stream_link_target, rel: 'noopener' do
|
||||||
%span= l(status.created_at)
|
%span= l(status.created_at)
|
||||||
·
|
·
|
||||||
- if status.application
|
- if status.application
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
.status.light
|
.status.light
|
||||||
.status__header
|
.status__header
|
||||||
.status__meta
|
.status__meta
|
||||||
= link_to time_ago_in_words(status.created_at), TagManager.instance.url_for(status), class: 'status__relative-time u-url u-uid', title: l(status.created_at), target: @external_links ? '_blank' : nil, rel: 'noopener'
|
= link_to time_ago_in_words(status.created_at), TagManager.instance.url_for(status), class: 'status__relative-time u-url u-uid', title: l(status.created_at), target: stream_link_target, rel: 'noopener'
|
||||||
%data.dt-published{ value: status.created_at.to_time.iso8601 }
|
%data.dt-published{ value: status.created_at.to_time.iso8601 }
|
||||||
|
|
||||||
= link_to TagManager.instance.url_for(status.account), class: 'status__display-name p-author h-card', target: @external_links ? '_blank' : nil, rel: 'noopener' do
|
= link_to TagManager.instance.url_for(status.account), class: 'status__display-name p-author h-card', target: stream_link_target, rel: 'noopener' do
|
||||||
.status__avatar
|
.status__avatar
|
||||||
%div
|
%div
|
||||||
= image_tag status.account.avatar(:original), width: 48, height: 48, alt: '', class: 'u-photo'
|
= image_tag status.account.avatar(:original), width: 48, height: 48, alt: '', class: 'u-photo'
|
||||||
|
|
|
@ -17,4 +17,14 @@ RSpec.describe StreamEntriesController, type: :controller do
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'GET #embed' do
|
||||||
|
it 'returns embedded view of status' do
|
||||||
|
get :embed, params: { account_username: alice.username, id: status.stream_entry.id }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(response.headers['X-Frame-Options']).to eq 'ALLOWALL'
|
||||||
|
expect(response).to render_template(layout: 'embedded')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue