From 44b18894ac0195767a5882372a011be328000f40 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Tue, 17 Nov 2020 14:50:42 +0100 Subject: Add example with dot imports (#47) --- examples/dot-import/dot-import.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/dot-import/dot-import.go (limited to 'examples') diff --git a/examples/dot-import/dot-import.go b/examples/dot-import/dot-import.go new file mode 100644 index 0000000..be3bd50 --- /dev/null +++ b/examples/dot-import/dot-import.go @@ -0,0 +1,37 @@ +package main + +import ( + "net/http" + + . "github.com/maragudk/gomponents" + . "github.com/maragudk/gomponents/components" + . "github.com/maragudk/gomponents/el" +) + +func main() { + _ = http.ListenAndServe("localhost:8080", http.HandlerFunc(handler)) +} + +func handler(w http.ResponseWriter, r *http.Request) { + p := page(props{ + title: r.URL.Path, + path: r.URL.Path, + }) + _ = p.Render(w) +} + +type props struct { + title string + path string +} + +func page(p props) Node { + return HTML5(DocumentProps{ + Title: p.title, + Language: "en", + Body: []Node{ + H1(p.title), + P(Textf("Welcome to the page at %v.", p.path)), + }, + }) +} -- cgit 1.4.1