39 lines
840 B
Go
39 lines
840 B
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"io/fs"
|
|
|
|
"source.toby3d.me/toby3d/home/internal/domain"
|
|
"source.toby3d.me/toby3d/home/internal/templateutil"
|
|
"source.toby3d.me/toby3d/home/internal/theme"
|
|
)
|
|
|
|
type themeUseCase struct {
|
|
partials fs.FS
|
|
themes theme.Repository
|
|
}
|
|
|
|
func NewThemeUseCase(partials fs.FS, themes theme.Repository) theme.UseCase {
|
|
return &themeUseCase{
|
|
partials: partials,
|
|
themes: themes,
|
|
}
|
|
}
|
|
|
|
func (ucase *themeUseCase) Do(ctx context.Context, site *domain.Site, page *domain.Page) (theme.Writer, error) {
|
|
out, err := ucase.themes.Get(ctx, templateutil.New(ucase.partials, site))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot find theme: %w", err)
|
|
}
|
|
|
|
return func(w io.Writer) error {
|
|
return out.Lookup("baseof.html").Execute(w, &domain.Context{
|
|
Site: site,
|
|
Page: page,
|
|
})
|
|
}, nil
|
|
}
|