providers/path: Add functions to check if a file is hidden
This commit is contained in:
parent
b7952cf8eb
commit
5e3421a0a7
@ -1,10 +1,13 @@
|
|||||||
package path
|
package path
|
||||||
|
|
||||||
import "path"
|
import "path"
|
||||||
// import "strings"
|
import "strings"
|
||||||
import "html/template"
|
import "html/template"
|
||||||
|
import "path/filepath"
|
||||||
import "git.tebibyte.media/sashakoshka/step"
|
import "git.tebibyte.media/sashakoshka/step"
|
||||||
|
|
||||||
|
const hiddenPrefix = "."
|
||||||
|
|
||||||
var _ step.FuncProvider = new(Provider)
|
var _ step.FuncProvider = new(Provider)
|
||||||
|
|
||||||
// Provider provides path functions.
|
// Provider provides path functions.
|
||||||
@ -15,11 +18,21 @@ type Provider struct {
|
|||||||
// FuncMap fulfills the step.FuncProvider interface.
|
// FuncMap fulfills the step.FuncProvider interface.
|
||||||
func (this *Provider) FuncMap () template.FuncMap {
|
func (this *Provider) FuncMap () template.FuncMap {
|
||||||
return template.FuncMap {
|
return template.FuncMap {
|
||||||
|
"isHidden": funcIsHidden,
|
||||||
|
"osIsHidden": funcOSIsHidden,
|
||||||
"joinPaths": funcJoinPaths,
|
"joinPaths": funcJoinPaths,
|
||||||
"osJoinPaths": funcOSJoinPaths,
|
"osJoinPaths": funcOSJoinPaths,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func funcIsHidden (name string) bool {
|
||||||
|
return strings.HasPrefix(path.Base(name), hiddenPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func funcOSIsHidden (name string) bool {
|
||||||
|
return strings.HasPrefix(filepath.Base(name), hiddenPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
func funcJoinPaths (left, right string) string {
|
func funcJoinPaths (left, right string) string {
|
||||||
return path.Join(left, right)
|
return path.Join(left, right)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user