Files
sablier/pkg/theme/render.go
Alexis Couvreur fca9c79289 refactor: reorganize code structure (#556)
* refactor: rename providers to Provider

* refactor folders

* fix build cmd

* fix build cmd

* fix build cmd

* fix cmd start
2025-03-10 14:11:40 -04:00

38 lines
816 B
Go

package theme
import (
"fmt"
"github.com/sablierapp/sablier/pkg/version"
"io"
"github.com/sablierapp/sablier/pkg/durations"
)
func (t *Themes) Render(name string, opts Options, writer io.Writer) error {
var instances []Instance
if opts.ShowDetails {
instances = opts.InstanceStates
} else {
instances = []Instance{}
}
options := templateOptions{
DisplayName: opts.DisplayName,
InstanceStates: instances,
SessionDuration: durations.Humanize(opts.SessionDuration),
RefreshFrequency: fmt.Sprintf("%d", int64(opts.RefreshFrequency.Seconds())),
Version: version.Version,
}
tpl := t.themes.Lookup(fmt.Sprintf("%s.html", name))
if tpl == nil {
return ErrThemeNotFound{
Theme: name,
AvailableThemes: t.List(),
}
}
return tpl.Execute(writer, options)
}