mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
move icon helpers to InstanceHelper
This commit is contained in:
parent
752fe1731e
commit
8de13f1413
6 changed files with 46 additions and 47 deletions
|
@ -244,22 +244,6 @@ module ApplicationHelper
|
||||||
full_asset_url(instance_presenter.mascot&.file&.url || frontend_asset_path('images/elephant_ui_plane.svg'))
|
full_asset_url(instance_presenter.mascot&.file&.url || frontend_asset_path('images/elephant_ui_plane.svg'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_presenter
|
|
||||||
@instance_presenter ||= InstancePresenter.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def favicon_path(size = '48')
|
|
||||||
instance_presenter.favicon&.file&.url(size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def app_icon_path(size = '48')
|
|
||||||
instance_presenter.app_icon&.file&.url(size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def use_mask_icon?
|
|
||||||
instance_presenter.app_icon.blank?
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def storage_host_var
|
def storage_host_var
|
||||||
|
|
|
@ -13,6 +13,22 @@ module InstanceHelper
|
||||||
safe_join([description_prefix(invite), I18n.t('auth.description.suffix')], ' ')
|
safe_join([description_prefix(invite), I18n.t('auth.description.suffix')], ' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def instance_presenter
|
||||||
|
@instance_presenter ||= InstancePresenter.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def favicon_path(size = '48')
|
||||||
|
instance_presenter.favicon&.file&.url(size)
|
||||||
|
end
|
||||||
|
|
||||||
|
def app_icon_path(size = '48')
|
||||||
|
instance_presenter.app_icon&.file&.url(size)
|
||||||
|
end
|
||||||
|
|
||||||
|
def use_mask_icon?
|
||||||
|
instance_presenter.app_icon.blank?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def description_prefix(invite)
|
def description_prefix(invite)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ManifestSerializer < ActiveModel::Serializer
|
class ManifestSerializer < ActiveModel::Serializer
|
||||||
include ApplicationHelper
|
include InstanceHelper
|
||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
include InstanceHelper
|
include InstanceHelper
|
||||||
include ApplicationHelper
|
|
||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
|
|
||||||
attributes :domain, :title, :version, :source_url, :description,
|
attributes :domain, :title, :version, :source_url, :description,
|
||||||
|
|
|
@ -285,33 +285,4 @@ describe ApplicationHelper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'favicon' do
|
|
||||||
context 'when an icon exists' do
|
|
||||||
let!(:favicon) { Fabricate(:site_upload, var: 'favicon') }
|
|
||||||
let!(:app_icon) { Fabricate(:site_upload, var: 'app_icon') }
|
|
||||||
|
|
||||||
it 'returns the URL of the icon' do
|
|
||||||
expect(helper.favicon_path).to eq(favicon.file.url('48'))
|
|
||||||
expect(helper.app_icon_path).to eq(app_icon.file.url('48'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns the URL of the icon with size parameter' do
|
|
||||||
expect(helper.favicon_path(16)).to eq(favicon.file.url('16'))
|
|
||||||
expect(helper.app_icon_path(16)).to eq(app_icon.file.url('16'))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when an icon does not exist' do
|
|
||||||
it 'returns nil' do
|
|
||||||
expect(helper.favicon_path).to be_nil
|
|
||||||
expect(helper.app_icon_path).to be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns nil with size parameter' do
|
|
||||||
expect(helper.favicon_path(16)).to be_nil
|
|
||||||
expect(helper.app_icon_path(16)).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,4 +24,33 @@ describe InstanceHelper do
|
||||||
expect(helper.site_hostname).to eq 'example.com'
|
expect(helper.site_hostname).to eq 'example.com'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'favicon' do
|
||||||
|
context 'when an icon exists' do
|
||||||
|
let!(:favicon) { Fabricate(:site_upload, var: 'favicon') }
|
||||||
|
let!(:app_icon) { Fabricate(:site_upload, var: 'app_icon') }
|
||||||
|
|
||||||
|
it 'returns the URL of the icon' do
|
||||||
|
expect(helper.favicon_path).to eq(favicon.file.url('48'))
|
||||||
|
expect(helper.app_icon_path).to eq(app_icon.file.url('48'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns the URL of the icon with size parameter' do
|
||||||
|
expect(helper.favicon_path(16)).to eq(favicon.file.url('16'))
|
||||||
|
expect(helper.app_icon_path(16)).to eq(app_icon.file.url('16'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when an icon does not exist' do
|
||||||
|
it 'returns nil' do
|
||||||
|
expect(helper.favicon_path).to be_nil
|
||||||
|
expect(helper.app_icon_path).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil with size parameter' do
|
||||||
|
expect(helper.favicon_path(16)).to be_nil
|
||||||
|
expect(helper.app_icon_path(16)).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue