From 95e5fe8b8fb1e16c71ffbed6681ab8b2203249d4 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 1 Jul 2025 21:43:13 +0200 Subject: Add subtitles to pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/controllers/exports_controller.rb | 1 + app/controllers/searches_controller.rb | 2 ++ app/controllers/shared_searches_controller.rb | 2 ++ app/controllers/tags_controller.rb | 3 +++ app/controllers/things_controller.rb | 2 ++ app/helpers/layout_helper.rb | 14 ++++++++++++++ app/views/layouts/application.html.erb | 2 +- 7 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/helpers/layout_helper.rb (limited to 'app') diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 812cf39..4b809c9 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -36,6 +36,7 @@ class ExportsController < ApplicationController else Search.find(params[:search_id]) end + @subtitle = @search.name end def set_results diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 376455c..a01fd59 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -14,6 +14,7 @@ class SearchesController < ApplicationController def new @search = Search.new + @subtitle = I18n.t('searches.title') end def edit; end @@ -52,6 +53,7 @@ class SearchesController < ApplicationController def set_search @search = Search.find(params[:id]) + @subtitle = @search.name end def search_params diff --git a/app/controllers/shared_searches_controller.rb b/app/controllers/shared_searches_controller.rb index ca65539..ffdd56e 100644 --- a/app/controllers/shared_searches_controller.rb +++ b/app/controllers/shared_searches_controller.rb @@ -6,10 +6,12 @@ class SharedSearchesController < ApplicationController def index @searches = Search.order(:name) @saved_searches = @searches.where(shared: true) + @subtitle = I18n.t('searches.shared.title') end def show @search = Search.where(shared: true).find(params[:search_id]) + @subtitle = @search.name @results = @search.results.values.flatten end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index c5ca6a8..c56b9f9 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -5,10 +5,12 @@ class TagsController < ApplicationController def index @tags = Tag.order(:name) + @subtitle = I18n.t('tags.title') end def new @tag = Tag.new + @subtitle = I18n.t('tags.title') end def edit; end @@ -59,6 +61,7 @@ class TagsController < ApplicationController def search @search = Search.new(name: 'temporary', body: "tag:\"#{@tag.name}\"") + @subtitle = "#{I18n.t('tags.searching-by')} '#{@tag.name}'" render 'searches/show' end diff --git a/app/controllers/things_controller.rb b/app/controllers/things_controller.rb index e994a3d..f9e7674 100644 --- a/app/controllers/things_controller.rb +++ b/app/controllers/things_controller.rb @@ -9,6 +9,7 @@ class ThingsController < ApplicationController def new @thing = Thing.new + @subtitle = I18n.t('activerecord.models.thing') end def edit; end @@ -59,6 +60,7 @@ class ThingsController < ApplicationController def set_thing @thing = Thing.find(params[:id]) + @subtitle = @thing.title end def thing_params diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb new file mode 100644 index 0000000..03917d5 --- /dev/null +++ b/app/helpers/layout_helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module LayoutHelper + # Returns a strign containing the string to be used for the HTML tag. + def page_title + title = ENV.fetch('OPERUM_BASE_TITLE', 'Operum') + + if @subtitle + "#{@subtitle} - #{title}" + else + title + end + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 422270d..8a46e3f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@ <!DOCTYPE html> <html lang="<%= I18n.default_locale %>"> <head> - <title><%= ENV.fetch('OPERUM_BASE_TITLE', 'Operum') %> + <%= page_title %> -- cgit v1.2.3