Drop unused ability to filter social sharing sites
This commit is contained in:
parent
e1a1bebd95
commit
dee02bccd3
2 changed files with 8 additions and 41 deletions
|
@ -13,18 +13,10 @@ module SocialShareButtonHelper
|
|||
|
||||
# Generates a set of social share buttons based on the specified options.
|
||||
def social_share_buttons(opts = {})
|
||||
sites = opts.fetch(:allow_sites, [])
|
||||
valid_sites, invalid_sites = filter_allowed_sites(sites)
|
||||
|
||||
# Log invalid sites
|
||||
invalid_sites.each do |invalid_site|
|
||||
Rails.logger.error("Invalid site or icon not configured: #{invalid_site}")
|
||||
end
|
||||
|
||||
tag.div(
|
||||
:class => "social-share-button d-flex gap-1 align-items-end flex-wrap mb-3"
|
||||
) do
|
||||
valid_sites.map do |site|
|
||||
SOCIAL_SHARE_CONFIG.map do |site, icon|
|
||||
link_options = {
|
||||
:rel => ["nofollow", opts[:rel]].compact,
|
||||
:class => "ssb-icon rounded-circle",
|
||||
|
@ -33,7 +25,7 @@ module SocialShareButtonHelper
|
|||
}
|
||||
|
||||
link_to generate_share_url(site, opts), link_options do
|
||||
image_tag(icon_path(site), :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
|
||||
image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28)
|
||||
end
|
||||
end.join.html_safe
|
||||
end
|
||||
|
@ -41,20 +33,6 @@ module SocialShareButtonHelper
|
|||
|
||||
private
|
||||
|
||||
def filter_allowed_sites(sites)
|
||||
valid_sites = sites.empty? ? SOCIAL_SHARE_CONFIG.keys : sites.select { |site| valid_site?(site) }
|
||||
invalid_sites = sites - valid_sites
|
||||
[valid_sites, invalid_sites]
|
||||
end
|
||||
|
||||
def icon_path(site)
|
||||
SOCIAL_SHARE_CONFIG[site.to_sym] || ""
|
||||
end
|
||||
|
||||
def valid_site?(site)
|
||||
SOCIAL_SHARE_CONFIG.key?(site.to_sym)
|
||||
end
|
||||
|
||||
def generate_share_url(site, params)
|
||||
site = site.to_sym
|
||||
case site
|
||||
|
|
|
@ -5,7 +5,6 @@ class SocialShareButtonHelperTest < ActionView::TestCase
|
|||
|
||||
def setup
|
||||
@options = {
|
||||
:allow_sites => %w[x facebook linkedin],
|
||||
:title => "Test Title",
|
||||
:url => "https://example.com",
|
||||
:desc => "Test Description",
|
||||
|
@ -13,24 +12,14 @@ class SocialShareButtonHelperTest < ActionView::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_social_share_buttons_with_valid_sites
|
||||
def test_social_share_buttons
|
||||
result = social_share_buttons(@options)
|
||||
assert_includes result, "x"
|
||||
assert_includes result, "email"
|
||||
assert_includes result, "bluesky"
|
||||
assert_includes result, "facebook"
|
||||
assert_includes result, "linkedin"
|
||||
end
|
||||
|
||||
def test_render_social_share_buttons_with_invalid_site
|
||||
@options[:allow_sites] << "invalid_site"
|
||||
result = social_share_buttons(@options)
|
||||
assert_not_includes result, "invalid_site"
|
||||
end
|
||||
|
||||
def test_social_share_buttons_with_no_sites
|
||||
@options[:allow_sites] = []
|
||||
result = social_share_buttons(@options)
|
||||
SocialShareButtonHelper::SOCIAL_SHARE_CONFIG.each_key do |site|
|
||||
assert_includes result, site.to_s # Convert symbol to string
|
||||
end
|
||||
assert_includes result, "mastodon"
|
||||
assert_includes result, "telegram"
|
||||
assert_includes result, "x"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue