(* emit_xml.ml *)
module T = Template
let escape s = Escape.apply Escape.Xml s
let get v k = match v with T.Obj kvs -> List.assoc_opt k kvs | _ -> None
let s v k = match get v k with Some (T.Str x) -> x | _ -> ""
let el b name value =
Buffer.add_string b (" <" ^ name ^ ">" ^ escape value ^ "" ^ name ^ ">\n")
let day b d =
Buffer.add_string b (" \n");
el b "season" (s d "season");
el b "season_name" (s d "season_name");
el b "week" (s d "week");
el b "slug" (s d "slug");
(* The resolved display name. A single element, no [lang] attribute: the
view's own [name] is now one resolved string, not a lang-keyed object
(view.ml), so there is exactly one to emit rather than one per language. *)
el b "name" (s d "name");
el b "weekday" (s d "weekday");
el b "rank" (s d "rank");
el b "rank_name" (s d "rank_name");
el b "colour" (s d "colour");
el b "colour_name" (s d "colour_name");
el b "subject" (s d "subject");
(match get d "comms" with
| Some (T.List l) ->
List.iter (fun c -> Buffer.add_string b (" " ^ escape (s c "slug") ^ "\n")) l
| _ -> ());
let cite name value =
if value <> "" then
Buffer.add_string b (" " ^ escape value ^ "\n")
in
(* W5: a THIRD element, not a hardcoded pair -- [] is a repeated
element, not a fixed column, so there is no structural reason to leave
[second] out the way [Emit_csv]'s own fixed header row genuinely must
(see that module's own comment). [cite]'s own [value <> ""] guard
already makes this a no-op for every EF day (view.ml's [day_value]
never sets a "second" key for EF at all, so [s d "second"] resolves to
"" through [get]'s own [None -> ""] fallback) -- EF's XML is therefore
unchanged BY CONSTRUCTION, not by a rite check here. *)
cite "first" (s d "first");
cite "second" (s d "second");
cite "gospel" (s d "gospel");
Buffer.add_string b " \n"
let year v =
let b = Buffer.create (128 * 1024) in
Buffer.add_string b "\n";
Buffer.add_string b
("\n");
Buffer.add_string b " \n";
(match get v "days" with Some (T.List l) -> List.iter (day b) l | _ -> ());
Buffer.add_string b " \n\n";
Buffer.contents b