From 3bfbe688f5a62e29835c7d3c4f282e7fff57949d Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 18 Jan 2024 17:47:12 +0000 Subject: [PATCH] Rename --- README.md | 4 +- gleam.toml | 2 +- .../lesson00_hello_world/code.gleam | 5 - .../lesson00_hello_world/text.html | 26 ---- .../lesson00_use/code.gleam | 0 .../lesson00_use/text.html | 0 .../lesson01_use_sugar/code.gleam | 0 .../lesson01_use_sugar/text.html | 0 .../lesson02_todo/code.gleam | 0 .../lesson02_todo/text.html | 0 .../lesson03_panic/code.gleam | 0 .../lesson03_panic/text.html | 0 .../lesson04_externals/code.gleam | 0 .../lesson04_externals/text.html | 0 .../code.gleam | 0 .../lesson05_multi_target_externals/text.html | 0 .../code.gleam | 0 .../text.html | 0 src/{try_gleam.gleam => tour.gleam} | 139 +++++++++++++++--- static/index.js | 1 - .../{try_gleam_test.gleam => tour_test.gleam} | 0 21 files changed, 118 insertions(+), 59 deletions(-) delete mode 100644 src/content/chapter0_basics/lesson00_hello_world/code.gleam delete mode 100644 src/content/chapter0_basics/lesson00_hello_world/text.html rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson00_use/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson00_use/text.html (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson01_use_sugar/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson01_use_sugar/text.html (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson02_todo/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson02_todo/text.html (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson03_panic/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson03_panic/text.html (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson04_externals/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson04_externals/text.html (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson05_multi_target_externals/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson05_multi_target_externals/text.html (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson06_external_gleam_fallbacks/code.gleam (100%) rename src/content/{chapter5_advance_features => chapter5_advanced_features}/lesson06_external_gleam_fallbacks/text.html (100%) rename src/{try_gleam.gleam => tour.gleam} (76%) rename test/{try_gleam_test.gleam => tour_test.gleam} (100%) diff --git a/README.md b/README.md index 30c0149..ce1a26e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/gleam.toml b/gleam.toml index 6d7186b..6435c03 100644 --- a/gleam.toml +++ b/gleam.toml @@ -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 @@ -

Hello, friend 💫

-

- Welcome to Try Gleam! An interactive tour of the Gleam programming language. -

-

- 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. -

-

- The tour is interactive! The code shown is editable and will be compiled and - evaluated as you type. Anything you print using io.println or - io.debug 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. -

-

- If at any point you get stuck or have a question do not hesitate to ask in - the Gleam Discord server. 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. -

-

- OK, let's go. Click "Next" to get started, or click "Index" to jump to a - specific topic. -

diff --git a/src/content/chapter5_advance_features/lesson00_use/code.gleam b/src/content/chapter5_advanced_features/lesson00_use/code.gleam similarity index 100% rename from src/content/chapter5_advance_features/lesson00_use/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson00_use/text.html rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson01_use_sugar/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson01_use_sugar/text.html rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson02_todo/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson02_todo/text.html rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson03_panic/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson03_panic/text.html rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson04_externals/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson04_externals/text.html rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson05_multi_target_externals/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson05_multi_target_externals/text.html rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/code.gleam rename to 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 similarity index 100% rename from src/content/chapter5_advance_features/lesson06_external_gleam_fallbacks/text.html rename to src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/text.html diff --git a/src/try_gleam.gleam b/src/tour.gleam similarity index 76% rename from src/try_gleam.gleam rename to 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 = " +

Welcome the Gleam language tour! 💫

+

+ 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. +

+

+ The tour is interactive! The code shown is editable and will be compiled and + evaluated as you type. Anything you print using io.println or + io.debug 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. +

+

+ If at any point you get stuck or have a question do not hesitate to ask in + the Gleam Discord server. 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. +

+

+ OK, let's go. Click \"Next\" to get started, or click \"Index\" to jump to a + specific topic. +

+" + +const what_next_html = " +

What next? 💫

+

+ Congratulations on completing the tour! Here's some ideas for what to do next: +

+ +

+ Read the Gleam getting started + documentation to learn more about the language and its tooling. +

+

+ Join the the Gleam Discord server + and meet the community. They're friendly and helpful! +

+

+ Enroll in the Exercism + Gleam track practice your Gleam skills through a series of exercises, + and get feedback from experienced Gleam developers. +

+" + +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 similarity index 100% rename from test/try_gleam_test.gleam rename to test/tour_test.gleam