Skip to content

Fix template rendering for skip files and engines #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2021
Merged
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
6 changes: 5 additions & 1 deletion examples/skip-not-path/boilerplate.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
variables:
- name: SkipNotPath
default: "docs"

skip_files:
- not_path: docs/**
- not_path: "{{ .SkipNotPath }}/**"
2 changes: 1 addition & 1 deletion templates/engines_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func processEngines(
) ([]ProcessedEngine, error) {
output := []ProcessedEngine{}
for _, engine := range engines {
matchedPaths, err := renderGlobPath(opts, engine.Path)
matchedPaths, err := renderGlobPath(opts, engine.Path, variables)
if err != nil {
return nil, err
}
Expand Down
16 changes: 12 additions & 4 deletions templates/skip_files_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ type ProcessedSkipFile struct {
func processSkipFiles(skipFiles []variables.SkipFile, opts *options.BoilerplateOptions, variables map[string]interface{}) ([]ProcessedSkipFile, error) {
output := []ProcessedSkipFile{}
for _, skipFile := range skipFiles {
matchedPaths, err := renderGlobPath(opts, skipFile.Path)
matchedPaths, err := renderGlobPath(opts, skipFile.Path, variables)
if err != nil {
return nil, errors.WithStackTrace(err)
}
if skipFile.Path != "" {
debugLogForMatchedPaths(skipFile.Path, matchedPaths, "SkipFile", "Path")
}

matchedNotPaths, err := renderGlobPath(opts, skipFile.NotPath)
matchedNotPaths, err := renderGlobPath(opts, skipFile.NotPath, variables)
if err != nil {
return nil, errors.WithStackTrace(err)
}
Expand Down Expand Up @@ -94,13 +94,21 @@ func debugLogForMatchedPaths(sourcePath string, paths []string, directiveName st

// renderGlobPath will render the glob of the given path in the template folder and return the list of matched paths.
// Note that the paths will be canonicalized to unix slashes regardless of OS.
func renderGlobPath(opts *options.BoilerplateOptions, path string) ([]string, error) {
func renderGlobPath(opts *options.BoilerplateOptions, path string, variables map[string]interface{}) ([]string, error) {
if path == "" {
return []string{}, nil
}

rawMatchedPaths, err := zglob.Glob(filepath.Join(opts.TemplateFolder, path))
rendered, err := render.RenderTemplateRecursively(opts.TemplateFolder, path, variables, opts)
if err != nil {
return nil, err
}

globPath := filepath.Join(opts.TemplateFolder, rendered)
rawMatchedPaths, err := zglob.Glob(globPath)
if err != nil {
// TODO: logger-debug - switch to debug
util.Logger.Printf("ERROR: could not glob %s", globPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have logging levels implemented in boilerplate yet. This is a tag to help us track which ones we want to convert to debug logs when we implement it.
I thought we had an issue already for this, but filed a new one #82

return nil, errors.WithStackTrace(err)
}
// Canonicalize the matched paths prior to storage
Expand Down