Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

cowsaydemo.gno

0.88 Kb · 32 lines
 1// Package cowsaydemo is a small gnoweb demo of the cowsay renderer provided by
 2// the [p/moul/x/daily/cowsay](/p/moul/x/daily/cowsay/v0) library: it makes the
 3// ASCII cow say whatever you put in the path.
 4//
 5// It contains no rendering logic of its own — the art comes entirely from
 6// `cowsay.Say`.
 7package cowsaydemo
 8
 9import (
10	"strings"
11
12	"gno.land/p/moul/x/daily/cowsay/v0"
13)
14
15// Render displays the cow for gnoweb.
16//
17//	Render("")             -> default message ("Moo!")
18//	Render("/hello there") -> renders "hello there", word-wrapped
19func Render(path string) string {
20	msg := strings.TrimLeft(path, "/")
21	art := cowsay.Say(msg)
22
23	var b strings.Builder
24	b.WriteString("# cowsay\n\n")
25	if strings.TrimSpace(msg) == "" {
26		b.WriteString("_Tip: pass a message in the path, e.g._ `/Hello, gno.land!`\n\n")
27	}
28	b.WriteString("```\n")
29	b.WriteString(art)
30	b.WriteString("```\n")
31	return b.String()
32}