diff options
author | Markus Wüstenberg | 2020-12-10 14:27:10 +0100 |
---|---|---|
committer | GitHub | 2020-12-10 14:27:10 +0100 |
commit | 428a2519eaa8e16767f86b417abd5af007f24fc6 (patch) | |
tree | 7458b63507259b0225c0e41d249aeb7b36ebeff8 /examples/dot-import | |
parent | febffb600db7fbfd81827ded1b8fa3774bf42107 (diff) | |
download | gomponents-428a2519eaa8e16767f86b417abd5af007f24fc6.tar.lz gomponents-428a2519eaa8e16767f86b417abd5af007f24fc6.tar.zst gomponents-428a2519eaa8e16767f86b417abd5af007f24fc6.zip |
Change main example to be the dot-import version (#56)
Diffstat (limited to 'examples/dot-import')
-rw-r--r-- | examples/dot-import/dot-import.go | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/examples/dot-import/dot-import.go b/examples/dot-import/dot-import.go deleted file mode 100644 index d735785..0000000 --- a/examples/dot-import/dot-import.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "net/http" - - g "github.com/maragudk/gomponents" - . "github.com/maragudk/gomponents/components" - . "github.com/maragudk/gomponents/html" -) - -func main() { - _ = http.ListenAndServe("localhost:8080", http.HandlerFunc(handler)) -} - -func handler(w http.ResponseWriter, r *http.Request) { - page := Page("Hi!", r.URL.Path) - _ = page.Render(w) -} - -func Page(title, currentPath string) g.Node { - return HTML5(HTML5Props{ - Title: title, - Language: "en", - Head: []g.Node{ - StyleEl(Type("text/css"), g.Raw(".is-active{ font-weight: bold }")), - }, - Body: []g.Node{ - Navbar(currentPath), - H1(title), - P(g.Textf("Welcome to the page at %v.", currentPath)), - }, - }) -} - -func Navbar(currentPath string) g.Node { - return Nav( - NavbarLink("/", "Home", currentPath), - NavbarLink("/about", "About", currentPath), - ) -} - -func NavbarLink(href, name, currentPath string) g.Node { - return A(Href(href), Classes{"is-active": currentPath == href}, g.Text(name)) -} |