Skip to content

Commit

Permalink
Extract a TitleComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 18, 2024
1 parent d829bc8 commit b56c39d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
6 changes: 6 additions & 0 deletions app/components/spotlight/title_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="container site-title-container">
<div class="site-title-wrapper">
<%= title %>
<%= subtitle %>
</div>
</div>
22 changes: 22 additions & 0 deletions app/components/spotlight/title_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

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

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

def subtitle
return unless @subtitle

tag.small(@subtitle, class: 'd-none d-md-block py-2 fs-4')
end
end
end
19 changes: 1 addition & 18 deletions app/views/shared/_masthead.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,7 @@
<% end %>

<%= masthead_navbar if resource_masthead? %>

<div class="container site-title-container">
<div class="site-title-wrapper">
<% if content_for? :masthead %>
<h1 class="site-title h2">
<%= content_for :masthead %>
</h1>
<% else %>
<h1 class="site-title h2">
<%= masthead_heading_content %>
</h1>
<% if masthead_subheading_content %>
<small class="d-none d-md-block py-2 fs-4"><%= masthead_subheading_content %></small>
<% end %>
<% end %>
</div>
</div>

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

Expand Down
1 change: 1 addition & 0 deletions lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def self.blacklight_config
ActiveSupport::Reloader.to_prepare do
Spotlight::Engine.config.spotlight = OpenStruct.new
Spotlight::Engine.config.spotlight.header_navigation_link_component = Spotlight::HeaderNavigationLinkComponent
Spotlight::Engine.config.spotlight.title_component = Spotlight::TitleComponent
end
end

Expand Down

0 comments on commit b56c39d

Please sign in to comment.