-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(examples): add more r/docs
items
#3987
base: master
Are you sure you want to change the base?
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
r/docs
itemsr/docs
items
|
||
var out string | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the init just after global vars (~line 10)
var ( | ||
slice []int | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ( | |
slice []int | |
) | |
var slice []int |
slice []int | ||
) | ||
|
||
// SetSlice takes in a complex argument, which needs to be called via MsgRun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SetSlice takes in a complex argument, which needs to be called via MsgRun | |
// SetSlice takes a complex argument that must be called using MsgRun or from another contract that imports this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, can you try to execute MsgRun complexargs.SetSlice([]int{1,2,3})
, shut down your chain, and then wake it up again? I believe it may currently only work with the same memory, but after a reboot, we could encounter a problem (or not).
If possible, this example should also include a more complex setter, such as SetStruct(locallyDefinedStructType{...})
. However, I'm pretty sure it will fail in maketx run
if we have non-persisted objects. This needs to be tested, please.
` | ||
|
||
out = strings.Replace(out, "\"", "`", -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you try this altearntive:
out = ```
# Complex argument functions
Exposed... `MsgCall` ...
```
|
||
// SetSlice takes in a complex argument, which needs to be called via MsgRun | ||
func SetSlice(newSlice []int) { | ||
slice = newSlice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sad not to return this in the render function.
|
||
func init() { | ||
admins.Add(lc.OwnableMain.Owner()) // @leohhhn | ||
admins.Add(mc.Addr()) // @moul |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi: i'll remove my mc.Addr in favor of a mc.Authz using p/moul/authz, so that i can easily manage my authorization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please start a r/devrels/config using p/moul/authz and add both your key and mine.
@@ -29,6 +43,8 @@ Explore various examples to learn more about Gno functionality and usage. | |||
- [Official documentation](https://github.com/gnolang/gno/tree/master/docs) <!-- should be /docs with gnoweb embedding the docs/ folder. --> | |||
` | |||
content := "" | |||
content += frontMatter() // XXX: try to remove this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we SHOULD remove this, since it was rollbacked.
// Entry needs to be under r/docs to be valid. | ||
// Title and description are required. | ||
func AddEntry(title, description string) { | ||
if !admins.Has(std.OriginCaller()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevrealm, not origcaller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do a registry pattern, so prevrealm is the actual docs item, and the deployer is the origcaller. Until we have sys/teams this is the way to go, I think. then we can do a team based perms to deploy to r/docs
chronological.Set(id.String(), entry) | ||
alphabetical.Set(entryPath, entry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep a single list, but allow for an arbitrary weight argument that we can modify. It is our responsibility to manage the weight to display items as we choose.
admins.Add(mc.Addr()) // @moul | ||
} | ||
|
||
const docsPrefix = "gno.land/r/docs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const docsPrefix = "gno.land/r/docs" | |
var docsPrefix = std.ChainDomain()+"/r/docs" |
// Disallow non-code calls and non-docs realms | ||
// This will automatically reject non-code calls as pkgpath of a user realm is "" | ||
if !strings.HasPrefix(entryPath, docsPrefix) { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return | |
panic("invalid path") |
|
||
// Need both title and description | ||
if title == "" || description == "" { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return | |
panic("empty title or desc") |
out := "# Emitting events in Gno\n\n" | ||
|
||
out += `Emitting events in blockchain systems is one of the ways to make off-chain life easier. | ||
To emit an event, simply use the **Emit()** function found in the **std** package. | ||
This function takes in string arguments as follows: | ||
` | ||
out += "```\nstd.Emit(\"EventName\", \"key1\", \"value1\", \"key2\", \"value2\")\n```\n" | ||
out += "The function takes in a variadic number of key:value pairs after the event name.\n\n" | ||
out += "Events are stored in block results, and can be listened to via the [tx-indexer](https://github.com/gnolang/tx-indexer)." | ||
|
||
return out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out := "# Emitting events in Gno\n\n" | |
out += `Emitting events in blockchain systems is one of the ways to make off-chain life easier. | |
To emit an event, simply use the **Emit()** function found in the **std** package. | |
This function takes in string arguments as follows: | |
` | |
out += "```\nstd.Emit(\"EventName\", \"key1\", \"value1\", \"key2\", \"value2\")\n```\n" | |
out += "The function takes in a variadic number of key:value pairs after the event name.\n\n" | |
out += "Events are stored in block results, and can be listened to via the [tx-indexer](https://github.com/gnolang/tx-indexer)." | |
return out | |
return ```# Emitting ... | |
... | |
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you see with @alexiscolin what's the current status of README.md embedding as a block in gnoweb? I think that you should move most of your text in the README.md, while keeping the Render empty or minimakl.
@@ -0,0 +1,95 @@ | |||
package routing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
var ( | ||
// Initialize the router object | ||
router = mux.NewRouter() | ||
) | ||
|
||
func init() { | ||
// Pass specific path patterns and their function handlers | ||
// The handler functions need to have a specific signature: | ||
// func(*mux.ResponseWriter, *mux.Request) | ||
|
||
// Below are some examples for specific path patterns and their handlers | ||
|
||
// When no render path is passed, ie the root render | ||
router.HandleFunc("", homeHandler) | ||
|
||
// When a specific render path is passed | ||
router.HandleFunc("staticpage", staticpageHanlder) | ||
|
||
// When a render path with a variable is passed, ie `addr` | ||
router.HandleFunc("user/{name}", profileHandler) | ||
|
||
// When a wildcard path is passed | ||
router.HandleFunc("wildcard/*/", wildcardHandler) | ||
} | ||
|
||
// Render displays the current number value, last update timestamp, and a link to call Add with 42 | ||
func Render(path string) string { | ||
// Pass the render path to the router | ||
return router.Render(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ( | |
// Initialize the router object | |
router = mux.NewRouter() | |
) | |
func init() { | |
// Pass specific path patterns and their function handlers | |
// The handler functions need to have a specific signature: | |
// func(*mux.ResponseWriter, *mux.Request) | |
// Below are some examples for specific path patterns and their handlers | |
// When no render path is passed, ie the root render | |
router.HandleFunc("", homeHandler) | |
// When a specific render path is passed | |
router.HandleFunc("staticpage", staticpageHanlder) | |
// When a render path with a variable is passed, ie `addr` | |
router.HandleFunc("user/{name}", profileHandler) | |
// When a wildcard path is passed | |
router.HandleFunc("wildcard/*/", wildcardHandler) | |
} | |
// Render displays the current number value, last update timestamp, and a link to call Add with 42 | |
func Render(path string) string { | |
// Pass the render path to the router | |
return router.Render(path) | |
// Render displays the current number value, last update timestamp, and a link to call Add with 42 | |
func Render(path string) string { | |
// Initialize the router object | |
router = mux.NewRouter() | |
// Pass specific path patterns and their function handlers | |
// The handler functions need to have a specific signature: | |
// func(*mux.ResponseWriter, *mux.Request) | |
// Below are some examples for specific path patterns and their handlers | |
// When no render path is passed, ie the root render | |
router.HandleFunc("", homeHandler) | |
// When a specific render path is passed | |
router.HandleFunc("staticpage", staticpageHanlder) | |
// When a render path with a variable is passed, ie `addr` | |
router.HandleFunc("user/{name}", profileHandler) | |
// When a wildcard path is passed | |
router.HandleFunc("wildcard/*/", wildcardHandler) | |
// Pass the render path to the router | |
return router.Render(path) |
// This data might be privileged because only certain users | ||
// have the edit rights, or for other reasons. | ||
type SafeObject struct { | ||
privilegedData string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the admin inside (configurable), so it's a "dynbamic sfae object"
Description
Compiling small examples on how to use some packages in
r/docs
.Adds:
p/demo/mux