From 21fb29d0eec71f3dd7c12e260af5925d452b238f Mon Sep 17 00:00:00 2001 From: Alexander Kavon Date: Mon, 27 Nov 2023 17:52:06 -0500 Subject: template files for registration page, updated cwd handling, included cwd and config file path in conf struct --- src/auth/routes.go | 4 ++-- src/conf/conf.go | 18 +++++++++++++++--- ui/pages/auth/register.tmpl.html | 16 ++++++++++++++++ ui/templates/base.tmpl.html | 12 ++++++++++++ views/templates/main.tmpl.html | 10 ---------- 5 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 ui/pages/auth/register.tmpl.html create mode 100644 ui/templates/base.tmpl.html delete mode 100644 views/templates/main.tmpl.html diff --git a/src/auth/routes.go b/src/auth/routes.go index 796d123..4f161de 100644 --- a/src/auth/routes.go +++ b/src/auth/routes.go @@ -25,7 +25,7 @@ func Register(s *server.Server) http.HandlerFunc { if err != nil { log.Fatal(err) } - tmpl := template.Must(template.ParseFiles(cwd + "/views/templates/main.tmpl.html")) - tmpl.Execute(w, nil) + tmpl := template.Must(template.ParseFiles(cwd+"/ui/templates/base.tmpl.html", cwd+"/ui/pages/auth/register.tmpl.html")) + tmpl.ExecuteTemplate(w, "base", nil) } } diff --git a/src/conf/conf.go b/src/conf/conf.go index 8abb8a8..969332a 100644 --- a/src/conf/conf.go +++ b/src/conf/conf.go @@ -9,6 +9,8 @@ import ( type ( Conf struct { + cwd string + path string Db Db `toml:"database"` Server Server `toml:"server"` } @@ -28,20 +30,22 @@ type ( func NewConf() *Conf { - workingdir, err := os.Getwd() + cwd, err := os.Getwd() if err != nil { log.Fatal(err) } filepath := os.Getenv("NEWSSTAND_CONFIG_PATH") if filepath == "" { - filepath = workingdir + "/.newsstandrc.toml" + filepath = cwd + "/.newsstandrc.toml" } log.Printf("Config file path: %s", filepath) c := Conf{ + cwd, + filepath, Db{}, Server{ - TemplatePath: workingdir + "/views", + TemplatePath: cwd + "/ui", }, } _, err = toml.DecodeFile(filepath, &c) @@ -52,3 +56,11 @@ func NewConf() *Conf { return &c } + +func (c *Conf) GetCwd() string { + return c.cwd +} + +func (c *Conf) GetPath() string { + return c.path +} diff --git a/ui/pages/auth/register.tmpl.html b/ui/pages/auth/register.tmpl.html new file mode 100644 index 0000000..7dfd7aa --- /dev/null +++ b/ui/pages/auth/register.tmpl.html @@ -0,0 +1,16 @@ +{{define "title"}}Register{{end}} + +{{define "main"}} +

Registration

+
+ + + +
+{{end}} diff --git a/ui/templates/base.tmpl.html b/ui/templates/base.tmpl.html new file mode 100644 index 0000000..4e28bc0 --- /dev/null +++ b/ui/templates/base.tmpl.html @@ -0,0 +1,12 @@ +{{define "base"}} + + + + {{template "title" .}} | newsstand.nyc + + + + {{template "main" .}} + + +{{end}} diff --git a/views/templates/main.tmpl.html b/views/templates/main.tmpl.html deleted file mode 100644 index b6eeb51..0000000 --- a/views/templates/main.tmpl.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - newsstand.nyc - - - -

Wello, Horld!

- - -- cgit v1.2.3