From bf1f01b9bf7fcd2a4596a8df9669508573a29b72 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 2 Apr 2019 19:01:36 -0700 Subject: [PATCH] update filter interface --- context.go | 2 +- goldsmith.go | 14 ++++++++++++++ interface.go | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 51c3f33..30cab84 100644 --- a/context.go +++ b/context.go @@ -94,7 +94,7 @@ func (context *Context) step() { } for _, fileFilter := range fileFilters { - if accept, err = fileFilter.Accept(context, inputFile); err != nil { + if accept, err = fileFilter.Accept(inputFile); err != nil { context.goldsmith.fault(fileFilter.Name(), inputFile, err) return } diff --git a/goldsmith.go b/goldsmith.go index afb5a5e..447cde7 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -82,7 +82,20 @@ func (goldsmith *Goldsmith) End(targetDir string) []error { } context := goldsmith.contexts[len(goldsmith.contexts)-1] + +export: for file := range context.outputFiles { + for _, fileFilter := range goldsmith.fileFilters { + accept, err := fileFilter.Accept(file) + if err != nil { + goldsmith.fault(fileFilter.Name(), file, err) + continue export + } + if !accept { + continue export + } + } + goldsmith.exportFile(file) } @@ -103,6 +116,7 @@ func (goldsmith *Goldsmith) storeFile(context *Context, outputFile *File, inputF if goldsmith.fileCache != nil { goldsmith.fileCache.storeFile(context, outputFile, inputFiles) } + } func (goldsmith *Goldsmith) removeUnreferencedFiles() { diff --git a/interface.go b/interface.go index 084f6c3..0337f5c 100644 --- a/interface.go +++ b/interface.go @@ -18,7 +18,7 @@ type Component interface { type Filter interface { Component - Accept(context *Context, file *File) (bool, error) + Accept(file *File) (bool, error) } type Plugin interface {