diff options
| -rw-r--r-- | lib/render/view.ml | 14 | ||||
| -rw-r--r-- | man/colitur-templates.5 | 34 | ||||
| -rw-r--r-- | test/test_view.ml | 19 |
3 files changed, 62 insertions, 5 deletions
diff --git a/lib/render/view.ml b/lib/render/view.ml index 0691ffb..67dfa70 100644 --- a/lib/render/view.ml +++ b/lib/render/view.ml @@ -267,8 +267,20 @@ let of_days ~lang ~sigla ~vocab ~rite ~year days = let month_name = Lang.month lang m in let month_abbr = Lang.month_abbr lang m in T.Obj - [ ("num", str month_num); + [ (* A month carries its own name under BOTH spellings. The week + objects nested below expose [month_name]/[month_num]/ + [month_abbr], and a template author who learned those names + there naturally reaches for them one level up -- where, before + this, they resolved to nothing and rendered as the empty + string, because an unknown key is silently empty by design. + A month is the only scope where the short forms are + unambiguous, so they stay as the primary names and the + qualified forms are aliases. *) + ("num", str month_num); ("name", str month_name); + ("month_num", str month_num); + ("month_name", str month_name); + ("month_abbr", str month_abbr); ("days", T.List day_values); ("weeks", T.List (weeks_of_month ~first_dow ~month_num ~month_name ~month_abbr day_values)) ]) in diff --git a/man/colitur-templates.5 b/man/colitur-templates.5 index e04560b..e668b55 100644 --- a/man/colitur-templates.5 +++ b/man/colitur-templates.5 @@ -566,13 +566,21 @@ template iterates over directly, without going through .BR months . .SS month .TP -.B num -The month number, 1 through 12, as a string. +.BR num ", " month_num +The month number, 1 through 12, as a string. The two spellings are the same +value \(em see the note at the end of this subsection. .TP -.B name +.BR name ", " month_name The month's own resolved display name in the active language (e.g. .RB \(lq Ianuarius \(rq ), -a plain string. +a plain string. Both spellings are the same value. +.TP +.B month_abbr +The month's abbreviated name in the active language (e.g. +.RB \(lq Ian \(rq ), +from the language file's own +.B [month_abbr] +section. .TP .B days This month's own @@ -587,6 +595,24 @@ last rows padded with blank cells (see .B day \(-> in_month below) so every row has seven entries regardless of which weekday the month starts or ends on. +.PP +.B "Why two spellings." +A +.B week +object (below) carries +.BR month_name ", " month_num " and " month_abbr, +because at that level a bare +.B name +would be ambiguous. An author who learned those names inside +.B {{#weeks}} +naturally reaches for them one level up, inside +.BR {{#months}} . +Before colitur 0.9 they resolved to nothing there, and because an unknown +key renders as the EMPTY STRING by design (see +.B SCOPE AND LOOKUP +above), the result was a silently blank month heading rather than any +error. A month now answers to both. Prefer the short forms in new +templates: a month is the only scope where they are unambiguous. .SS week .TP .B num diff --git a/test/test_view.ml b/test/test_view.ml index b2d302e..a542419 100644 --- a/test/test_view.ml +++ b/test/test_view.ml @@ -292,6 +292,25 @@ let test_vocabularies_localise () = Alcotest.(check string) "rite_name" "Missale Romanum, editio typica 1962" (as_str (get [ "rite_name" ] v)) +(* A month answers to BOTH spellings of its own name. The week objects nested + inside a month expose [month_name]/[month_num]/[month_abbr], so an author + who learned those names there reaches for them one level up too -- and an + unknown key renders as the EMPTY STRING by design, so the mistake produced + a silently blank heading rather than any error. Found by writing a template + from scratch; the shipped ones all sidestep it. *) +let test_month_answers_to_both_spellings () = + let v = view_named 2027 in + let jan = List.hd (as_list (get [ "months" ] v)) in + let same a b = + Alcotest.(check string) (a ^ " = " ^ b) (as_str (get [ a ] jan)) + (as_str (get [ b ] jan)) + in + same "name" "month_name"; + same "num" "month_num"; + Alcotest.(check string) "month_name" "Ianuarius" (as_str (get [ "month_name" ] jan)); + Alcotest.(check bool) "month_abbr is present and non-empty" true + (as_str (get [ "month_abbr" ] jan) <> "") + let suite = ( "View", [ Alcotest.test_case "year shape" `Quick test_year_shape; |
