From bdee1205270f84d9915789cc26dacc6c6e5affc7 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 18 Jul 2023 17:42:16 +0200 Subject: [PATCH] docs: improve 01-hello to be frendlier --- scripts/generate.ts | 17 +++++++------ src/tutorials/gno.land/gbe/01-hello/README.md | 21 +++++++++++++--- src/tutorials/gno.land/gbe/01-hello/hello.gno | 4 +-- .../gno.land/gbe/01-hello/hello_test.gno | 4 +-- src/tutorials/gno.land/gbe/01-hello/index.ts | 25 +++++++++++++++---- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/scripts/generate.ts b/scripts/generate.ts index e9d9dea..a6c5581 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -80,7 +80,7 @@ const parseTutorial = (directory: string): TutorialItem => { const codeFilePath = path.join(directory, filePath); let codeContent = fs.readFileSync(codeFilePath, 'utf-8'); - + // Check if there are any specific code segments that need embedding if (/#L\d+-L\d+/.test(codeRef)) { const [startLine, endLine] = @@ -103,7 +103,7 @@ const parseTutorial = (directory: string): TutorialItem => { } codeContent = lines.slice(startLine - 1, endLine).join('\n') - } + } let files = []; @@ -115,18 +115,21 @@ const parseTutorial = (directory: string): TutorialItem => { files.push({ path: codeFilePath, content: codeContent }) }) - const filesEncoded = encodeURIComponent(JSON.stringify(files)) + const filesEncoded = encodeURIComponent(JSON.stringify(files)) const embeddedCodeBlock = ``; mdContent = mdContent.replace(codeRef, embeddedCodeBlock); } - // Make sure to escape all other backticks - mdContent = mdContent.replace(/([^\\])`/g, '$1\\`'); + mdContent = mdContent. + // Escape backslashes + replace(/\\/g, '\\\\'). + // Escape all other backticks + replace(/([^\\])`/g, '$1\\`'). + // Drop the metadata section + replace(/---[\s\S]*?---/, ''); - // Make sure to drop the metadata section - mdContent = mdContent.replace(/---[\s\S]*?---/, ''); const tsFilePath = path.join(directory, 'index.ts'); let output: string = `const markdownContent: string = \n\`${mdContent}\`;\n`; diff --git a/src/tutorials/gno.land/gbe/01-hello/README.md b/src/tutorials/gno.land/gbe/01-hello/README.md index 75115b7..4fb9268 100644 --- a/src/tutorials/gno.land/gbe/01-hello/README.md +++ b/src/tutorials/gno.land/gbe/01-hello/README.md @@ -3,13 +3,28 @@ title: Hello World section: Getting Started --- -This is the simplest application that you can create using Gno. `Render(string) string` is a special method that will be -used by `gnoweb` to render markdown output. +Whether you're a seasoned Go developer, or you're just dipping your toes into +Gno, let's start off on the right foot with a ritual +[Hello World](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program) program! + +Being designed to run smart contracts, there is no such thing as a "main +program" or "main function" as you may be used to in other programming +languages. However, the [gno.land](https://gno.land) blockchain allows having +programs with a special function, `Render(string) string`. + +This function is called when loading programs from the test nodes' website. The +website will also parse it as markdown and render it, so it's a good idea to add +some **\*\*spice!\*\*** to it. ```go file=./hello.gno ``` -We can test the `Render` method: +On this website, to show how each function is working we'll be using tests; +which work similarly to how they do in Go. + +You can define tests in function ending with the `_test.gno` suffix. These can +be executed by clicking on the `Test` button, available from the menu hidden in +the bottom right circle. ```go file=./hello_test.gno depends_on_file=./hello.gno ``` diff --git a/src/tutorials/gno.land/gbe/01-hello/hello.gno b/src/tutorials/gno.land/gbe/01-hello/hello.gno index bf02013..e326cf0 100644 --- a/src/tutorials/gno.land/gbe/01-hello/hello.gno +++ b/src/tutorials/gno.land/gbe/01-hello/hello.gno @@ -1,5 +1,5 @@ package hello func Render(path string) string { - return "Hello World!" -} \ No newline at end of file + return "Hello World! And hello, **bold!**" +} diff --git a/src/tutorials/gno.land/gbe/01-hello/hello_test.gno b/src/tutorials/gno.land/gbe/01-hello/hello_test.gno index f641e64..8117111 100644 --- a/src/tutorials/gno.land/gbe/01-hello/hello_test.gno +++ b/src/tutorials/gno.land/gbe/01-hello/hello_test.gno @@ -4,8 +4,8 @@ import "testing" func TestHello(t *testing.T) { got := Render("") - expected := "Hello World!" + expected := "Hello World! And hello, **bold!**" if got != expected { t.Fatalf("expected %q, got %q.", expected, got) } -} \ No newline at end of file +} diff --git a/src/tutorials/gno.land/gbe/01-hello/index.ts b/src/tutorials/gno.land/gbe/01-hello/index.ts index 957d14d..531927e 100644 --- a/src/tutorials/gno.land/gbe/01-hello/index.ts +++ b/src/tutorials/gno.land/gbe/01-hello/index.ts @@ -1,13 +1,28 @@ const markdownContent: string = ` -This is the simplest application that you can create using Gno. \`Render(string) string\` is a special method that will be -used by \`gnoweb\` to render markdown output. +Whether you're a seasoned Go developer, or you're just dipping your toes into +Gno, let's start off on the right foot with a ritual +[Hello World](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program) program! - +Being designed to run smart contracts, there is no such thing as a "main +program" or "main function" as you may be used to in other programming +languages. However, the [gno.land](https://gno.land) blockchain allows having +programs with a special function, \`Render(string) string\`. -We can test the \`Render\` method: +This function is called when loading programs from the test nodes' website. The +website will also parse it as markdown and render it, so it's a good idea to add +some **\\*\\*spice!\\*\\*** to it. - + + +On this website, to show how each function is working we'll be using tests; +which work similarly to how they do in Go. + +You can define tests in function ending with the \`_test.gno\` suffix. These can +be executed by clicking on the \`Test\` button, available from the menu hidden in +the bottom right circle. + + `; const title: string = "Hello World";