Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Image tag, plugin search #815

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ type List map[string]Commands
// * file/command must respond to `available` and return JSON of
// plugins.Commands{}
//
// Caveats:
// * The C:\Windows directory is excluded
// Limit full path scan with direct plugin path
func Available() (List, error) {
list := List{}
paths := []string{"plugins"}
if runtime.GOOS == "windows" {
paths = append(paths, strings.Split(os.Getenv("PATH"), ";")...)
} else {
paths = append(paths, strings.Split(os.Getenv("PATH"), ":")...)
}
paths = append(paths, strings.Split(os.Getenv("BUFFALO_PLUGIN_PATH"), ";")...)
for _, p := range paths {
if strings.HasPrefix(strings.ToLower(p), `c:\windows`) {
continue
}
if _, err := os.Stat(p); err != nil {
continue
}
Expand Down
18 changes: 18 additions & 0 deletions render/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func (s templateRenderer) addAssetsHelpers(helpers Helpers) Helpers {
return cssTag(h, options), nil
}

helpers["imgTag"] = func(file string, options tags.Options) (template.HTML, error) {
h, err := s.assetPath(file)
if err != nil {
return "", errors.WithStack(err)
}
return imgTag(h, options), nil
}
return helpers
}

Expand Down Expand Up @@ -91,3 +98,14 @@ func cssTag(href string, options tags.Options) template.HTML {

return cssTag.HTML()
}

func imgTag(src string, options tags.Options) template.HTML {
if options == nil {
options = tags.Options{}
}

options["src"] = src
imgTag := tags.New("img", options)

return imgTag.HTML()
}