diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/TODO b/TODO new file mode 100644 index 0000000..161eded --- /dev/null +++ b/TODO @@ -0,0 +1,49 @@ +Defining template: +{{ define “template_name” }} {{ end }} + +Using template: +{{ template “template_name” . }} + +Block: +{{ block “content” . }} {{ end }} + +Is equivalent to => {{ template “content” . }} {{ define “content” }} {{ end }} + +If: +{{ if var }} //… {{ else if var }} //… {{ else }} //… {{ end }} + +Assignment: +{{ $first_name := “arash” }} {{ $first_name = .Name }} + +With: +{{ with . Firstname }} // . refers to Firstname {{ end }} + +{{ with $ firstname := .Firstname }} // . and $firstname both refer to Firstname {{ end }} + +Range: +{{ range .Users }} {{ .Firstname }} {{ end }} + +{{ range $user := .Users }} {{ .Firstname }} {{ $user.Firstname }} {{ else }} No users found {{ end }} + +{{ range $index, $user := .Users }} {{ end }} + +Functions: +{{ if and cond1 cond2 … }} + +{{ if or cond1 cond2 … }} + +{{ if not cond }} + +{{ len var }} + +tmpl, _ := template.New(“template_name”).Parse(“...”) + +tmpl.Name() => name of current template + +tmpl.Execute(...) => execute current template + +tmpl.ExecuteTemplate(...) => execute template by name + +tmpl = tmpl.Lookup(“template_name”) => change current template + +tmpl.Templates() => Get defined templates \ No newline at end of file diff --git a/handlers/hbcp.go b/handlers/hbcp.go new file mode 100644 index 0000000..d90c165 --- /dev/null +++ b/handlers/hbcp.go @@ -0,0 +1,19 @@ +package handlers + +import ( + "net/http" + "text/template" + + "github.com/julienschmidt/httprouter" +) + +func HBCPHandler() httprouter.Handle { + return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + t, _ := template.ParseFiles("templates/base.html", "templates/hbcp.html") + err := t.Execute(w, nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } +} diff --git a/handlers/index.go b/handlers/index.go index dfa6242..8ec8ab0 100644 --- a/handlers/index.go +++ b/handlers/index.go @@ -9,7 +9,7 @@ import ( func IndexHandler() httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - t, _ := template.ParseFiles("templates/index.html") + t, _ := template.ParseFiles("templates/base.html", "templates/index.html") err := t.Execute(w, nil) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/routes/routes.go b/routes/routes.go index 8e7c3db..c9604d7 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -8,5 +8,6 @@ import ( func CreateRoutes(r *httprouter.Router, storage storage.Storager) { r.GET("/", handlers.IndexHandler()) + r.GET("/hbcp", handlers.HBCPHandler()) } diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..2c70cc4 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,19 @@ + + + + + + + + + {{ template "title" . }} + + + + + {{ template "body" . }} + + + \ No newline at end of file diff --git a/templates/hbcp.html b/templates/hbcp.html new file mode 100644 index 0000000..948908b --- /dev/null +++ b/templates/hbcp.html @@ -0,0 +1,49 @@ +{{define "title"}}Falcon UI{{end}} + +{{define "body"}} + + + +
+
+
+ +
+
+ +
+
+
+ + + + +{{ end }} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index e87312a..de5601e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,147 +1,136 @@ - - +{{define "title"}}Falcon UI{{end}} - - - - - - Falcon - +{{define "body"}} - - -
-
-
- -
-
- -
-
- -
-
- -
+
+
+
+ +
+
+ + +
+
+
- - - \ No newline at end of file +
+{{ end }} \ No newline at end of file