diff options
Diffstat (limited to 'internal/calfeed')
| -rw-r--r-- | internal/calfeed/calfeed.go | 30 | ||||
| -rw-r--r-- | internal/calfeed/json.go | 17 | ||||
| -rw-r--r-- | internal/calfeed/json_test.go | 35 |
3 files changed, 82 insertions, 0 deletions
diff --git a/internal/calfeed/calfeed.go b/internal/calfeed/calfeed.go new file mode 100644 index 0000000..cb2a8ff --- /dev/null +++ b/internal/calfeed/calfeed.go @@ -0,0 +1,30 @@ +package calfeed + +type ReadingView struct { + Part string `json:"part"` + Citation string `json:"citation"` +} + +type CelView struct { + Slug string `json:"slug"` + Name string `json:"name"` + Rank string `json:"rank"` + Class int `json:"class"` +} + +type DayView struct { + Date string `json:"date"` // YYYY-MM-DD + Season string `json:"season"` + Week int `json:"week"` + Weekday string `json:"weekday"` + Colour string `json:"colour"` + Observed CelView `json:"observed"` + Others []CelView `json:"others"` + Cycles Cycles `json:"cycles"` + Readings []ReadingView `json:"readings"` +} + +type Cycles struct { + Sunday string `json:"sunday"` + Weekday string `json:"weekday"` +} diff --git a/internal/calfeed/json.go b/internal/calfeed/json.go new file mode 100644 index 0000000..c1a50ca --- /dev/null +++ b/internal/calfeed/json.go @@ -0,0 +1,17 @@ +package calfeed + +import "encoding/json" + +const Schema = "lectio.calendar/1" + +// JSON renders days as the stable lectio.calendar/1 envelope. +func JSON(form string, days []DayView) ([]byte, error) { + if days == nil { + days = []DayView{} + } + return json.MarshalIndent(struct { + Schema string `json:"schema"` + Form string `json:"form"` + Days []DayView `json:"days"` + }{Schema, form, days}, "", " ") +} diff --git a/internal/calfeed/json_test.go b/internal/calfeed/json_test.go new file mode 100644 index 0000000..d2bc856 --- /dev/null +++ b/internal/calfeed/json_test.go @@ -0,0 +1,35 @@ +package calfeed + +import ( + "encoding/json" + "testing" +) + +func TestJSONShape(t *testing.T) { + days := []DayView{{ + Date: "2026-01-06", Season: "time-after-epiphany", Week: 1, + Weekday: "Tuesday", Colour: "white", + Observed: CelView{Slug: "ef-epiphany", Name: "The Epiphany of the Lord", Rank: "class-1", Class: 1}, + Others: []CelView{}, + Cycles: Cycles{}, + Readings: []ReadingView{{Part: "gospel", Citation: "Matt 2:1-12"}}, + }} + b, err := JSON("old", days) + if err != nil { + t.Fatal(err) + } + var out struct { + Schema string `json:"schema"` + Form string `json:"form"` + Days []DayView `json:"days"` + } + if err := json.Unmarshal(b, &out); err != nil { + t.Fatal(err) + } + if out.Schema != "lectio.calendar/1" || out.Form != "old" || len(out.Days) != 1 { + t.Fatalf("bad envelope: %s", b) + } + if out.Days[0].Observed.Name != "The Epiphany of the Lord" { + t.Fatalf("bad day: %s", b) + } +} |
