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 a820963 commit 0c368f6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
28 changes: 28 additions & 0 deletions app/components/spotlight/masthead_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% 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 %>

<%- 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 %>

<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:) %>
31 changes: 31 additions & 0 deletions app/components/spotlight/masthead_component.rb
Original file line number Diff line number Diff line change
@@ -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
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:) %>
<%= content_for?(:header_content) ? yield(:header_content) : "" %>

<main id="main-container" class="<%= container_classes %>" aria-label="<%= t('blacklight.main.aria.main_container') %>">
Expand Down
30 changes: 2 additions & 28 deletions app/views/shared/_masthead.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +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 %>

<%- 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 %>

<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:) %>
<% Spotlight.deprecator.warn "Rendering deprecated partial shared/masthead. Use MastheadComponent instead" %>
<%= render Spotlight::MastheadComponent.new(current_exhibit:, current_masthead:) %>

0 comments on commit 0c368f6

Please sign in to comment.