aboutsummaryrefslogtreecommitdiff
path: root/internal/bible/booktable.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/bible/booktable.go')
-rw-r--r--internal/bible/booktable.go46
1 files changed, 29 insertions, 17 deletions
diff --git a/internal/bible/booktable.go b/internal/bible/booktable.go
index ac7ea95..ae005a5 100644
--- a/internal/bible/booktable.go
+++ b/internal/bible/booktable.go
@@ -6,13 +6,13 @@ import (
"sort"
"strings"
- "github.com/pelletier/go-toml/v2"
+ "github.com/lukaszkasprzak/lectio/internal/ini"
)
-// booksFS embeds the built-in default book table (names + abbreviations per UI
-// language). Users override it per book via ~/.config/lectio/books.toml.
+// booksFS embeds the built-in default book table (names + abbreviations per
+// dialect: en/pl/la). Users override it per book via ~/.config/lectio/books.ini.
//
-//go:embed books.toml
+//go:embed books.ini
var booksFS embed.FS
// BookInfo is one book's display data in one dialect, for `lectio --list` and
@@ -23,8 +23,8 @@ type BookInfo struct {
Shortcut string // primary abbreviation in the dialect, e.g. "Jn" / "J"
}
-// BookTable resolves book references and lists books per "dialect" -- a books.toml
-// section, keyed by the same codes as the UI languages ("en"/"pl"). It is built
+// BookTable resolves book references and lists books per "dialect" -- a books.ini
+// section, keyed by dialect ("en"/"pl"/"la"). It is built
// from the embedded default merged with an optional user override.
type BookTable struct {
forms map[string]map[string][]string // dialect -> canonical -> forms (first=shortcut, last=name)
@@ -38,16 +38,16 @@ type BookTable struct {
// It always returns a usable table; a non-nil error means userTOML was present
// but unparseable (the returned table is defaults-only, so callers can warn and
// proceed).
-func LoadBookTable(userTOML []byte) (*BookTable, error) {
+func LoadBookTable(userINI []byte) (*BookTable, error) {
def, err := parseBooks(mustReadEmbedded())
if err != nil {
- return nil, fmt.Errorf("embedded books.toml: %w", err) // our bug, not the user's
+ return nil, fmt.Errorf("embedded books.ini: %w", err) // our bug, not the user's
}
var uerr error
- if len(strings.TrimSpace(string(userTOML))) > 0 {
- user, perr := parseBooks(userTOML)
+ if len(strings.TrimSpace(string(userINI))) > 0 {
+ user, perr := parseBooks(userINI)
if perr != nil {
- uerr = fmt.Errorf("ignoring malformed books.toml: %w", perr)
+ uerr = fmt.Errorf("ignoring malformed books.ini: %w", perr)
} else {
for dialect, books := range user {
if def[dialect] == nil {
@@ -84,20 +84,32 @@ func LoadBookTable(userTOML []byte) (*BookTable, error) {
}
func mustReadEmbedded() []byte {
- b, _ := booksFS.ReadFile("books.toml") // embedded: always present
+ b, _ := booksFS.ReadFile("books.ini") // embedded: always present
return b
}
-// DefaultBooksTOML returns the embedded default books.toml (the seed the
+// DefaultBooksTOML returns the embedded default books.ini (the seed the
// /settings editor shows when the user has no override yet).
-func DefaultBooksTOML() []byte { return mustReadEmbedded() }
+func DefaultBooksINI() []byte { return mustReadEmbedded() }
func parseBooks(data []byte) (map[string]map[string][]string, error) {
- var raw map[string]map[string][]string
- if err := toml.Unmarshal(data, &raw); err != nil {
+ secs, err := ini.Parse(data)
+ if err != nil {
return nil, err
}
- return raw, nil
+ out := map[string]map[string][]string{}
+ for _, s := range secs {
+ if s.Name == "" { // no top-level pairs in the book table
+ continue
+ }
+ if out[s.Name] == nil {
+ out[s.Name] = map[string][]string{}
+ }
+ for _, p := range s.Pairs {
+ out[s.Name][p.Key] = ini.List(p.Val)
+ }
+ }
+ return out, nil
}
// Books returns every book of the dialect in scriptural (canonOrder) order.