From 84657fa9d633a7d3e20c10645589061ecebeee3f Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 3 Aug 2026 17:12:34 +0200 Subject: Render dates, booleans and counts through the locale files --- app/helpers/datetime_helper.rb | 9 +++++++++ app/helpers/events_helper.rb | 5 +++++ app/models/event.rb | 3 +++ app/views/events/index.html.erb | 14 +++++--------- app/views/events/show.html.erb | 4 ++-- app/views/events/without_node.html.erb | 8 ++++---- app/views/nodes/_node_list.html.erb | 2 +- app/views/nodes/show.html.erb | 4 ++-- app/views/nodes/sitemap.html.erb | 2 +- app/views/revisions/index.html.erb | 2 +- app/views/revisions/show.html.erb | 4 ++-- app/views/users/show.html.erb | 2 +- 12 files changed, 36 insertions(+), 23 deletions(-) (limited to 'app') diff --git a/app/helpers/datetime_helper.rb b/app/helpers/datetime_helper.rb index 8497b1c0..ea6fd5c2 100644 --- a/app/helpers/datetime_helper.rb +++ b/app/helpers/datetime_helper.rb @@ -50,4 +50,13 @@ module DatetimeHelper locale == :de ? "vor #{count} #{word}" : "#{count} #{word} ago" end + def admin_datetime(time) + return "" if time.blank? + I18n.l(time, :format => :ccc) + end + + def admin_date(time) + return "" if time.blank? + I18n.l(time, :format => :ccc_date) + end end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 5e84f534..1e2e91dc 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -10,4 +10,9 @@ module EventsHelper return "" if rrule.blank? raw(rrule.split(';', -1).map { |part| CGI.escapeHTML(part) }.join(';')) end + + def external_url_link(url) + return nil if url.blank? + url.match?(%r{\Ahttps?://}i) ? link_to(url, url) : h(url) + end end diff --git a/app/models/event.rb b/app/models/event.rb index 7726f9bf..792ab448 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -6,6 +6,9 @@ class Event < ApplicationRecord acts_as_taggable_on :tags validates :title, presence: true, unless: -> { node_id.present? } + validates :url, :format => { :with => %r{\Ahttps?://}i, + :allow_blank => true, + :message => :must_be_http } after_save :generate_occurrences diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index 138a02ec..7dfb854c 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -24,16 +24,12 @@ <% @events.each do |event| %> <%= link_to event.display_title, event %> - <%=h event.start_time %> - <%=h event.end_time %> + <%= admin_datetime(event.start_time) %> + <%= admin_datetime(event.end_time) %> <%= rrule_with_break_opportunities(event.rrule) %> - <%=h event.allday %> → <%= event.allday ? t("admin.common.yes") : t("admin.common.no") %> - - <% if event.url.present? %> - <%= link_to event.url, event.url %> - <% end %> - - <%= event.node ? link_to(event.node_id, node_path(event.node)) : '' %> + <%= t("admin.common.#{event.allday ? "yes" : "no"}") %> + <%= external_url_link(event.url) %> + <%= event.node ? link_to(event.node.unique_name, node_path(event.node)) : "" %> <%= link_to t(".edit_link"), edit_event_path(event) %> <% end %> diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb index 98e972c6..d77f770e 100644 --- a/app/views/events/show.html.erb +++ b/app/views/events/show.html.erb @@ -24,10 +24,10 @@
<%= Event.human_attribute_name(:start_time) %>
-
<%=h @event.start_time %>
+
<%= admin_datetime(@event.start_time) %>
<%= Event.human_attribute_name(:end_time) %>
-
<%=h @event.end_time %>
+
<%= admin_datetime(@event.end_time) %>
<%= Event.human_attribute_name(:rrule) %>
<%=h @event.rrule %>
diff --git a/app/views/events/without_node.html.erb b/app/views/events/without_node.html.erb index c610b560..e59eedc7 100644 --- a/app/views/events/without_node.html.erb +++ b/app/views/events/without_node.html.erb @@ -20,11 +20,11 @@ <% @events.each do |event| %> <%= link_to event.display_title, event %> - <%=h event.start_time %> - <%=h event.end_time %> - <%=h event.allday %> → <%= event.allday ? t("admin.common.yes") : t("admin.common.no") %> + <%= admin_datetime(event.start_time) %> + <%= admin_datetime(event.end_time) %> + <%= t("admin.common.#{event.allday ? "yes" : "no"}") %> <%=h event.url %> - <%= link_to t("events.index.edit_link"), edit_event_path(event) %> + <%= external_url_link(event.url) %> <% end %> diff --git a/app/views/nodes/_node_list.html.erb b/app/views/nodes/_node_list.html.erb index 1e5d0ed9..0dc3c5a0 100644 --- a/app/views/nodes/_node_list.html.erb +++ b/app/views/nodes/_node_list.html.erb @@ -34,7 +34,7 @@ <%= link_to 'revisions', node_revisions_path(node) %> <%= node.lock_owner.login if node.lock_owner %> - <%= node.draft ? node.draft.revision : (node.head ? node.head.revision : "EMPTY") %> + <%= node.draft ? node.draft.revision : (node.head ? node.head.revision : t(".no_revision")) %> <% end %> diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index a6167c9e..a94e001c 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb @@ -195,12 +195,12 @@
<%= t(".last_updated") %> - <%= @page.updated_at %> + <%= admin_datetime(@page.updated_at) %>
<% if @page.published_at.present? %>
<%= @page.public? ? t(".published_at") : t(".will_publish_at") %> - <%= @page.published_at %> + <%= admin_datetime(@page.published_at) %>
<% end %>
diff --git a/app/views/nodes/sitemap.html.erb b/app/views/nodes/sitemap.html.erb index f749a803..ea64b356 100644 --- a/app/views/nodes/sitemap.html.erb +++ b/app/views/nodes/sitemap.html.erb @@ -23,7 +23,7 @@ <% if next_level && next_level > level %> > - <%= pluralize(@sitemap_descendant_counts[node.id], 'descendant', 'descendants') %> + <%= t(".descendants", :count => @sitemap_descendant_counts[node.id]) %> <% open_details.push(level) %> <% end %> diff --git a/app/views/revisions/index.html.erb b/app/views/revisions/index.html.erb index d118f96a..3fb33b90 100644 --- a/app/views/revisions/index.html.erb +++ b/app/views/revisions/index.html.erb @@ -52,7 +52,7 @@ <%= page.revision %> <%= page.translations.find_by(:locale => @translation_locale)&.title || "—" %> <%= page.editor.try(:login) %> - <%= page.updated_at %> + <%= admin_datetime(page.updated_at) %> <%= link_to t(".show_link"), node_revision_path(@node, page, :translation_locale => @translation_locale) %> <%= button_to t(".restore_link"), restore_node_revision_path(@node, page), diff --git a/app/views/revisions/show.html.erb b/app/views/revisions/show.html.erb index addcfa1a..1456a051 100644 --- a/app/views/revisions/show.html.erb +++ b/app/views/revisions/show.html.erb @@ -22,10 +22,10 @@
<%= @page.editor.try(:login) %>
<%= t("nodes.show.last_updated") %>
-
<%= @page.updated_at %>
+
<%= admin_datetime(@page.updated_at) %>
<%= t("nodes.show.published_at") %>
-
<%= @page.published_at %>
+
<%= admin_datetime(@page.published_at) %>
<%= Page.human_attribute_name(:title) %>
<%= translation&.title %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index fc6df4e3..2685a15b 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -28,7 +28,7 @@
<%= t("users.labels.last_login") %>
<% if @user.last_login_at %> - <%= I18n.l(@user.last_login_at, :format => :ccc_date) %> + <%= admin_date(@user.last_login_at) %> <% else %> <%= t("users.never_signed_in") %> <% end %> -- cgit v1.3