diff --git a/app/components/spotlight/masthead_component.html.erb b/app/components/spotlight/masthead_component.html.erb new file mode 100644 index 000000000..d3a4a0bd0 --- /dev/null +++ b/app/components/spotlight/masthead_component.html.erb @@ -0,0 +1,28 @@ +<% if show_contact_form? && (current_exhibit.nil? || !current_page?(spotlight.new_exhibit_contact_form_path(current_exhibit))) %> +
+ <%= render 'spotlight/shared/report_a_problem' %> +
+<% end %> + +<%- masthead_navbar = capture do %> + <% if content_for? :masthead_navbar %> + <%= content_for :masthead_navbar %> + <% elsif current_exhibit %> + <%= render 'shared/exhibit_navbar' %> + <% else %> + <%= render 'shared/site_navbar' %> + <% end %> +<% end %> + +
+ <% if current_masthead %> + + + <% end %> + + <%= masthead_navbar if resource_masthead? %> + <%= render Spotlight::Engine.config.spotlight.title_component.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %> + <%= masthead_navbar unless resource_masthead? %> +
+ +<%= render Spotlight::BreadcrumbsComponent.new(breadcrumbs:) %> diff --git a/app/components/spotlight/masthead_component.rb b/app/components/spotlight/masthead_component.rb new file mode 100644 index 000000000..06de18fea --- /dev/null +++ b/app/components/spotlight/masthead_component.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Spotlight + # Draws the masthead + class MastheadComponent < ViewComponent::Base + def initialize(current_exhibit:, current_masthead:) + @current_exhibit = current_exhibit + @current_masthead = current_masthead + super + end + + attr_reader :current_exhibit, :current_masthead + + def show_contact_form? + helpers.show_contact_form? && + (current_exhibit.nil? || !current_page?(spotlight.new_exhibit_contact_form_path(current_exhibit))) + end + + def masthead_navbar + @masthead_navbar ||= capture do + if content_for? :masthead_navbar + content_for :masthead_navbar + elsif current_exhibit + render 'shared/exhibit_navbar' + else + render 'shared/site_navbar' + end + end + end + end +end diff --git a/app/views/layouts/spotlight/base.html.erb b/app/views/layouts/spotlight/base.html.erb index 3a60d47b6..dbd613ec6 100644 --- a/app/views/layouts/spotlight/base.html.erb +++ b/app/views/layouts/spotlight/base.html.erb @@ -46,7 +46,7 @@ <%= content_for(:skip_links) %> <% end %> <%= render partial: 'shared/header_navbar' %> - <%= render partial: 'shared/masthead' %> + <%= render Spotlight::MastheadComponent.new(current_exhibit:) %> <%= content_for?(:header_content) ? yield(:header_content) : "" %>
diff --git a/app/views/shared/_masthead.html.erb b/app/views/shared/_masthead.html.erb index d3a4a0bd0..64b36d328 100644 --- a/app/views/shared/_masthead.html.erb +++ b/app/views/shared/_masthead.html.erb @@ -1,28 +1,2 @@ -<% if show_contact_form? && (current_exhibit.nil? || !current_page?(spotlight.new_exhibit_contact_form_path(current_exhibit))) %> -
- <%= render 'spotlight/shared/report_a_problem' %> -
-<% end %> - -<%- masthead_navbar = capture do %> - <% if content_for? :masthead_navbar %> - <%= content_for :masthead_navbar %> - <% elsif current_exhibit %> - <%= render 'shared/exhibit_navbar' %> - <% else %> - <%= render 'shared/site_navbar' %> - <% end %> -<% end %> - -
- <% if current_masthead %> - - - <% end %> - - <%= masthead_navbar if resource_masthead? %> - <%= render Spotlight::Engine.config.spotlight.title_component.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %> - <%= masthead_navbar unless resource_masthead? %> -
- -<%= render Spotlight::BreadcrumbsComponent.new(breadcrumbs:) %> +<% Spotlight.deprecator.warn "Rendering deprecated partial shared/masthead. Use MastheadComponent instead" %> +<%= render Spotlight::MastheadComponent.new(current_exhibit:, current_masthead:) %>