-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: hyperlink buttons demo (#3245)
<!-- please provide a detailed description of the changes made in this pull request. --> ## Description Adds a `r/docs` that showcases how "buttons" can be added to realm renders. <details><summary>Contributors' checklist...</summary> - [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 </details> --------- Co-authored-by: Morgan <[email protected]>
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package buttons | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/ufmt" | ||
"gno.land/p/moul/txlink" | ||
) | ||
|
||
var ( | ||
motd = "The Initial Message\n\n" | ||
lastCaller std.Address | ||
) | ||
|
||
func UpdateMOTD(newmotd string) { | ||
motd = newmotd | ||
lastCaller = std.PrevRealm().Addr() | ||
} | ||
|
||
func Render(path string) string { | ||
if path == "motd" { | ||
out := "# Message of the Day:\n\n" | ||
out += "---\n\n" | ||
out += "# " + motd + "\n\n" | ||
out += "---\n\n" | ||
link := txlink.Call("UpdateMOTD", "newmotd", "Message!") // "/r/docs/buttons$help&func=UpdateMOTD&newmotd=Message!" | ||
out += ufmt.Sprintf("Click **[here](%s)** to update the Message of The Day!\n\n", link) | ||
out += "[Go back to home page](/r/docs/buttons)\n\n" | ||
out += "Last updated by " + lastCaller.String() | ||
|
||
return out | ||
} | ||
|
||
out := `# Buttons | ||
Users can create simple hyperlink buttons to view specific realm pages and | ||
do specific realm actions, such as calling a specific function with some arguments. | ||
The foundation for this functionality are markdown links; for example, you can | ||
click... | ||
` + "\n## [here](/r/docs/buttons:motd)\n" + `...to view this realm's message of the day.` | ||
|
||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package buttons | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestRenderMotdLink(t *testing.T) { | ||
res := Render("motd") | ||
const wantLink = "/r/docs/buttons$help&func=UpdateMOTD&newmotd=Message!" | ||
if !strings.Contains(res, wantLink) { | ||
t.Fatalf("%s\ndoes not contain correct help page link: %s", res, wantLink) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/r/docs/buttons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters