Skip to content

Commit

Permalink
Link masthead title and subtitle to app or exhibit home
Browse files Browse the repository at this point in the history
  • Loading branch information
corylown committed Feb 21, 2025
1 parent 1a9534f commit 35aa85d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/modules/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
}

.masthead {
.masthead-title a {
--bs-link-hover-decoration: none;
}

.masthead-navigation {
li {
--sul-link-font-weight: 700;
Expand Down
4 changes: 4 additions & 0 deletions app/components/masthead_title_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="masthead-title">
<%= title %>
<%= subtitle %>
</div>
28 changes: 28 additions & 0 deletions app/components/masthead_title_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# Draws the title in the masthead
class MastheadTitleComponent < ViewComponent::Base
def initialize(title:, subtitle:)
@title = title
@subtitle = subtitle
super
end

def title
tag.h1 link(@title), class: 'site-title h2'
end

def subtitle
return unless @subtitle

tag.small link(@subtitle), class: 'py-2 fs-4'
end

private

def link(link_text)
return link_to link_text, helpers.spotlight.exhibit_path(helpers.current_exhibit) if helpers.current_exhibit

link_to link_text, helpers.spotlight.exhibits_path
end
end
16 changes: 2 additions & 14 deletions app/views/shared/_masthead.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@

<div class="masthead bg-light fog-light mb-0 pb-2">
<div class="container d-flex flex-wrap flex-md-row flex-column justify-content-between align-items-md-center align-items-start">
<div class="">
<h1 class="site-title h2">
<% if content_for? :masthead %>
<%= content_for :masthead %>
<% else %>
<%= masthead_heading_content %>
<% end %>
</h1>

<% if masthead_subheading_content %>
<small class="py-2 fs-4"><%= masthead_subheading_content %></small>
<% end %>
</div>

<%= render MastheadTitleComponent.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %>

<div class="align-self-md-end align-self-start">
<div class="collapse d-md-flex me-md-2"
aria-label="browse" id="user-util-collapse">
Expand Down
25 changes: 25 additions & 0 deletions spec/components/masthead_title_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe MastheadTitleComponent, type: :component do
subject(:rendered) do
Capybara::Node::Simple.new(render_inline(described_class.new(title: 'Exhibit Title',
subtitle: 'Exhibit Subtitle')).to_s)
end

context 'when there is no current exhibit' do
it { expect(rendered).to have_link('Exhibit Title', href: '/') }
it { expect(rendered).to have_link('Exhibit Subtitle', href: '/') }
end

context 'when there is a current exhibit' do
before do
allow(vc_test_controller).to receive(:current_exhibit)
.and_return(create(:exhibit, slug: 'exhibit-slug'))
end

it { expect(rendered).to have_link('Exhibit Title', href: '/exhibit-slug') }
it { expect(rendered).to have_link('Exhibit Subtitle', href: '/exhibit-slug') }
end
end

0 comments on commit 35aa85d

Please sign in to comment.