Files
grecia/app/components/shared/banner_component.rb
Javi Martín 0dec47c055 Use just the banner title as the banner link text
We were using an <a> tag wrapping the whole content of the banner in
order to make the whole banner clickable. However, that made the text of
the link less concise, affecting people using screen readers. So,
instead, we're using the `card` mixin, which we introduced in commit
f285dfcba.

We're making this change now because the HTML5 Sanitizer that we're
about to enable in the next commit was handling the whitespace inside
the banner differently, causing one test to fail, and we didn't find a
different way to fix it.
2025-05-20 15:38:52 +02:00

27 lines
706 B
Ruby

class Shared::BannerComponent < ApplicationComponent
attr_reader :banner_or_section
def initialize(banner_or_section)
@banner_or_section = banner_or_section
end
def banner
@banner ||= if banner_or_section.respond_to?(:sections)
banner_or_section
else
Banner.in_section(banner_or_section).with_active.sample
end
end
def render?
banner && (banner.title.present? || banner.description.present?)
end
private
def banner_content
tag.h2(link_to(banner.title, banner.target_url), style: "color:#{banner.font_color}") +
tag.h3(banner.description, style: "color:#{banner.font_color}")
end
end