about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-11-17 14:50:42 +0100
committerGitHub2020-11-17 14:50:42 +0100
commit44b18894ac0195767a5882372a011be328000f40 (patch)
tree2ad6e5d855efa216c4d5596a943ab14978b6fcd3
parent633b000d9115dbf7d4cc072cb1349268a09c3375 (diff)
downloadgomponents-44b18894ac0195767a5882372a011be328000f40.tar.lz
gomponents-44b18894ac0195767a5882372a011be328000f40.tar.zst
gomponents-44b18894ac0195767a5882372a011be328000f40.zip
Add example with dot imports (#47)
-rw-r--r--examples/dot-import/dot-import.go37
1 files changed, 37 insertions, 0 deletions
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)),
+		},
+	})
+}