-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2866 from sul-dlss/linked-title
Link masthead title and subtitle to app or exhibit home
- Loading branch information
Showing
5 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="masthead-title"> | ||
<%= title %> | ||
<%= subtitle %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |