elliotchance/gedcom

View on GitHub
html/source_list_page.go

Summary

Maintainability
A
35 mins
Test Coverage
package html

import (
    "io"

    "github.com/elliotchance/gedcom/v39"
    "github.com/elliotchance/gedcom/v39/html/core"
)

type SourceListPage struct {
    document          *gedcom.Document
    googleAnalyticsID string
    options           *PublishShowOptions
    indexLetters      []rune
    placesMap         map[string]*place
}

func NewSourceListPage(document *gedcom.Document, googleAnalyticsID string, options *PublishShowOptions, indexLetters []rune, placesMap map[string]*place) *SourceListPage {
    return &SourceListPage{
        document:          document,
        googleAnalyticsID: googleAnalyticsID,
        options:           options,
        indexLetters:      indexLetters,
        placesMap:         placesMap,
    }
}

func (c *SourceListPage) WriteHTMLTo(w io.Writer) (int64, error) {
    table := []core.Component{
        core.NewTableHead("Name"),
    }

    for _, source := range c.document.Sources() {
        table = append(table, NewSourceInList(c.document, source))
    }

    return core.NewPage("Sources", core.NewComponents(
        NewPublishHeader(c.document, "", selectedSourcesTab, c.options,
            c.indexLetters, c.placesMap),
        core.NewRow(
            core.NewColumn(core.EntireRow, core.NewTable("", table...)),
        ),
    ), c.googleAnalyticsID).WriteHTMLTo(w)
}