2019-09-02 18:42:27 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-02-29 16:51:32 -07:00
|
|
|
"time"
|
2020-08-17 17:43:57 -06:00
|
|
|
|
|
|
|
"github.com/spf13/afero"
|
2019-09-02 18:42:27 -06:00
|
|
|
)
|
|
|
|
|
2020-08-17 17:43:57 -06:00
|
|
|
// Theme defines a filesystem-backed ThemeProvider.
|
2019-09-02 18:42:27 -06:00
|
|
|
type Theme struct {
|
2020-02-29 16:51:32 -07:00
|
|
|
afero.Fs
|
2019-09-02 18:42:27 -06:00
|
|
|
}
|
|
|
|
|
2020-08-17 17:43:57 -06:00
|
|
|
// NewTheme returns a new Theme, backed by Fs.
|
2019-12-05 22:25:03 -07:00
|
|
|
func NewTheme(fs afero.Fs) *Theme {
|
2019-09-02 18:42:27 -06:00
|
|
|
return &Theme{
|
2020-02-29 16:51:32 -07:00
|
|
|
Fs: fs,
|
2019-09-02 18:42:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 17:43:57 -06:00
|
|
|
// Open returns a new opened file.
|
2020-03-01 16:10:55 -07:00
|
|
|
func (t *Theme) Open(name string) (ReadSeekCloser, time.Time, error) {
|
|
|
|
f, err := t.Fs.Open(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, time.Time{}, err
|
|
|
|
}
|
2020-08-17 17:43:57 -06:00
|
|
|
|
2020-03-01 16:10:55 -07:00
|
|
|
fi, err := f.Stat()
|
|
|
|
if err != nil {
|
|
|
|
f.Close()
|
|
|
|
return nil, time.Time{}, err
|
2019-09-02 18:42:27 -06:00
|
|
|
}
|
2020-08-17 17:43:57 -06:00
|
|
|
|
2020-03-01 16:10:55 -07:00
|
|
|
return f, fi.ModTime(), nil
|
2020-02-29 16:51:32 -07:00
|
|
|
}
|
2019-09-02 18:42:27 -06:00
|
|
|
|
2020-08-18 17:04:23 -06:00
|
|
|
// Maintain performs housekeeping for a Theme.
|
|
|
|
func (t *Theme) Maintain(i time.Duration) {
|
2020-02-29 16:51:32 -07:00
|
|
|
// No periodic tasks for a theme
|
2019-09-02 18:42:27 -06:00
|
|
|
}
|