-
Notifications
You must be signed in to change notification settings - Fork 20
/
individual_name_and_sex.go
59 lines (49 loc) 路 1.53 KB
/
individual_name_and_sex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
)
// IndividualNameAndSex shows the name parts and sex of an individual in the
// "Name & Sex" section of the individuals page.
type IndividualNameAndSex struct {
individual *gedcom.IndividualNode
}
func NewIndividualNameAndSex(individual *gedcom.IndividualNode) *IndividualNameAndSex {
return &IndividualNameAndSex{
individual: individual,
}
}
func (c *IndividualNameAndSex) WriteHTMLTo(w io.Writer) (int64, error) {
primaryName := c.individual.Names()[0]
title := primaryName.Title()
prefix := primaryName.Prefix()
name := primaryName.GivenName()
surnamePrefix := primaryName.SurnamePrefix()
surname := primaryName.Surname()
suffix := primaryName.Suffix()
titleRow := keyedRow("Title", title)
prefixRow := keyedRow("Prefix", prefix)
givenNameRow := keyedRow("Given Name", name)
surnamePrefixRow := keyedRow("Surname Prefix", surnamePrefix)
surnameRow := keyedRow("Surname", surname)
suffixRow := keyedRow("Suffix", suffix)
sexBadge := NewSexBadge(c.individual.Sex())
sexRow := core.NewKeyedTableRow("Sex", sexBadge, true)
s := core.NewComponents(
titleRow,
prefixRow,
givenNameRow,
surnamePrefixRow,
surnameRow,
suffixRow,
sexRow,
)
return core.NewCard(core.NewText("Name & Sex"), core.CardNoBadgeCount,
core.NewTable("", s)).WriteHTMLTo(w)
}
func keyedRow(title, value string) *core.KeyedTableRow {
text := core.NewText(value)
visible := value != ""
return core.NewKeyedTableRow(title, text, visible)
}