diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-03 03:22:02 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-03 03:22:02 +0200 |
| commit | 287569c9bbfdadae767254792cd2b53d0515d928 (patch) | |
| tree | 8a9b1fb8dd9b26c315fd2b0e9e412e2cc056d80b /app | |
| parent | e5e8212db58ec6ed7421ed95a85f6b654e8e300a (diff) | |
Add weekday abbreviation for open-today widget
RruleHumanizer gains WEEKDAY_NAMES_ABBR (Mo/Di/Mi/...) alongside the
existing WEEKDAY_NAMES and WEEKDAY_NAMES_ADVERBIAL hashes, plus a
self.wday_abbr(time, locale) utility mapping a Time's wday to its
RFC5545 code and looking up the abbreviation - keeping RFC5545
vocabulary in one place rather than teaching ContentHelper about day
codes directly.
ContentHelper#weekday_abbr is a thin wrapper passing I18n.locale
through. The partial now renders "Fr 19:00" instead of just "19:00",
joined with a non-breaking space so the pair can't split across a
line wrap.
Takes an explicit Time rather than reading Date.today, matching this
file's existing style of passing state in rather than reading it
ambiently - and staying correct if the currently-unused
calendar/_front_page_calendar partial (spanning six weeks, not just
today) is ever revived and reuses this helper.
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/content_helper.rb | 4 | ||||
| -rw-r--r-- | app/models/concerns/rrule_humanizer.rb | 9 | ||||
| -rw-r--r-- | app/views/content/_open_erfas_today.html.erb | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index bf7287f..6043089 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -39,6 +39,10 @@ module ContentHelper | |||
| 39 | ) | 39 | ) |
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | def weekday_abbr(time) | ||
| 43 | RruleHumanizer.wday_abbr(time, I18n.locale) | ||
| 44 | end | ||
| 45 | |||
| 42 | def tags | 46 | def tags |
| 43 | render :partial => 'content/tags' | 47 | render :partial => 'content/tags' |
| 44 | end | 48 | end |
diff --git a/app/models/concerns/rrule_humanizer.rb b/app/models/concerns/rrule_humanizer.rb index 6cee711..8231de8 100644 --- a/app/models/concerns/rrule_humanizer.rb +++ b/app/models/concerns/rrule_humanizer.rb | |||
| @@ -10,6 +10,10 @@ module RruleHumanizer | |||
| 10 | de: { "MO"=>"montags","TU"=>"dienstags","WE"=>"mittwochs","TH"=>"donnerstags","FR"=>"freitags","SA"=>"samstags","SU"=>"sonntags" } | 10 | de: { "MO"=>"montags","TU"=>"dienstags","WE"=>"mittwochs","TH"=>"donnerstags","FR"=>"freitags","SA"=>"samstags","SU"=>"sonntags" } |
| 11 | }.freeze | 11 | }.freeze |
| 12 | 12 | ||
| 13 | WEEKDAY_NAMES_ABBR = { | ||
| 14 | de: { "MO"=>"Mo","TU"=>"Di","WE"=>"Mi","TH"=>"Do","FR"=>"Fr","SA"=>"Sa","SU"=>"So" } | ||
| 15 | }.freeze | ||
| 16 | |||
| 13 | ORDINAL_NAMES = { | 17 | ORDINAL_NAMES = { |
| 14 | de: { 1=>"ersten", 2=>"zweiten", 3=>"dritten", 4=>"vierten", -1=>"letzten", -2=>"vorletzten" }, | 18 | de: { 1=>"ersten", 2=>"zweiten", 3=>"dritten", 4=>"vierten", -1=>"letzten", -2=>"vorletzten" }, |
| 15 | en: { 1=>"first", 2=>"second", 3=>"third", 4=>"fourth", -1=>"last", -2=>"second-to-last" } | 19 | en: { 1=>"first", 2=>"second", 3=>"third", 4=>"fourth", -1=>"last", -2=>"second-to-last" } |
| @@ -79,4 +83,9 @@ module RruleHumanizer | |||
| 79 | 83 | ||
| 80 | base | 84 | base |
| 81 | end | 85 | end |
| 86 | |||
| 87 | def self.wday_abbr(time, locale) | ||
| 88 | code = %w[SU MO TU WE TH FR SA][time.wday] | ||
| 89 | (WEEKDAY_NAMES_ABBR[locale.to_sym] || WEEKDAY_NAMES_ABBR[:de])[code] | ||
| 90 | end | ||
| 82 | end | 91 | end |
diff --git a/app/views/content/_open_erfas_today.html.erb b/app/views/content/_open_erfas_today.html.erb index 3448af3..468bedc 100644 --- a/app/views/content/_open_erfas_today.html.erb +++ b/app/views/content/_open_erfas_today.html.erb | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | <% occurrences.each do |occurrence| %> | 4 | <% occurrences.each do |occurrence| %> |
| 5 | <li> | 5 | <li> |
| 6 | <%= link_to_path occurrence.node.head.title, occurrence.node.unique_name %> | 6 | <%= link_to_path occurrence.node.head.title, occurrence.node.unique_name %> |
| 7 | <span class="event_time"><%= occurrence.start_time.strftime("%H:%M") %></span> | 7 | <span class="event_time"><%= weekday_abbr(occurrence.start_time) %> <%= occurrence.start_time.strftime("%H:%M") %></span> |
| 8 | </li> | 8 | </li> |
| 9 | <% end %> | 9 | <% end %> |
| 10 | </ul> | 10 | </ul> |
