Skip to content

Commit 1be703c

Browse files
committed
feat: add page_title helper and update title rendering in application layout
1 parent a065fd0 commit 1be703c

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

app/helpers/better_together/application_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ module BetterTogether
77
module ApplicationHelper # rubocop:todo Metrics/ModuleLength
88
include MetricsHelper
99

10+
# Returns the page title for the current page, combining any page-specific title with the platform name
11+
def page_title(title = nil)
12+
title_parts = []
13+
title_parts << title if title.present?
14+
title_parts << host_platform.name if host_platform.present? && !turbo_native_app?
15+
title_parts.compact.join(' | ')
16+
end
17+
1018
# Returns the base URL configured for BetterTogether.
1119
def base_url
1220
::BetterTogether.base_url
@@ -205,6 +213,10 @@ def better_together_url_helper?(method)
205213
method.to_s.end_with?('_path', '_url') && BetterTogether::Engine.routes.url_helpers.respond_to?(method)
206214
end
207215

216+
def turbo_native_app?
217+
request.user_agent.to_s.include?('Turbo Native')
218+
end
219+
208220
# Returns the appropriate icon and color for an event based on the person's relationship to it
209221
def event_relationship_icon(person, event) # rubocop:todo Metrics/MethodLength
210222
relationship = person.event_relationship_for(event)

app/models/better_together/navigation_item.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,15 @@ def self.permitted_attributes(id: false, destroy: false) # rubocop:todo Metrics/
214214
super + attrs
215215
end
216216

217-
def url
217+
def url(path_only: false)
218218
fallback_url = "##{identifier}"
219219

220220
if linkable.present?
221221
linkable.url
222222
elsif route_name.present? # If the route_name is present, use the dynamic route
223-
retrieve_route(route_name)
223+
route = route_name
224+
route = route_name.sub('url', 'path') if path_only
225+
retrieve_route(route)
224226
else
225227
read_attribute(:url) or fallback_url
226228
end

app/views/layouts/better_together/_navbar_brand.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<%= cache ['header_branding', host_community.cache_key_with_version] do %>
33
<!-- Branding Element -->
4-
<%= link_to base_url_with_locale, class: 'navbar-brand' do %>
4+
<%= link_to base_path_with_locale, class: 'navbar-brand' do %>
55
<% if host_community_logo_url %>
66
<%= image_tag host_community_logo_url, class: "#{dom_class(host_community, :host)}_logo", title: host_community.name, alt: host_community.name %>
77
<% else %>

app/views/layouts/better_together/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- Custom Head Javascript from Host App -->
1010
<%= render 'layouts/better_together/custom_head_javascript' %>
1111

12-
<title><%= (yield(:page_title) + ' | ') if content_for?(:page_title) %><%= host_platform.name %></title>
12+
<title><%= page_title(content_for(:page_title) || nil) %></title>
1313
<%= open_graph_meta_tags %>
1414
<%= seo_meta_tags %>
1515
<%= robots_meta_tag %>

0 commit comments

Comments
 (0)