package slice import "html/template" import "github.com/gabriel-vasile/mimetype" import "git.tebibyte.media/sashakoshka/step" const hiddenPrefix = "." var _ step.FuncProvider = new(Provider) // Provider provides MIME functions. type Provider struct { } // FuncMap fulfills the step.FuncProvider interface. func (this *Provider) FuncMap () template.FuncMap { return nil } // FuncMapFor fulfills the step.FuncProviderFor interface. func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap { stat := &state { document: document, } return template.FuncMap { "fileContentType": stat.funcFileContentType, } } type state struct { document *step.Document } func (this *state) funcFileContentType (name string) (string, error) { name, err := this.document.Rel(name) if err != nil { return "", err } typ, err := mimetype.DetectFile(name) if err != nil { return "", err } return typ.String(), err }