mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-21 12:05:07 +01:00
Refactor active_nav_class for use with multiple paths (#8757)
This commit is contained in:
parent
d0d65b5a28
commit
c39183cc62
@ -7,8 +7,8 @@ module ApplicationHelper
|
|||||||
follow
|
follow
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
def active_nav_class(path)
|
def active_nav_class(*paths)
|
||||||
current_page?(path) ? 'active' : ''
|
paths.any? { |path| current_page?(path) } ? 'active' : ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_link_to(label, path, **options)
|
def active_link_to(label, path, **options)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
= fa_icon('lock') if account.locked?
|
= fa_icon('lock') if account.locked?
|
||||||
.public-account-header__tabs__tabs
|
.public-account-header__tabs__tabs
|
||||||
.details-counters
|
.details-counters
|
||||||
.counter{ class: active_nav_class(short_account_url(account)) + active_nav_class(short_account_with_replies_url(account)) + active_nav_class(short_account_media_url(account)) }
|
.counter{ class: active_nav_class(short_account_url(account), short_account_with_replies_url(account), short_account_media_url(account)) }
|
||||||
= link_to short_account_url(account), class: 'u-url u-uid', title: number_with_delimiter(account.statuses_count) do
|
= link_to short_account_url(account), class: 'u-url u-uid', title: number_with_delimiter(account.statuses_count) do
|
||||||
%span.counter-number= number_to_human account.statuses_count, strip_insignificant_zeros: true
|
%span.counter-number= number_to_human account.statuses_count, strip_insignificant_zeros: true
|
||||||
%span.counter-label= t('accounts.posts', count: account.statuses_count)
|
%span.counter-label= t('accounts.posts', count: account.statuses_count)
|
||||||
|
@ -9,6 +9,14 @@ describe ApplicationHelper do
|
|||||||
expect(result).to eq "active"
|
expect(result).to eq "active"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns active when on a current page' do
|
||||||
|
allow(helper).to receive(:current_page?).with('/foo').and_return(false)
|
||||||
|
allow(helper).to receive(:current_page?).with('/test').and_return(true)
|
||||||
|
|
||||||
|
result = helper.active_nav_class('/foo', '/test')
|
||||||
|
expect(result).to eq "active"
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns empty string when not on current page' do
|
it 'returns empty string when not on current page' do
|
||||||
allow(helper).to receive(:current_page?).and_return(false)
|
allow(helper).to receive(:current_page?).and_return(false)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user