mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-17 14:30:06 +02:00
Add CurrentURL template variable back (#37444)
Because some custom template users need it, also add a new test and comments
This commit is contained in:
parent
45b4fffae4
commit
b45be5b20d
@ -163,6 +163,7 @@ func Contexter() func(next http.Handler) http.Handler {
|
|||||||
base := NewBaseContext(resp, req)
|
base := NewBaseContext(resp, req)
|
||||||
ctx := NewWebContext(base, rnd, session.GetContextSession(req))
|
ctx := NewWebContext(base, rnd, session.GetContextSession(req))
|
||||||
ctx.Data.MergeFrom(middleware.CommonTemplateContextData())
|
ctx.Data.MergeFrom(middleware.CommonTemplateContextData())
|
||||||
|
ctx.Data["CurrentURL"] = setting.AppSubURL + req.URL.RequestURI()
|
||||||
ctx.Data["Link"] = ctx.Link
|
ctx.Data["Link"] = ctx.Link
|
||||||
|
|
||||||
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules
|
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules
|
||||||
|
|||||||
@ -10,6 +10,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
"code.gitea.io/gitea/modules/web"
|
||||||
|
"code.gitea.io/gitea/services/context"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -21,6 +24,7 @@ func TestView(t *testing.T) {
|
|||||||
t.Run("CommitListActions", testCommitListActions)
|
t.Run("CommitListActions", testCommitListActions)
|
||||||
t.Run("SecurityHeadersDefaults", testSecurityHeadersDefaults)
|
t.Run("SecurityHeadersDefaults", testSecurityHeadersDefaults)
|
||||||
t.Run("SiteManifest", testSiteManifest)
|
t.Run("SiteManifest", testSiteManifest)
|
||||||
|
t.Run("CurrentURL", testViewPageCurrentURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRenderFileSVGIsInImgTag(t *testing.T) {
|
func testRenderFileSVGIsInImgTag(t *testing.T) {
|
||||||
@ -113,3 +117,15 @@ func testSiteManifest(t *testing.T) {
|
|||||||
)
|
)
|
||||||
assert.JSONEq(t, expectedJSON, resp.Body.String())
|
assert.JSONEq(t, expectedJSON, resp.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testViewPageCurrentURL(t *testing.T) {
|
||||||
|
defer test.MockVariableValue(&setting.AppSubURL, "/subpath")()
|
||||||
|
var currentURL string
|
||||||
|
web.RouteMock(web.MockAfterMiddlewares, func(ctx *context.Context) {
|
||||||
|
// Some custom template users need this template variable to construct links in their templates
|
||||||
|
currentURL, _ = ctx.Data["CurrentURL"].(string)
|
||||||
|
})
|
||||||
|
defer web.RouteMockReset()
|
||||||
|
MakeRequest(t, NewRequest(t, "GET", "/any-page?k=v"), http.StatusNotFound)
|
||||||
|
assert.Equal(t, "/subpath/any-page?k=v", currentURL)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user