From 889082fad93961dc404723f09f3698c46312a6c2 Mon Sep 17 00:00:00 2001
From: Leon Hudak <33522493+leohhhn@users.noreply.github.com>
Date: Thu, 21 Nov 2024 15:52:40 +0900
Subject: [PATCH] feat(examples): add source code view doc, add `r/` README
(#3163)
## Description
Related to #3084
Adds a realm that teaches the user about the source code viewer in
`gnoweb`.
It also adds a `r/` root README.
Contributors' checklist...
- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
---------
Co-authored-by: Morgan
---
examples/gno.land/r/README.md | 10 ++++++++++
.../r/docs/{add/add.gno => adder/adder.gno} | 2 +-
.../{add/add_test.gno => adder/adder_test.gno} | 8 ++++----
examples/gno.land/r/docs/{add => adder}/gno.mod | 2 +-
examples/gno.land/r/docs/home/home.gno | 5 +++--
examples/gno.land/r/docs/source/gno.mod | 1 +
examples/gno.land/r/docs/source/source.gno | 17 +++++++++++++++++
7 files changed, 37 insertions(+), 8 deletions(-)
create mode 100644 examples/gno.land/r/README.md
rename examples/gno.land/r/docs/{add/add.gno => adder/adder.gno} (98%)
rename examples/gno.land/r/docs/{add/add_test.gno => adder/adder_test.gno} (74%)
rename examples/gno.land/r/docs/{add => adder}/gno.mod (61%)
create mode 100644 examples/gno.land/r/docs/source/gno.mod
create mode 100644 examples/gno.land/r/docs/source/source.gno
diff --git a/examples/gno.land/r/README.md b/examples/gno.land/r/README.md
new file mode 100644
index 00000000000..b12a996d781
--- /dev/null
+++ b/examples/gno.land/r/README.md
@@ -0,0 +1,10 @@
+# `r/`
+
+This directory primarily contains realms. It further branches out into namespaces:
+- `demo` - realms meant to demonstrate Gno functionality
+- `docs` - realms meant to teach about specific packages and concepts
+- `gnoland` - official gno.land realms
+- `gov` - governance realms
+- `sys` - system realms
+- `x` - experimental realms
+- `*` - can include personal namespaces, such as `manfred`, `leon`, etc.
\ No newline at end of file
diff --git a/examples/gno.land/r/docs/add/add.gno b/examples/gno.land/r/docs/adder/adder.gno
similarity index 98%
rename from examples/gno.land/r/docs/add/add.gno
rename to examples/gno.land/r/docs/adder/adder.gno
index ffc8f9c6877..cd96d241692 100644
--- a/examples/gno.land/r/docs/add/add.gno
+++ b/examples/gno.land/r/docs/adder/adder.gno
@@ -1,4 +1,4 @@
-package add
+package adder
import (
"strconv"
diff --git a/examples/gno.land/r/docs/add/add_test.gno b/examples/gno.land/r/docs/adder/adder_test.gno
similarity index 74%
rename from examples/gno.land/r/docs/add/add_test.gno
rename to examples/gno.land/r/docs/adder/adder_test.gno
index 8994b895f7e..327908ab2d3 100644
--- a/examples/gno.land/r/docs/add/add_test.gno
+++ b/examples/gno.land/r/docs/adder/adder_test.gno
@@ -1,4 +1,4 @@
-package add
+package adder
import (
"testing"
@@ -13,7 +13,7 @@ Current Number: 0
Last Updated: Never
-[Increase Number](/r/docs/add$help&func=Add&n=42)
+[Increase Number](/r/docs/adder$help&func=Add&n=42)
`
if output != expected {
t.Errorf("Initial Render failed, got:\n%s", output)
@@ -36,9 +36,9 @@ Current Number: 5
Last Updated: 2009-02-13 23:31:30
-[Increase Number](/r/docs/add$help&func=Add&n=42)
+[Increase Number](/r/docs/adder$help&func=Add&n=42)
`
if output != expected {
- t.Errorf("Final Render failed, got:\n%s", output)
+ t.Errorf("Final Render failed, got:\n%s\nexpected:\n%s", output, finalOutput)
}
}
diff --git a/examples/gno.land/r/docs/add/gno.mod b/examples/gno.land/r/docs/adder/gno.mod
similarity index 61%
rename from examples/gno.land/r/docs/add/gno.mod
rename to examples/gno.land/r/docs/adder/gno.mod
index a66c63e0910..f8bbf9d6fe8 100644
--- a/examples/gno.land/r/docs/add/gno.mod
+++ b/examples/gno.land/r/docs/adder/gno.mod
@@ -1,3 +1,3 @@
-module gno.land/r/docs/add
+module gno.land/r/docs/adder
require gno.land/p/moul/txlink v0.0.0-latest
diff --git a/examples/gno.land/r/docs/home/home.gno b/examples/gno.land/r/docs/home/home.gno
index 2c581019380..6e61f08c11a 100644
--- a/examples/gno.land/r/docs/home/home.gno
+++ b/examples/gno.land/r/docs/home/home.gno
@@ -9,8 +9,9 @@ Explore various examples to learn more about Gno functionality and usage.
## Examples
- [Hello World](/r/docs/hello) - A simple introductory example.
-- [Add](/r/docs/add) - An interactive example to update a number with transactions.
-- [AVL Pager](/r/docs/avl_pager) - Paginate through AVL tree items.
+- [Adder](/r/docs/adder) - An interactive example to update a number with transactions.
+- [Source](/r/docs/source) - View realm source code.
+- [AVL Pager](/r/docs/avl_pager) - Paginate through AVL tree items.
- ...
## Other resources
diff --git a/examples/gno.land/r/docs/source/gno.mod b/examples/gno.land/r/docs/source/gno.mod
new file mode 100644
index 00000000000..a2b5ad313c0
--- /dev/null
+++ b/examples/gno.land/r/docs/source/gno.mod
@@ -0,0 +1 @@
+module gno.land/r/docs/source
diff --git a/examples/gno.land/r/docs/source/source.gno b/examples/gno.land/r/docs/source/source.gno
new file mode 100644
index 00000000000..45db3c98f06
--- /dev/null
+++ b/examples/gno.land/r/docs/source/source.gno
@@ -0,0 +1,17 @@
+package source
+
+// Welcome to the source code of this realm!
+
+func Render(_ string) string {
+ return `# Viewing source code
+gno.land makes it easy to view the source code of any pure
+package or realm, by using ABCI queries.
+
+gno.land's web frontend, ` + "`gnoweb`, " + ` makes this easy by
+providing a intuitive UI that fetches the source of the
+realm, that you can inspect anywhere by simply clicking
+on the [source] button.
+
+Check it out in the top right corner!
+`
+}