-
Notifications
You must be signed in to change notification settings - Fork 20
/
all_parent_buttons.go
52 lines (43 loc) 路 1.44 KB
/
all_parent_buttons.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
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
)
// AllParentButtons represent one or more families that an individual belongs
// to. These are show as large buttons above the large name of the person in on
// their individual page.
type AllParentButtons struct {
individual *gedcom.IndividualNode
document *gedcom.Document
visibility LivingVisibility
}
func NewAllParentButtons(document *gedcom.Document, individual *gedcom.IndividualNode, visibility LivingVisibility) *AllParentButtons {
return &AllParentButtons{
individual: individual,
document: document,
visibility: visibility,
}
}
func (c *AllParentButtons) WriteHTMLTo(w io.Writer) (int64, error) {
families := c.individual.Families()
components := []core.Component{}
for _, family := range families {
husbandMatches := family.Husband().IsIndividual(c.individual)
wifeMatches := family.Wife().IsIndividual(c.individual)
if husbandMatches || wifeMatches {
continue
}
components = append(components,
NewParentButtons(c.document, family, c.visibility))
}
// If there are no families we still want to show an empty family. We just
// create a dummy family that has no child nodes.
if len(components) == 0 {
familyNode := gedcom.NewDocument().AddFamily("")
components = []core.Component{
NewParentButtons(c.document, familyNode, c.visibility),
}
}
return core.NewComponents(components...).WriteHTMLTo(w)
}