diff --git a/app/components/sdg/goals/index_component.html.erb b/app/components/sdg/goals/index_component.html.erb index f3b4b0fa8..99caed36a 100644 --- a/app/components/sdg/goals/index_component.html.erb +++ b/app/components/sdg/goals/index_component.html.erb @@ -1,5 +1,7 @@ <% provide(:title) { title } %> +<%= render Shared::BannerComponent.new("sdg") %> +
<%= link_list(*goal_links, class: "sdg-goal-list") %> diff --git a/app/components/shared/banner_component.html.erb b/app/components/shared/banner_component.html.erb new file mode 100644 index 000000000..fe020302a --- /dev/null +++ b/app/components/shared/banner_component.html.erb @@ -0,0 +1,5 @@ +<% if banner %> + +<% end %> diff --git a/app/components/shared/banner_component.rb b/app/components/shared/banner_component.rb new file mode 100644 index 000000000..de61e1602 --- /dev/null +++ b/app/components/shared/banner_component.rb @@ -0,0 +1,24 @@ +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 + + private + + def link + link_to banner.target_url do + tag.h2(banner.title, style: "color:#{banner.font_color}") + + tag.h3(banner.description, style: "color:#{banner.font_color}") + end + end +end diff --git a/app/controllers/budgets_controller.rb b/app/controllers/budgets_controller.rb index 9fb0b0bf6..ec7e93f57 100644 --- a/app/controllers/budgets_controller.rb +++ b/app/controllers/budgets_controller.rb @@ -17,7 +17,6 @@ class BudgetsController < ApplicationController def index @finished_budgets = @budgets.finished.order(created_at: :desc) @budgets_coordinates = current_budget_map_locations - @banners = Banner.in_section("budgets").with_active end private diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 8b2a6d3bc..5523285bf 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,7 +16,6 @@ module CommentableActions index_customization @tag_cloud = tag_cloud - @banners = Banner.in_section(section(resource_model.name)).with_active set_resource_votes(@resources) @@ -110,15 +109,6 @@ module CommentableActions nil end - def section(resource_name) - case resource_name - when "Proposal" - "proposals" - when "Debate" - "debates" - end - end - def featured_proposals @featured_proposals ||= [] end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index a4b01cf09..03bb40828 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -6,7 +6,6 @@ class PagesController < ApplicationController def show @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id]) - @banners = Banner.in_section("help_page").with_active if @custom_page.present? @cards = @custom_page.cards diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 4e3081e73..9fa9bf1f2 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -11,7 +11,6 @@ class WelcomeController < ApplicationController @header = Widget::Card.header.first @feeds = Widget::Feed.active @cards = Widget::Card.body - @banners = Banner.in_section("homepage").with_active @remote_translations = detect_remote_translations(@feeds, @recommended_debates, @recommended_proposals) diff --git a/app/helpers/banners_helper.rb b/app/helpers/banners_helper.rb deleted file mode 100644 index 42cdb240d..000000000 --- a/app/helpers/banners_helper.rb +++ /dev/null @@ -1,12 +0,0 @@ -module BannersHelper - def has_banners? - @banners.present? && @banners.count > 0 - end - - def banner_target_link(banner) - link_to banner.target_url do - tag.h2(banner.title, style: "color:#{banner.font_color}") + - tag.h3(banner.description, style: "color:#{banner.font_color}") - end - end -end diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 70e55079e..8737b760b 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -79,6 +79,6 @@
- <%= render "shared/banner", banner: @banner %> + <%= render Shared::BannerComponent.new(@banner) %>
<% end %> diff --git a/app/views/admin/banners/index.html.erb b/app/views/admin/banners/index.html.erb index 67b151d86..bd71afb5f 100644 --- a/app/views/admin/banners/index.html.erb +++ b/app/views/admin/banners/index.html.erb @@ -30,7 +30,7 @@ <%= t("admin.banners.index.preview") %> - <%= render "shared/banner", banner: banner %> + <%= render Shared::BannerComponent.new(banner) %> diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 1beeb1179..4121e817d 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -1,4 +1,4 @@ -<%= render "shared/banner" %> +<%= render Shared::BannerComponent.new("budgets") %> <% provide :title do %><%= t("budgets.index.title") %><% end %> diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 0d9651360..24142020b 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -40,7 +40,7 @@
- <%= render "shared/banner" %> + <%= render Shared::BannerComponent.new("debates") %> <% unless @search_terms || !has_featured? %> <%= render "featured_debates" %> diff --git a/app/views/pages/help/index.html.erb b/app/views/pages/help/index.html.erb index 505ff2196..34f441e69 100644 --- a/app/views/pages/help/index.html.erb +++ b/app/views/pages/help/index.html.erb @@ -3,7 +3,7 @@ <%= render "shared/canonical", href: help_url %> <% end %> -<%= render "shared/banner" %> +<%= render Shared::BannerComponent.new("help_page") %>
diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index c28790495..8ec111379 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -49,7 +49,7 @@
- <%= render "shared/banner" %> + <%= render Shared::BannerComponent.new("proposals") %> <% if show_featured_proposals? %>