diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | gleam.toml | 2 | ||||
-rw-r--r-- | src/content/chapter0_basics/lesson00_hello_world/code.gleam | 5 | ||||
-rw-r--r-- | src/content/chapter0_basics/lesson00_hello_world/text.html | 26 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson00_use/code.gleam (renamed from src/content/chapter5_advance_features/lesson00_use/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson00_use/text.html (renamed from src/content/chapter5_advance_features/lesson00_use/text.html) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson01_use_sugar/code.gleam (renamed from src/content/chapter5_advance_features/lesson01_use_sugar/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson01_use_sugar/text.html (renamed from src/content/chapter5_advance_features/lesson01_use_sugar/text.html) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson02_todo/code.gleam (renamed from src/content/chapter5_advance_features/lesson02_todo/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson02_todo/text.html (renamed from src/content/chapter5_advance_features/lesson02_todo/text.html) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson03_panic/code.gleam (renamed from src/content/chapter5_advance_features/lesson03_panic/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson03_panic/text.html (renamed from src/content/chapter5_advance_features/lesson03_panic/text.html) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson04_externals/code.gleam (renamed from src/content/chapter5_advance_features/lesson04_externals/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson04_externals/text.html (renamed from src/content/chapter5_advance_features/lesson04_externals/text.html) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson05_multi_target_externals/code.gleam (renamed from src/content/chapter5_advance_features/lesson05_multi_target_externals/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson05_multi_target_externals/text.html (renamed from src/content/chapter5_advance_features/lesson05_multi_target_externals/text.html) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam (renamed from src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/code.gleam) | 0 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/text.html (renamed from src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/text.html) | 0 | ||||
-rw-r--r-- | src/tour.gleam (renamed from src/try_gleam.gleam) | 139 | ||||
-rw-r--r-- | static/index.js | 1 | ||||
-rw-r--r-- | test/tour_test.gleam (renamed from test/try_gleam_test.gleam) | 0 |
21 files changed, 118 insertions, 59 deletions
@@ -1,3 +1,3 @@ -# Try Gleam +# The Gleam Language Tour -An interactive Gleam tutorial and playground! Watch this space. +An interactive tour of the Gleam programming language. @@ -1,4 +1,4 @@ -name = "try_gleam" +name = "tour" version = "1.0.0" target = "javascript" diff --git a/src/content/chapter0_basics/lesson00_hello_world/code.gleam b/src/content/chapter0_basics/lesson00_hello_world/code.gleam deleted file mode 100644 index 30530b2..0000000 --- a/src/content/chapter0_basics/lesson00_hello_world/code.gleam +++ /dev/null @@ -1,5 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("Hello, Joe!") -} diff --git a/src/content/chapter0_basics/lesson00_hello_world/text.html b/src/content/chapter0_basics/lesson00_hello_world/text.html deleted file mode 100644 index cb41be9..0000000 --- a/src/content/chapter0_basics/lesson00_hello_world/text.html +++ /dev/null @@ -1,26 +0,0 @@ -<h2>Hello, friend 💫</h2> -<p> - Welcome to Try Gleam! An interactive tour of the Gleam programming language. -</p> -<p> - It covers all aspects of the Gleam language, and assuming you have some - prior programming experience should teach you everything you need to write - real programs in Gleam. -</p> -<p> - The tour is interactive! The code shown is editable and will be compiled and - evaluated as you type. Anything you print using <code>io.println</code> or - <code>io.debug</code> will be shown in the bottom section, along with any - compile errors and warnings. To evaluate Gleam code the tour compiles Gleam to - JavaScript and runs it, all entirely within your browser window. -</p> -<p> - If at any point you get stuck or have a question do not hesitate to ask in - <a href="https://discord.gg/Fm8Pwmy">the Gleam Discord server</a>. We're here - to help, and if you find something confusing then it's likely others will too, - and we want to know about it so we can improve the tour. -</p> -<p> - OK, let's go. Click "Next" to get started, or click "Index" to jump to a - specific topic. -</p> diff --git a/src/content/chapter5_advance_features/lesson00_use/code.gleam b/src/content/chapter5_advanced_features/lesson00_use/code.gleam index 37624ab..37624ab 100644 --- a/src/content/chapter5_advance_features/lesson00_use/code.gleam +++ b/src/content/chapter5_advanced_features/lesson00_use/code.gleam diff --git a/src/content/chapter5_advance_features/lesson00_use/text.html b/src/content/chapter5_advanced_features/lesson00_use/text.html index e295dda..e295dda 100644 --- a/src/content/chapter5_advance_features/lesson00_use/text.html +++ b/src/content/chapter5_advanced_features/lesson00_use/text.html diff --git a/src/content/chapter5_advance_features/lesson01_use_sugar/code.gleam b/src/content/chapter5_advanced_features/lesson01_use_sugar/code.gleam index ac61062..ac61062 100644 --- a/src/content/chapter5_advance_features/lesson01_use_sugar/code.gleam +++ b/src/content/chapter5_advanced_features/lesson01_use_sugar/code.gleam diff --git a/src/content/chapter5_advance_features/lesson01_use_sugar/text.html b/src/content/chapter5_advanced_features/lesson01_use_sugar/text.html index e28c843..e28c843 100644 --- a/src/content/chapter5_advance_features/lesson01_use_sugar/text.html +++ b/src/content/chapter5_advanced_features/lesson01_use_sugar/text.html diff --git a/src/content/chapter5_advance_features/lesson02_todo/code.gleam b/src/content/chapter5_advanced_features/lesson02_todo/code.gleam index d5abe8f..d5abe8f 100644 --- a/src/content/chapter5_advance_features/lesson02_todo/code.gleam +++ b/src/content/chapter5_advanced_features/lesson02_todo/code.gleam diff --git a/src/content/chapter5_advance_features/lesson02_todo/text.html b/src/content/chapter5_advanced_features/lesson02_todo/text.html index 4a2c433..4a2c433 100644 --- a/src/content/chapter5_advance_features/lesson02_todo/text.html +++ b/src/content/chapter5_advanced_features/lesson02_todo/text.html diff --git a/src/content/chapter5_advance_features/lesson03_panic/code.gleam b/src/content/chapter5_advanced_features/lesson03_panic/code.gleam index fce9d66..fce9d66 100644 --- a/src/content/chapter5_advance_features/lesson03_panic/code.gleam +++ b/src/content/chapter5_advanced_features/lesson03_panic/code.gleam diff --git a/src/content/chapter5_advance_features/lesson03_panic/text.html b/src/content/chapter5_advanced_features/lesson03_panic/text.html index 843a65b..843a65b 100644 --- a/src/content/chapter5_advance_features/lesson03_panic/text.html +++ b/src/content/chapter5_advanced_features/lesson03_panic/text.html diff --git a/src/content/chapter5_advance_features/lesson04_externals/code.gleam b/src/content/chapter5_advanced_features/lesson04_externals/code.gleam index ade2c54..ade2c54 100644 --- a/src/content/chapter5_advance_features/lesson04_externals/code.gleam +++ b/src/content/chapter5_advanced_features/lesson04_externals/code.gleam diff --git a/src/content/chapter5_advance_features/lesson04_externals/text.html b/src/content/chapter5_advanced_features/lesson04_externals/text.html index 81202d6..81202d6 100644 --- a/src/content/chapter5_advance_features/lesson04_externals/text.html +++ b/src/content/chapter5_advanced_features/lesson04_externals/text.html diff --git a/src/content/chapter5_advance_features/lesson05_multi_target_externals/code.gleam b/src/content/chapter5_advanced_features/lesson05_multi_target_externals/code.gleam index b62a735..b62a735 100644 --- a/src/content/chapter5_advance_features/lesson05_multi_target_externals/code.gleam +++ b/src/content/chapter5_advanced_features/lesson05_multi_target_externals/code.gleam diff --git a/src/content/chapter5_advance_features/lesson05_multi_target_externals/text.html b/src/content/chapter5_advanced_features/lesson05_multi_target_externals/text.html index dc10a19..dc10a19 100644 --- a/src/content/chapter5_advance_features/lesson05_multi_target_externals/text.html +++ b/src/content/chapter5_advanced_features/lesson05_multi_target_externals/text.html diff --git a/src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/code.gleam b/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam index a97b8fc..a97b8fc 100644 --- a/src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/code.gleam +++ b/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam diff --git a/src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/text.html b/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/text.html index 243c7ea..243c7ea 100644 --- a/src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/text.html +++ b/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/text.html diff --git a/src/try_gleam.gleam b/src/tour.gleam index 0f701c8..5738bcf 100644 --- a/src/try_gleam.gleam +++ b/src/tour.gleam @@ -33,6 +33,72 @@ pub fn main() { } " +const hello_mike = "import gleam/io +import gleam/list + +pub fn main() { + list.each(erlang_the_movie, io.println) +} + +const erlang_the_movie = [ + \"📞\", \"Hello, Mike!\", \"Hello, Joe!\", \"System working?\", \"Seems to be.\", + \"OK, fine.\", \"OK.\", \"💫\", +] +" + +const home_html = " +<h2>Welcome the Gleam language tour! 💫</h2> +<p> + This tour covers all aspects of the Gleam language, and assuming you have some + prior programming experience should teach you everything you need to write + real programs in Gleam. +</p> +<p> + The tour is interactive! The code shown is editable and will be compiled and + evaluated as you type. Anything you print using <code>io.println</code> or + <code>io.debug</code> will be shown in the bottom section, along with any + compile errors and warnings. To evaluate Gleam code the tour compiles Gleam to + JavaScript and runs it, all entirely within your browser window. +</p> +<p> + If at any point you get stuck or have a question do not hesitate to ask in + <a href=\"https://discord.gg/Fm8Pwmy\">the Gleam Discord server</a>. We're here + to help, and if you find something confusing then it's likely others will too, + and we want to know about it so we can improve the tour. +</p> +<p> + OK, let's go. Click \"Next\" to get started, or click \"Index\" to jump to a + specific topic. +</p> +" + +const what_next_html = " +<h2>What next? 💫</h2> +<p> + Congratulations on completing the tour! Here's some ideas for what to do next: +</p> + +<p> + Read the <a href=\"https://gleam.run/getting-started/\">Gleam getting started + documentation</a> to learn more about the language and its tooling. +</p> +<p> + Join the <a href=\"https://discord.gg/Fm8Pwmy\">the Gleam Discord server</a> + and meet the community. They're friendly and helpful! +</p> +<p> + Enroll in the <a href=\"https://exercism.io/tracks/gleam\">Exercism + Gleam track</a> practice your Gleam skills through a series of exercises, + and get feedback from experienced Gleam developers. +</p> +" + +const path_home = "/" + +const path_index = "/index" + +const path_what_next = "/what-next" + // Don't include deprecated stdlib modules const skipped_stdlib_modules = [ "bit_string.gleam", "bit_builder.gleam", "map.gleam", @@ -130,28 +196,53 @@ fn load_lesson(chapter_path: String, names: FileNames) -> snag.Result(Lesson) { fn load_content() -> snag.Result(List(Chapter)) { use chapters <- result.try(load_directory_names(content_path)) use chapters <- result.try(list.try_map(chapters, load_chapter)) - Ok(add_prev_next(chapters, [], Some("/"))) + Ok(add_prev_next(chapters, [], path_home)) } fn write_content(chapters: List(Chapter)) -> snag.Result(Nil) { let lessons = list.flat_map(chapters, fn(c) { c.lessons }) use _ <- result.try(list.try_map(lessons, write_lesson)) - let html = - chapters - |> list.map(index_chapter_html) - |> string.join("\n") + let assert Ok(first) = list.first(lessons) + let assert Ok(last) = list.last(lessons) - let lesson = - Lesson( + // Home page + use _ <- result.try( + write_lesson(Lesson( + name: "Hello, world!", + text: home_html, + code: hello_joe, + path: path_home, + previous: None, + next: Some(first.path), + )), + ) + + // "What next" final page + use _ <- result.try( + write_lesson(Lesson( + name: "What next?", + text: what_next_html, + code: hello_mike, + path: path_what_next, + previous: Some(last.path), + next: None, + )), + ) + + // Lesson index page + use _ <- result.try( + write_lesson(Lesson( name: "Index", - text: html, + text: string.join(list.map(chapters, index_chapter_html), "\n"), code: hello_joe, - path: "/index", + path: path_index, previous: None, next: None, - ) - write_lesson(lesson) + )), + ) + + Ok(Nil) } fn index_chapter_html(chapter: Chapter) -> String { @@ -195,13 +286,13 @@ fn write_lesson(lesson: Lesson) -> snag.Result(Nil) { fn add_prev_next( rest: List(Chapter), acc: List(Chapter), - previous: Option(String), + previous: String, ) -> List(Chapter) { case rest { [chapter1, Chapter(lessons: [next, ..], ..) as chapter2, ..rest] -> { let lessons = chapter1.lessons let #(lessons, previous) = - add_prev_next_for_chapter(lessons, [], previous, Some(next.path)) + add_prev_next_for_chapter(lessons, [], previous, next.path) let chapter1 = Chapter(..chapter1, lessons: lessons) add_prev_next([chapter2, ..rest], [chapter1, ..acc], previous) } @@ -209,7 +300,7 @@ fn add_prev_next( [chapter, ..rest] -> { let lessons = chapter.lessons let #(lessons, previous) = - add_prev_next_for_chapter(lessons, [], previous, None) + add_prev_next_for_chapter(lessons, [], previous, path_what_next) let chapter = Chapter(..chapter, lessons: lessons) add_prev_next(rest, [chapter, ..acc], previous) } @@ -221,19 +312,19 @@ fn add_prev_next( fn add_prev_next_for_chapter( rest: List(Lesson), acc: List(Lesson), - previous: Option(String), - last: Option(String), -) -> #(List(Lesson), Option(String)) { + previous: String, + last: String, +) -> #(List(Lesson), String) { case rest { [lesson1, lesson2, ..rest] -> { - let next = Some(lesson2.path) - let lesson = Lesson(..lesson1, previous: previous, next: next) + let next = lesson2.path + let lesson = Lesson(..lesson1, previous: Some(previous), next: Some(next)) let rest = [lesson2, ..rest] - add_prev_next_for_chapter(rest, [lesson, ..acc], Some(lesson.path), last) + add_prev_next_for_chapter(rest, [lesson, ..acc], lesson.path, last) } [lesson, ..rest] -> { - let lesson = Lesson(..lesson, previous: previous, next: last) - add_prev_next_for_chapter(rest, [lesson, ..acc], Some(lesson.path), last) + let lesson = Lesson(..lesson, previous: Some(previous), next: Some(last)) + add_prev_next_for_chapter(rest, [lesson, ..acc], lesson.path, last) } [] -> #(list.reverse(acc), previous) } @@ -425,7 +516,7 @@ fn lesson_html(page: Lesson) -> String { ], [], ), - h("title", [], [text("Try Gleam")]), + h("title", [], [text(page.name <> " - The Gleam Language Tour")]), h("link", [#("rel", "stylesheet"), #("href", "/style.css")], []), ]), h("body", [], [ @@ -440,7 +531,7 @@ fn lesson_html(page: Lesson) -> String { h("nav", [#("class", "prev-next")], [ navlink("Back", page.previous), text(" — "), - h("a", [#("href", "/index")], [text("Index")]), + h("a", [#("href", path_index)], [text("Index")]), text(" — "), navlink("Next", page.next), ]), diff --git a/static/index.js b/static/index.js index b2e1b45..8d13c63 100644 --- a/static/index.js +++ b/static/index.js @@ -79,7 +79,6 @@ async function loadProgram(js) { /from\s+"\.\/(.+)"/g, `from "${href}precompiled/$1"`, ); - console.log(js1); const js2 = btoa(unescape(encodeURIComponent(js1))); const module = await import("data:text/javascript;base64," + js2); return module.main; diff --git a/test/try_gleam_test.gleam b/test/tour_test.gleam index 67c2bd5..67c2bd5 100644 --- a/test/try_gleam_test.gleam +++ b/test/tour_test.gleam |