mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
Allow to specify baseDir
This commit is contained in:
parent
7b1700ba3f
commit
0e6cc54ed9
7 changed files with 15 additions and 19 deletions
|
|
@ -16,16 +16,16 @@ type Controllers struct {
|
|||
}
|
||||
|
||||
// New returns a new group of controllers
|
||||
func New(app *app.App) *Controllers {
|
||||
func New(app *app.App, baseDir string) *Controllers {
|
||||
log.Info(app.Config.PageTemplateDir)
|
||||
|
||||
c := Controllers{}
|
||||
|
||||
c.Users = NewUsers(app)
|
||||
c.Users = NewUsers(app, baseDir)
|
||||
c.Notes = NewNotes(app)
|
||||
c.Books = NewBooks(app)
|
||||
c.Sync = NewSync(app)
|
||||
c.Static = NewStatic(app)
|
||||
c.Static = NewStatic(app, baseDir)
|
||||
c.Health = NewHealth(app)
|
||||
|
||||
return &c
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import (
|
|||
)
|
||||
|
||||
// NewStatic creates a new Static controller.
|
||||
func NewStatic(app *app.App) *Static {
|
||||
func NewStatic(app *app.App, baseDir string) *Static {
|
||||
return &Static{
|
||||
NotFoundView: views.NewView(app, views.Config{Title: "Not Found", Layout: "base"}, "static/not_found"),
|
||||
NotFoundView: views.NewView(baseDir, app, views.Config{Title: "Not Found", Layout: "base"}, "static/not_found"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func MustNewServer(t *testing.T, appParams *app.App) *httptest.Server {
|
|||
func NewServer(appParams *app.App) (*httptest.Server, error) {
|
||||
a := app.NewTest(appParams)
|
||||
|
||||
ctl := New(&a)
|
||||
ctl := New(&a, a.Config.PageTemplateDir)
|
||||
rc := RouteConfig{
|
||||
WebRoutes: NewWebRoutes(&a, ctl),
|
||||
APIRoutes: NewAPIRoutes(&a, ctl),
|
||||
|
|
|
|||
|
|
@ -33,29 +33,29 @@ var commonHelpers = map[string]interface{}{
|
|||
|
||||
// NewUsers creates a new Users controller.
|
||||
// It panics if the necessary templates are not parsed.
|
||||
func NewUsers(app *app.App) *Users {
|
||||
func NewUsers(app *app.App, baseDir string) *Users {
|
||||
return &Users{
|
||||
NewView: views.NewView(app,
|
||||
NewView: views.NewView(baseDir, app,
|
||||
views.Config{Title: "Join", Layout: "base", HelperFuncs: commonHelpers, AlertInBody: true},
|
||||
"users/new",
|
||||
),
|
||||
LoginView: views.NewView(app,
|
||||
LoginView: views.NewView(baseDir, app,
|
||||
views.Config{Title: "Sign In", Layout: "base", HelperFuncs: commonHelpers, AlertInBody: true},
|
||||
"users/login",
|
||||
),
|
||||
PasswordResetView: views.NewView(app,
|
||||
PasswordResetView: views.NewView(baseDir, app,
|
||||
views.Config{Title: "Reset Password", Layout: "base", HelperFuncs: commonHelpers, AlertInBody: true},
|
||||
"users/password_reset",
|
||||
),
|
||||
PasswordResetConfirmView: views.NewView(app,
|
||||
PasswordResetConfirmView: views.NewView(baseDir, app,
|
||||
views.Config{Title: "Reset Password", Layout: "base", HelperFuncs: commonHelpers, AlertInBody: true},
|
||||
"users/password_reset_confirm",
|
||||
),
|
||||
SettingView: views.NewView(app,
|
||||
SettingView: views.NewView(baseDir, app,
|
||||
views.Config{Layout: "base", HelperFuncs: commonHelpers, HeaderTemplate: "navbar"},
|
||||
"users/settings",
|
||||
),
|
||||
AboutView: views.NewView(app,
|
||||
AboutView: views.NewView(baseDir, app,
|
||||
views.Config{Title: "About", Layout: "base", HelperFuncs: commonHelpers, HeaderTemplate: "navbar"},
|
||||
"users/settings_about",
|
||||
),
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func startCmd() {
|
|||
panic(errors.Wrap(err, "running job"))
|
||||
}
|
||||
|
||||
ctl := controllers.New(&app)
|
||||
ctl := controllers.New(&app, *pageDir)
|
||||
rc := controllers.RouteConfig{
|
||||
WebRoutes: controllers.NewWebRoutes(&app, ctl),
|
||||
APIRoutes: controllers.NewAPIRoutes(&app, ctl),
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@ func (c Config) getClock() clock.Clock {
|
|||
}
|
||||
|
||||
// NewView returns a new view by parsing the given layout and files
|
||||
func NewView(app *app.App, viewConfig Config, files ...string) *View {
|
||||
baseDir := app.Config.PageTemplateDir
|
||||
func NewView(baseDir string, app *app.App, viewConfig Config, files ...string) *View {
|
||||
addTemplatePath(baseDir, files)
|
||||
addTemplateExt(files)
|
||||
|
||||
|
|
@ -138,9 +137,6 @@ func (v *View) Render(w http.ResponseWriter, r *http.Request, data *Data, status
|
|||
vd.Yield["CurrentPath"] = r.URL.Path
|
||||
vd.Yield["Standalone"] = buildinfo.Standalone
|
||||
|
||||
fmt.Println("######")
|
||||
fmt.Println(vd.Alert)
|
||||
|
||||
var buf bytes.Buffer
|
||||
csrfField := csrf.TemplateField(r)
|
||||
tpl := v.Template.Funcs(template.FuncMap{
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue