diff options
Diffstat (limited to 'internal/render/render.go')
| -rw-r--r-- | internal/render/render.go | 69 |
1 files changed, 52 insertions, 17 deletions
diff --git a/internal/render/render.go b/internal/render/render.go index 2807272..b8d778c 100644 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -55,23 +55,9 @@ func GatherVersion(version string, sec liturgy.Section, lectionary string) (labe return label, gatherPL(sec) } - citation := sec.Citation - if citation == "" { - if c, err := liturgy.ExtractCitation(sec.Heading); err == nil { - citation = c - } - } - if citation == "" { - return label, []string{"(brak odwołania)"} - } - - ref := citation - if lectionary == "new" { - r, err := bible.ToEnglishRef(citation, system(version)) - if err != nil { - return label, []string{fmt.Sprintf("(brak odwołania: %v)", err)} - } - ref = r + ref, err := resolveRef(version, sec, lectionary) + if err != nil { + return label, []string{err.Error()} } verses, missing := bible.Lookup(version, ref) @@ -89,6 +75,55 @@ func GatherVersion(version string, sec liturgy.Section, lectionary string) (labe return label, blocks } +// resolveRef resolves a non-"pl" version's bible.Lookup reference for sec: +// sec.Citation (or, failing that, the citation extracted from sec.Heading), +// converted to English/kjv-style via bible.ToEnglishRef when +// lectionary=="new" (a "traditional" citation is already English-style and +// used as-is). Shared by GatherVersion and GatherVerses so both apply the +// exact same resolution. +func resolveRef(version string, sec liturgy.Section, lectionary string) (string, error) { + citation := sec.Citation + if citation == "" { + if c, err := liturgy.ExtractCitation(sec.Heading); err == nil { + citation = c + } + } + if citation == "" { + return "", fmt.Errorf("(brak odwołania)") + } + + if lectionary != "new" { + return citation, nil + } + ref, err := bible.ToEnglishRef(citation, system(version)) + if err != nil { + return "", fmt.Errorf("(brak odwołania: %w)", err) + } + return ref, nil +} + +// GatherVerses returns one version's verses for a section as raw bible.Verse +// structs (for column/interlinear alignment). versified is false for "pl" +// (paragraph text, no verse numbers) and on any resolution/lookup failure -- +// callers fall back to GatherVersion's string blocks for those. +func GatherVerses(version string, sec liturgy.Section, lectionary string) (label string, verses []bible.Verse, versified bool) { + label = versionLabels[version] + if version == "pl" { + return label, nil, false + } + + ref, err := resolveRef(version, sec, lectionary) + if err != nil { + return label, nil, false + } + + verses, _ = bible.Lookup(version, ref) + if len(verses) == 0 { + return label, nil, false + } + return label, verses, true +} + // gatherPL returns the section's paragraphs, one block per paragraph, with // the liturgical incipit ("Słowa Ewangelii według ...") dropped and repeated // blocks (a responsorial psalm's refrain) deduped to their first occurrence. |
