render.gno
1.30 Kb ยท 61 lines
1package counter
2
3import "strings"
4
5func Render(path string) string {
6 content := `
7# Counter
8
9This Solidity contract defines a counter that can be incremented or decremented by anyone.
10
11---
12
13### Solidity Version
14
15^^^solidity
16contract Counter {
17 int public count = 0;
18
19 function increment() public {
20 count++;
21 }
22
23 function decrement() public {
24 count--;
25 }
26}
27^^^
28
29#### Explanation
30
31This Solidity contract does:
32
33* Declare a ^count^ variable readable by anyone initialized at 0
34* Define two functions, ^increment^ and ^decrement^, that increase and decrease the counter by 1.
35* These functions are marked ^public^, meaning anyone can call them
36
37---
38
39### Gno Version
40
41^^^go
42package counter
43
44var count int64 = 0
45
46func Increment(cur realm) {
47 count++
48}
49
50func Decrement(cur realm) {
51 count--
52}
53^^^
54
55* We define a global variable ^count^ of type ^int64^. Since it is declared at the package level, its value is **persistent**, just like in Solidity. As it is capitalized, it can be accessed from outside the package (read-only).
56* We provide two functions: ^Increment^ and ^Decrement^, which modify the counter value using Go-style syntax (^count++^ and ^count--^). As they are capitalized, they can be called from outside the package.
57
58---
59`
60 return strings.ReplaceAll(content+RenderDemo(), "^", "`")
61}