Skip to content

Commit

Permalink
feat: add ui.Jumbotron
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Apr 27, 2023
1 parent 73e66ea commit 4153530
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/gno.land/p/demo/ui/ui.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
22 changes: 22 additions & 0 deletions examples/gno.land/p/demo/ui/ui_test.gno
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions examples/gno.land/r/demo/ui/ui.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 4153530

Please sign in to comment.