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

Commit

Permalink
add prefix for render templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Xu Dongyan committed Feb 27, 2023
1 parent 387d22d commit b348f35
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions render/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ type Options struct {
// DefaultContentType instructs the engine what it should fall back to if
// the "content-type" is unknown
DefaultContentType string

// Prefix inherits the global single prefix from buffalo.Options
Prefix string
}
6 changes: 3 additions & 3 deletions render/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,18 @@ func (s *templateRenderer) assetPath(file string) (string, error) {
if err != nil {
manifest, err = s.AssetsFS.Open("assets/manifest.json")
if err != nil {
return assetPathFor(file), nil
return assetPathFor(s.Prefix, file), nil
}
}
defer manifest.Close()

err = loadManifest(manifest)
if err != nil {
return assetPathFor(file), fmt.Errorf("your manifest.json is not correct: %s", err)
return assetPathFor(s.Prefix, file), fmt.Errorf("your manifest.json is not correct: %s", err)
}
}

return assetPathFor(file), nil
return assetPathFor(s.Prefix, file), nil
}

// Template renders the named files using the specified
Expand Down
4 changes: 2 additions & 2 deletions render/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (s *templateRenderer) addAssetsHelpers(helpers Helpers) Helpers {

var assetMap = stringMap{}

func assetPathFor(file string) string {
func assetPathFor(prefix string, file string) string {
filePath, ok := assetMap.Load(file)
if filePath == "" || !ok {
filePath = file
}
return path.Join("/assets", filePath)
return path.Join(prefix, "assets", filePath)
}

func loadManifest(manifest io.Reader) error {
Expand Down

0 comments on commit b348f35

Please sign in to comment.