Skip to content

Commit

Permalink
Extract MastheadComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 20, 2024
1 parent eb2b869 commit 444f60a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
18 changes: 18 additions & 0 deletions app/components/spotlight/masthead_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% if show_contact_form? && (current_exhibit.nil? || !current_page?(spotlight.new_exhibit_contact_form_path(current_exhibit))) %>
<div id="report-problem-form">
<%= render 'spotlight/shared/report_a_problem' %>
</div>
<% end %>

<header class="masthead <%= 'image-masthead' if current_masthead %> <%= 'resource-masthead' if resource_masthead? %>">
<% if current_masthead %>
<span class='background-container' style="background-image: url('<%= current_masthead.iiif_url %>')"></span>
<span class='background-container-gradient'></span>
<% 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? %>
</header>

<%= render Spotlight::BreadcrumbsComponent.new(breadcrumbs:) %>
32 changes: 32 additions & 0 deletions app/components/spotlight/masthead_component.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/views/layouts/spotlight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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) : "" %>

<main id="main-container" class="<%= container_classes %>" aria-label="<%= t('blacklight.main.aria.main_container') %>">
Expand Down
20 changes: 2 additions & 18 deletions app/views/shared/_masthead.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
<% if show_contact_form? && (current_exhibit.nil? || !current_page?(spotlight.new_exhibit_contact_form_path(current_exhibit))) %>
<div id="report-problem-form">
<%= render 'spotlight/shared/report_a_problem' %>
</div>
<% end %>

<header class="masthead <%= 'image-masthead' if current_masthead %> <%= 'resource-masthead' if resource_masthead? %>">
<% if current_masthead %>
<span class='background-container' style="background-image: url('<%= current_masthead.iiif_url %>')"></span>
<span class='background-container-gradient'></span>
<% 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? %>
</header>

<%= 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?) %>

0 comments on commit 444f60a

Please sign in to comment.