ytdl-web/pkg/view/html/options.go

55 lines
960 B
Go
Raw Permalink Normal View History

2023-08-12 23:27:11 -04:00
package html
import (
"fmt"
"html/template"
)
type Options struct {
LeftDelim string
RightDelim string
Extension string
BaseDir string
FuncMap template.FuncMap
}
func DefaultOptions() *Options {
return &Options{
LeftDelim: "{{",
RightDelim: "}}",
Extension: ".html",
BaseDir: "/",
FuncMap: template.FuncMap{
"yield": func() error { return fmt.Errorf("yield called outside of a layout") },
},
}
}
func (o *Options) WithDelimiters(left, right string) *Options {
o.LeftDelim = left
o.RightDelim = right
return o
}
func (o *Options) WithExtension(ext string) *Options {
o.Extension = ext
return o
}
func (o *Options) WithBaseDir(dir string) *Options {
o.BaseDir = dir
return o
}
func (o *Options) WithFunction(name string, fn interface{}) *Options {
o.FuncMap[name] = fn
return o
}
func (o *Options) WithFunctions(funcs template.FuncMap) *Options {
for k, v := range funcs {
o.FuncMap[k] = v
}
return o
}