From 41535303d928d5d4d279a1e18fd59b6dfacd4050 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Thu, 27 Apr 2023 16:39:55 +0200 Subject: [PATCH] feat: add ui.Jumbotron --- examples/gno.land/p/demo/ui/ui.gno | 20 ++++++++++++++++++++ examples/gno.land/p/demo/ui/ui_test.gno | 22 ++++++++++++++++++++++ examples/gno.land/r/demo/ui/ui.gno | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/examples/gno.land/p/demo/ui/ui.gno b/examples/gno.land/p/demo/ui/ui.gno index 57c172d8b6a..c88b8877b58 100644 --- a/examples/gno.land/p/demo/ui/ui.gno +++ b/examples/gno.land/p/demo/ui/ui.gno @@ -123,3 +123,23 @@ func Bold(text string) stringer { return Raw{Content: "**" + text + "**"} } func Italic(text string) stringer { return Raw{Content: "_" + text + "_"} } func Code(text string) stringer { return Raw{Content: "`" + text + "`"} } func HR() stringer { return Raw{Content: "\n---\n"} } + +// Extension represents a custom markdown wrapped between `:::`. +type Extension struct { + Name string + Content Element +} + +func (e Extension) String() string { + return ":::" + e.Name + "\n" + e.Content.Content + ":::\n" +} + +func Jumbotron(content ...stringer) stringer { + j := Extension{ + Name: "jumbotron", + } + for _, c := range content { + j.Content.Append(c) + } + return j +} diff --git a/examples/gno.land/p/demo/ui/ui_test.gno b/examples/gno.land/p/demo/ui/ui_test.gno index 5b1faa2932c..4a75f9b62a0 100644 --- a/examples/gno.land/p/demo/ui/ui_test.gno +++ b/examples/gno.land/p/demo/ui/ui_test.gno @@ -1 +1,23 @@ package ui + +import ( + "testing" +) + +func TestJumbotron(t *testing.T) { + j := Jumbotron( + H1("Hello Jumbo"), + Text("This is a jumbotron, a markdown extension"), + ) + + want := `:::jumbotron +# Hello Jumbo + +This is a jumbotron, a markdown extension +::: +` + got := j.String() + if got != want { + t.Errorf("want=%s, got=%s", want, got) + } +} diff --git a/examples/gno.land/r/demo/ui/ui.gno b/examples/gno.land/r/demo/ui/ui.gno index 34c387c5083..5cbd2cb37ae 100644 --- a/examples/gno.land/r/demo/ui/ui.gno +++ b/examples/gno.land/r/demo/ui/ui.gno @@ -24,6 +24,10 @@ func Render(path string) string { )) dom.Body.Append( + ui.Jumbotron( + ui.H1("Hello Jumbo"), + ui.Text("This is a jumbotron, a markdown extension"), + ), ui.Paragraph("Simple UI demonstration."), ui.BulletList( ui.Text("a text"),