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

Commit

Permalink
replace filepath with path for URL-ish internal expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed May 14, 2022
1 parent 71fb47a commit 1112def
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 6 additions & 7 deletions render/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"net/http"
"path"
"path/filepath"
"reflect"
"strings"

Expand Down Expand Up @@ -117,34 +116,34 @@ func (ir htmlAutoRenderer) Render(w io.Writer, data Data) error {
}

if data["method"] == "PUT" {
return ir.HTML(filepath.Join(templatePrefix.String(), "edit.html")).Render(w, data)
return ir.HTML(path.Join(templatePrefix.String(), "edit.html")).Render(w, data)
}

return ir.HTML(filepath.Join(templatePrefix.String(), "new.html")).Render(w, data)
return ir.HTML(path.Join(templatePrefix.String(), "new.html")).Render(w, data)
}
return nil
}

cp, ok := data["current_path"].(string)

defCase := func() error {
return ir.HTML(filepath.Join(templatePrefix.String(), "index.html")).Render(w, data)
return ir.HTML(path.Join(templatePrefix.String(), "index.html")).Render(w, data)
}

if !ok {
return defCase()
}

if strings.HasSuffix(cp, "/edit/") {
return ir.HTML(filepath.Join(templatePrefix.String(), "edit.html")).Render(w, data)
return ir.HTML(path.Join(templatePrefix.String(), "edit.html")).Render(w, data)
}

if strings.HasSuffix(cp, "/new/") {
return ir.HTML(filepath.Join(templatePrefix.String(), "new.html")).Render(w, data)
return ir.HTML(path.Join(templatePrefix.String(), "new.html")).Render(w, data)
}

if !isPlural {
return ir.HTML(filepath.Join(templatePrefix.String(), "show.html")).Render(w, data)
return ir.HTML(path.Join(templatePrefix.String(), "show.html")).Render(w, data)
}

return defCase()
Expand Down
7 changes: 5 additions & 2 deletions render/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"html/template"
"io"
"path"
"path/filepath"

ht "github.com/gobuffalo/helpers/tags"
Expand Down Expand Up @@ -49,7 +50,7 @@ func assetPathFor(file string) string {
if filePath == "" || !ok {
filePath = file
}
return filepath.ToSlash(filepath.Join("/assets", filePath))
return path.Join("/assets", filePath)
}

func loadManifest(manifest io.Reader) error {
Expand All @@ -59,7 +60,9 @@ func loadManifest(manifest io.Reader) error {
return err
}
for k, v := range m {
assetMap.Store(k, v)
// I don't think v has backslash but if so, correct them when
// creating the map instead using the value in `assetPathFor()`.
assetMap.Store(k, filepath.ToSlash(v))
}
return nil
}

0 comments on commit 1112def

Please sign in to comment.