From c9f3bf46f0de09edb796e35f3dcff349febf75c9 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 24 Jul 2026 10:32:28 +0200 Subject: dayinfo: show feast/day name + colour (modern niedziela + traditional missalemeum) in cli/tui/web; v0.5.0 --- internal/readings/readings.go | 20 ++++++++++++-------- internal/readings/readings_test.go | 12 +++++++++--- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'internal/readings') diff --git a/internal/readings/readings.go b/internal/readings/readings.go index ac7209a..047e901 100644 --- a/internal/readings/readings.go +++ b/internal/readings/readings.go @@ -28,29 +28,33 @@ type Options struct { All bool } -// Load fetches the day's sections for the configured lectionary -// (cfg.Lectionary: "traditional" or "new") and applies part filtering. -// Returns liturgy.Section values regardless of source. -func Load(cfg config.Config, opts Options) ([]liturgy.Section, error) { +// Load fetches the day's sections and its DayInfo (celebration name, +// temporal, liturgical colour -- see liturgy.DayInfo) for the configured +// lectionary (cfg.Lectionary: "traditional" or "new") and applies part +// filtering. Returns liturgy.Section values regardless of source. A source +// that yields no DayInfo (see liturgy.Load/tradlit.Load) comes back as a +// zero liturgy.DayInfo, not an error -- callers omit the header for it. +func Load(cfg config.Config, opts Options) ([]liturgy.Section, liturgy.DayInfo, error) { offline := opts.Offline || cfg.Offline var secs []liturgy.Section + var info liturgy.DayInfo var err error if cfg.Lectionary == "traditional" { - secs, err = tradlit.Load(opts.Date, cfg.TraditionalLang, offline) + secs, info, err = tradlit.Load(opts.Date, cfg.TraditionalLang, offline) } else { - secs, err = liturgy.Load(liturgy.Options{ + secs, info, err = liturgy.Load(liturgy.Options{ Date: opts.Date, Refresh: opts.Refresh, Offline: offline, }) } if err != nil { - return nil, err + return nil, liturgy.DayInfo{}, err } - return filterParts(secs, cfg, opts.All), nil + return filterParts(secs, cfg, opts.All), info, nil } // filterParts keeps only the gospel when !all (PartID "ewangelia" modern or diff --git a/internal/readings/readings_test.go b/internal/readings/readings_test.go index 9a31802..c9e92cd 100644 --- a/internal/readings/readings_test.go +++ b/internal/readings/readings_test.go @@ -92,7 +92,7 @@ func TestLoadModernRoutes(t *testing.T) { t.Setenv("XDG_CACHE_HOME", t.TempDir()) cfg := config.Config{Lectionary: "new"} - secs, err := Load(cfg, Options{Date: "2026-07-22", All: true}) + secs, info, err := Load(cfg, Options{Date: "2026-07-22", All: true}) if err != nil { t.Fatalf("Load: %v", err) } @@ -106,6 +106,9 @@ func TestLoadModernRoutes(t *testing.T) { if !found { t.Errorf("no gospel section (PartID=ewangelia) found in %+v", secs) } + if !strings.Contains(info.Name, "Marii Magdaleny") { + t.Errorf("DayInfo.Name = %q, want it to contain %q", info.Name, "Marii Magdaleny") + } } // TestLoadTraditionalOfflineErrorsWithoutCache exercises the (formerly @@ -116,7 +119,7 @@ func TestLoadTraditionalOfflineErrorsWithoutCache(t *testing.T) { t.Setenv("XDG_CACHE_HOME", t.TempDir()) cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"} - _, err := Load(cfg, Options{Date: "2026-07-22", Offline: true}) + _, _, err := Load(cfg, Options{Date: "2026-07-22", Offline: true}) if err == nil { t.Fatal("expected error, got nil") } @@ -146,11 +149,14 @@ func TestLoadTraditionalOfflineReadsCache(t *testing.T) { } cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"} - secs, err := Load(cfg, Options{Date: "2026-07-22", Offline: true, All: true}) + secs, info, err := Load(cfg, Options{Date: "2026-07-22", Offline: true, All: true}) if err != nil { t.Fatalf("Load: %v", err) } if len(secs) == 0 { t.Error("expected traditional offline sections, got none") } + if info.Name != "St. Mary Magdalene" { + t.Errorf("DayInfo.Name = %q, want %q", info.Name, "St. Mary Magdalene") + } } -- cgit v1.3