diff --git a/app/components/spotlight/masthead_component.html.erb b/app/components/spotlight/masthead_component.html.erb new file mode 100644 index 000000000..43779f341 --- /dev/null +++ b/app/components/spotlight/masthead_component.html.erb @@ -0,0 +1,18 @@ +<% if show_contact_form? && (current_exhibit.nil? || !current_page?(spotlight.new_exhibit_contact_form_path(current_exhibit))) %> +
+ <%= render 'spotlight/shared/report_a_problem' %> +
+<% 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..53ecf8607 --- /dev/null +++ b/app/components/spotlight/masthead_component.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Spotlight + # Draws the masthead + class MastheadComponent < ViewComponent::Base + def initialize(current_exhibit:, current_masthead:, resource_masthead:) + @current_exhibit = current_exhibit + @current_masthead = current_masthead + @resource_masthead = resource_masthead + super + end + + attr_reader :current_exhibit, :current_masthead + + def resource_masthead? + @resource_masthead + end + + 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 + if current_exhibit + render 'shared/exhibit_navbar' + else + render 'shared/site_navbar' + end + end + end +end diff --git a/app/views/layouts/spotlight/base.html.erb b/app/views/layouts/spotlight/base.html.erb index 3a60d47b6..1aa32d63a 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:, current_masthead:, resource_masthead: resource_masthead?) %> <%= content_for?(:header_content) ? yield(:header_content) : "" %>
diff --git a/app/views/shared/_masthead.html.erb b/app/views/shared/_masthead.html.erb index 6c23fa053..b042ee6ca 100644 --- a/app/views/shared/_masthead.html.erb +++ b/app/views/shared/_masthead.html.erb @@ -1,18 +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 %> - -
- <% if current_masthead %> - - - <% end %> - - <%= render current_exhibit ? 'shared/exhibit_navbar' : 'shared/site_navbar' if resource_masthead? %> - <%= render Spotlight::Engine.config.spotlight.title_component.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %> - <%= render current_exhibit ? 'shared/exhibit_navbar' : 'shared/site_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:, resource_masthead: resource_masthead?) %>