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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

Playground

escape_test.gno

package piglatindemo

import (
	"testing"

	"gno.land/p/nt/uassert/v0"
)

// payload closes a one-backtick code span and opens an image. Written raw, as
// v0 does, it renders as markup the realm appears to have authored.
const payload = "x` ![p](https:e.io) `y"

// TestRenderEscapesSentence pins that the sentence and its translation are
// escaped inside their blockquotes: v0 wrote both raw, so an image or a link
// in the path rendered, and Translate keeps punctuation in place.
func TestRenderEscapesSentence(t *testing.T) {
	uassert.Equal(t, "# Pig Latin\n\n**Original:**\n\n> x\\` \\!\\[p\\]\\(https:e\\.io\\) \\`y\n\n**Pig Latin:**\n\n> xay\\` \\!\\[e\\.iop\\]\\(https:ay\\) \\`yay\n\n---\n\n[← rules & examples](/r/moul/x/daily/piglatindemo/v1)\n", Render("/"+payload))
}

gnomod.toml

module = "gno.land/r/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/daily/piglatindemo/v1"
gno = "0.9"
private = true

[addpkg]
  creator = "g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv"
  height = 914308
  max_deposit = "5000000ugnot"

piglatindemo.gno

// Package piglatindemo is a small gnoweb demo of the Pig Latin translator
// provided by the [p/moul/x/daily/piglatin](/p/moul/x/daily/piglatin/v0)
// library: it renders the rules, a gallery of worked examples, and an
// interactive sentence translator.
//
// It contains no translation logic of its own — everything comes from
// `piglatin.Translate` and `piglatin.TranslateToken`.
package piglatindemo

import (
	"strings"

	"gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/kit/ui/v0"
	"gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/daily/piglatin/v0"
)

// Render is the gnoweb entrypoint (Markdown). Root explains the rules; any
// other path is treated as a sentence to translate, e.g. Render("/Hello world").
func Render(path string) string {
	var b strings.Builder

	sentence := strings.TrimPrefix(path, "/")
	sentence = strings.TrimSpace(sentence)

	if sentence == "" {
		b.WriteString("# Pig Latin\n\n")
		b.WriteString("Demo of the [`p/moul/x/daily/piglatin`](/p/moul/x/daily/piglatin/v0) ")
		b.WriteString("library — a tiny port of the classic **Pig Latin** translator ")
		b.WriteString("(the go-to beginner exercise). Pure `strings`/`unicode`, fully deterministic.\n\n")
		b.WriteString("## Rules\n\n")
		b.WriteString("1. Word starts with a **vowel** → append `way`. `apple` → `appleway`\n")
		b.WriteString("2. Word starts with **consonant(s)** → move the leading consonant cluster to the end, then add `ay`. `string` → `ingstray`\n")
		b.WriteString("3. `y` is a consonant only as the first letter (`yellow` → `ellowyay`); otherwise a vowel (`myth` → `ythmay`).\n")
		b.WriteString("4. **Capitalization** is preserved: `Hello` → `Ellohay`, `NASA` → `ASANAY`.\n")
		b.WriteString("5. **Punctuation** glued to a word stays put: `Hello,` → `Ellohay,`.\n\n")
		b.WriteString("## Try it\n\n")
		b.WriteString("Append a sentence to the path — spaces are fine:\n\n")
		for _, ex := range []string{"hello world", "The quick brown fox", "I love Gno!"} {
			b.WriteString("- [`/")
			b.WriteString(ex)
			b.WriteString("`](/r/moul/x/daily/piglatindemo/v1:/")
			b.WriteString(ex)
			b.WriteString(") → `")
			b.WriteString(piglatin.Translate(ex))
			b.WriteString("`\n")
		}
		b.WriteString("\n## Examples\n\n")
		b.WriteString("| Input | Pig Latin |\n|---|---|\n")
		for _, w := range []string{"pig", "banana", "smile", "eat", "yellow", "myth", "Hello,", "GNO"} {
			b.WriteString("| `")
			b.WriteString(w)
			b.WriteString("` | `")
			b.WriteString(piglatin.TranslateToken(w))
			b.WriteString("` |\n")
		}
		return b.String()
	}

	b.WriteString("# Pig Latin\n\n")
	b.WriteString("**Original:**\n\n> ")
	b.WriteString(ui.Inline(sentence))
	b.WriteString("\n\n**Pig Latin:**\n\n> ")
	b.WriteString(ui.Inline(piglatin.Translate(sentence)))
	b.WriteString("\n\n---\n\n[← rules & examples](/r/moul/x/daily/piglatindemo/v1)\n")
	return b.String()
}

render_example_test.gno

package piglatindemo

// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
	print(Render(""))
	// Output:
	// # Pig Latin
	//
	// Demo of the [`p/moul/x/daily/piglatin`](/p/moul/x/daily/piglatin/v0) library — a tiny port of the classic **Pig Latin** translator (the go-to beginner exercise). Pure `strings`/`unicode`, fully deterministic.
	//
	// ## Rules
	//
	// 1. Word starts with a **vowel** → append `way`. `apple` → `appleway`
	// 2. Word starts with **consonant(s)** → move the leading consonant cluster to the end, then add `ay`. `string` → `ingstray`
	// 3. `y` is a consonant only as the first letter (`yellow` → `ellowyay`); otherwise a vowel (`myth` → `ythmay`).
	// 4. **Capitalization** is preserved: `Hello` → `Ellohay`, `NASA` → `ASANAY`.
	// 5. **Punctuation** glued to a word stays put: `Hello,` → `Ellohay,`.
	//
	// ## Try it
	//
	// Append a sentence to the path — spaces are fine:
	//
	// - [`/hello world`](/r/moul/x/daily/piglatindemo/v1:/hello world) → `ellohay orldway`
	// - [`/The quick brown fox`](/r/moul/x/daily/piglatindemo/v1:/The quick brown fox) → `Ethay uickqay ownbray oxfay`
	// - [`/I love Gno!`](/r/moul/x/daily/piglatindemo/v1:/I love Gno!) → `Iway ovelay Ognay!`
	//
	// ## Examples
	//
	// | Input | Pig Latin |
	// |---|---|
	// | `pig` | `igpay` |
	// | `banana` | `ananabay` |
	// | `smile` | `ilesmay` |
	// | `eat` | `eatway` |
	// | `yellow` | `ellowyay` |
	// | `myth` | `ythmay` |
	// | `Hello,` | `Ellohay,` |
	// | `GNO` | `OGNAY` |
}