aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/test.yml4
-rw-r--r--README.md23
-rw-r--r--src/try_gleam.gleam143
3 files changed, 80 insertions, 90 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index cf2096e..d52406f 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -15,9 +15,9 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "26.0.2"
- gleam-version: "0.32.4"
+ gleam-version: "0.33.0"
rebar3-version: "3"
# elixir-version: "1.15.4"
- run: gleam deps download
- - run: gleam test
- run: gleam format --check src test
+ - run: gleam run
diff --git a/README.md b/README.md
index 5516621..30c0149 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,3 @@
-# playground
+# Try Gleam
-[![Package Version](https://img.shields.io/hexpm/v/playground)](https://hex.pm/packages/playground)
-[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/playground/)
-
-## Quick start
-
-```sh
-gleam run # Run the project
-gleam test # Run the tests
-gleam shell # Run an Erlang shell
-```
-
-## Installation
-
-If available on Hex this package can be added to your Gleam project:
-
-```sh
-gleam add playground
-```
-
-and its documentation can be found at <https://hexdocs.pm/playground>.
+An interactive Gleam tutorial and playground! Watch this space.
diff --git a/src/try_gleam.gleam b/src/try_gleam.gleam
index 0be0ace..1cd9146 100644
--- a/src/try_gleam.gleam
+++ b/src/try_gleam.gleam
@@ -81,41 +81,41 @@ fn load_pages() -> snag.Result(List(Page)) {
|> list.sort(by: string.compare)
|> list.index_map(pair.new)
- use pages <- result.try(list.try_map(lessons, fn(pair) {
- let #(index, lesson) = pair
- let path = lessons_src <> "/" <> lesson
- let name =
- lesson
- |> string.split("_")
- |> list.drop(1)
- |> string.join("-")
-
- use code <- result.try(
- simplifile.read(path <> "/code.gleam")
- |> file_error("Failed to read code.gleam"),
- )
-
- use text <- result.try(
- simplifile.read(path <> "/text.html")
- |> file_error("Failed to read text.html"),
- )
-
- let path = case index {
- 0 -> "/"
- _ -> "/" <> name
- }
-
- Ok(
- Page(
+ use pages <- result.try(
+ list.try_map(lessons, fn(pair) {
+ let #(index, lesson) = pair
+ let path = lessons_src <> "/" <> lesson
+ let name =
+ lesson
+ |> string.split("_")
+ |> list.drop(1)
+ |> string.join("-")
+
+ use code <- result.try(
+ simplifile.read(path <> "/code.gleam")
+ |> file_error("Failed to read code.gleam"),
+ )
+
+ use text <- result.try(
+ simplifile.read(path <> "/text.html")
+ |> file_error("Failed to read text.html"),
+ )
+
+ let path = case index {
+ 0 -> "/"
+ _ -> "/" <> name
+ }
+
+ Ok(Page(
name: name,
text: text,
code: code,
path: path,
previous: None,
next: None,
- ),
- )
- }))
+ ))
+ }),
+ )
Ok(add_previous_next(pages, [], None))
}
@@ -127,16 +127,20 @@ fn write_pages(pages: List(Page)) -> snag.Result(Nil) {
let html =
string.concat([
render(h("h2", [], [text("Table of contents")])),
- render(h("ul", [], list.map(pages, fn(page) {
- h("li", [], [
- h("a", [#("href", page.path)], [
- page.name
- |> string.replace("-", " ")
- |> string.capitalise
- |> text,
- ]),
- ])
- }))),
+ render(h(
+ "ul",
+ [],
+ list.map(pages, fn(page) {
+ h("li", [], [
+ h("a", [#("href", page.path)], [
+ page.name
+ |> string.replace("-", " ")
+ |> string.capitalise
+ |> text,
+ ]),
+ ])
+ }),
+ )),
])
let page =
@@ -258,36 +262,42 @@ fn copy_compiled_stdlib(modules: List(String)) -> snag.Result(Nil) {
|> file_error("Failed to make " <> dest),
)
- use _ <- result.try(list.try_each(modules, fn(name) {
- let from = stdlib_compiled <> "/" <> name <> ".mjs"
- let to = dest <> "/" <> name <> ".mjs"
- simplifile.copy_file(from, to)
- |> file_error("Failed to copy stdlib module " <> from)
- }))
+ use _ <- result.try(
+ list.try_each(modules, fn(name) {
+ let from = stdlib_compiled <> "/" <> name <> ".mjs"
+ let to = dest <> "/" <> name <> ".mjs"
+ simplifile.copy_file(from, to)
+ |> file_error("Failed to copy stdlib module " <> from)
+ }),
+ )
Ok(Nil)
}
fn generate_stdlib_bundle(modules: List(String)) -> snag.Result(Nil) {
- use entries <- result.try(list.try_map(modules, fn(name) {
- let path = stdlib_sources <> "/" <> name <> ".gleam"
- use code <- result.try(
- simplifile.read(path)
- |> file_error("Failed to read stdlib module " <> path),
- )
- let name = string.replace(name, ".gleam", "")
- let code =
- code
- |> string.replace("\\", "\\\\")
- |> string.replace("`", "\\`")
- |> string.split("\n")
- |> list.filter(fn(line) { !string.starts_with(string.trim(line), "//") })
- |> list.filter(fn(line) { !string.starts_with(line, "@external(erlang") })
- |> list.filter(fn(line) { line != "" })
- |> string.join("\n")
-
- Ok(" \"gleam/" <> name <> "\": `" <> code <> "`")
- }))
+ use entries <- result.try(
+ list.try_map(modules, fn(name) {
+ let path = stdlib_sources <> "/" <> name <> ".gleam"
+ use code <- result.try(
+ simplifile.read(path)
+ |> file_error("Failed to read stdlib module " <> path),
+ )
+ let name = string.replace(name, ".gleam", "")
+ let code =
+ code
+ |> string.replace("\\", "\\\\")
+ |> string.replace("`", "\\`")
+ |> string.split("\n")
+ |> list.filter(fn(line) { !string.starts_with(string.trim(line), "//") })
+ |> list.filter(fn(line) {
+ !string.starts_with(line, "@external(erlang")
+ })
+ |> list.filter(fn(line) { line != "" })
+ |> string.join("\n")
+
+ Ok(" \"gleam/" <> name <> "\": `" <> code <> "`")
+ }),
+ )
entries
|> string.join(",\n")
@@ -370,9 +380,8 @@ fn page_html(page: Page) -> String {
]),
h("article", [#("class", "playground")], [
h("section", [#("id", "text")], [
- htmb.dangerous_unescaped_fragment(
- string_builder.from_string(page.text),
- ),
+ htmb.dangerous_unescaped_fragment(string_builder.from_string(page.text,
+ )),
h("nav", [#("class", "prev-next")], [
navlink("Back", page.previous),
text(" — "),