summaryrefslogtreecommitdiff
path: root/internal/render
diff options
context:
space:
mode:
Diffstat (limited to 'internal/render')
-rw-r--r--internal/render/render.go69
-rw-r--r--internal/render/render_test.go31
2 files changed, 83 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.
diff --git a/internal/render/render_test.go b/internal/render/render_test.go
index 87f9ed2..1b338a0 100644
--- a/internal/render/render_test.go
+++ b/internal/render/render_test.go
@@ -51,3 +51,34 @@ func TestOfflineVersions(t *testing.T) {
}
}
}
+
+func TestGatherVersesBible(t *testing.T) {
+ sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"}
+ label, verses, versified := GatherVerses("wuj", sec, "new")
+ if !strings.Contains(label, "Wujek") {
+ t.Errorf("label = %q", label)
+ }
+ if !versified {
+ t.Error("versified = false, want true for wuj with a resolvable citation")
+ }
+ if len(verses) == 0 {
+ t.Fatal("verses empty")
+ }
+ if verses[0].Chapter != 20 || verses[0].Verse != 1 || verses[0].Text == "" {
+ t.Errorf("verses[0] = %+v", verses[0])
+ }
+}
+
+func TestGatherVersesPL(t *testing.T) {
+ sec := liturgy.Section{
+ Heading: "Psalm (Ps 1)",
+ Paragraphs: [][]string{{"stanza one"}},
+ }
+ _, verses, versified := GatherVerses("pl", sec, "new")
+ if versified {
+ t.Error("versified = true, want false for pl (paragraph text, no verse numbers)")
+ }
+ if verses != nil {
+ t.Errorf("verses = %+v, want nil for pl", verses)
+ }
+}