Skip to content

Commit

Permalink
update for gleam v0.33
Browse files Browse the repository at this point in the history
  • Loading branch information
aslilac committed Dec 19, 2023
1 parent 575ff23 commit 7bf097d
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 147 deletions.
12 changes: 4 additions & 8 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

Any conduct related communications should be directly with me, [Kayla](mailto:mckayla@hey.com).

- Spamming, trolling, or other attention-stealing behavior is not welcome.
- Spamming, trolling, or other attention-stealing behavior is not welcome.

- This is a safe and welcoming environment for people of every of level of experience,
gender identity, sexual orientation, disability, personal appearance, body size, race,
ethnicity, age, religion, or nationality.
- This is a safe and welcoming environment for people of every of level of experience, gender identity, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

- Treat everyone kindly. There’s no need to be mean or rude.
- Treat everyone kindly. There’s no need to be mean or rude.

- Personal attacks are not okay. Actionable feedback about behavior, code quality, or
implementation is okay. Critique about other unrelated things will most likely be
considered inappropriate, and un-actionable feedback should be kept to a minimum.
- Personal attacks are not okay. Actionable feedback about behavior, code quality, or implementation is okay. Critique about other unrelated things will most likely be considered inappropriate, and un-actionable feedback should be kept to a minimum.
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
## Development

Parts of Nakai really on code generation so that we don't have to write and update
hundreds of identical functions by hand. The Gleam compiler does not provide a way for us
to generate this code automatically when running things like `gleam build`, or `gleam test`.
Instead, you should run `make`, `make test`, etc.
Parts of Nakai rely on code generation so that we don't have to write and update hundreds of identical functions by hand. The Gleam compiler does not provide a way for us to generate this code automatically when running things like `gleam build`, or `gleam test`. Instead, you should run `make`, `make test`, etc.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ pub fn header(attrs: List(Attr(a)), text: String) -> Node(a) {
}
pub fn app() -> String {
html.div(
[],
html.div([],
[
html.Head([html.title("Hello!")]),
header([], "Hello, from Nakai!")
],
]
)
|> nakai.to_string()
}
```

## Development

While Nakai itself is pure Gleam, the benchmarks require having [Elixir] installed,
and some of its dependencies require [Rebar3] to compile.
While Nakai itself is pure Gleam, and has no dependencies, the benchmarks require having [Elixir] installed, and building it requires that you have [Rebar3] installed.

[elixir]: https://elixir-lang.org/
[rebar3]: https://rebar3.org/
2 changes: 1 addition & 1 deletion codegen/html_prelude.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nakai/html/attrs.{Attr}
import nakai/html/attrs.{type Attr}

pub type Node(a) {
/// Can be used anywhere in the document, and will set the doctype of the document
Expand Down
11 changes: 6 additions & 5 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ links = [
]

internal_modules = ["nakai/internal/*", "nakai/experimental/*"]
gleam = ">= 0.33.0"

[dependencies]
gleam_stdlib = "~> 0.29"
gleam_stdlib = "~> 0.34"

[dev-dependencies]
gleam_erlang = "~> 0.19"
gleam_json = "~> 0.5"
gleeunit = "~> 0.10"
glychee = "~> 0.2"
gleam_erlang = "~> 0.23"
gleam_json = "~> 0.7"
gleeunit = "~> 0.11"
glychee = "~> 0.3"
23 changes: 12 additions & 11 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
# You typically do not need to edit this file

packages = [
{ name = "benchee", version = "1.1.0", build_tools = ["mix"], requirements = ["statistex", "deep_merge"], otp_app = "benchee", source = "hex", outer_checksum = "7DA57D545003165A012B587077F6BA90B89210FD88074CE3C60CE239EB5E6D93" },
{ name = "benchee", version = "1.2.0", build_tools = ["mix"], requirements = ["table", "deep_merge", "statistex"], otp_app = "benchee", source = "hex", outer_checksum = "EE729E53217898B8FD30AAAD3CCE61973DAB61574AE6F48229FE7FF42D5E4457" },
{ name = "deep_merge", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "deep_merge", source = "hex", outer_checksum = "CE708E5F094B9CD4E8F2BE4F00D2F4250C4095BE93F8CD6D018C753894885430" },
{ name = "gleam_erlang", version = "0.19.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "720D1E0A0CEBBD51C4AA88501D1D4FBFEF4AA7B3332C994691ED944767A52582" },
{ name = "gleam_json", version = "0.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9A805C1E60FB9CD73AF3034EB464268A6B522D937FCD2DF92BD246F2F4B37930" },
{ name = "gleam_stdlib", version = "0.29.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "B296BF9B8AA384A6B64CD49F333016A9DCA6AC73A95400D17F2271E072EFF986" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
{ name = "glychee", version = "0.2.7", build_tools = ["gleam"], requirements = ["benchee"], otp_app = "glychee", source = "hex", outer_checksum = "62313873A64576D8797EFC0F02DFDC67092C295519E38539BCA2F598BB55F551" },
{ name = "gleam_erlang", version = "0.23.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "C21CFB816C114784E669FFF4BBF433535EEA9960FA2F216209B8691E87156B96" },
{ name = "gleam_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "glychee", version = "0.3.0", build_tools = ["gleam"], requirements = ["benchee"], otp_app = "glychee", source = "hex", outer_checksum = "CB925EA2078B75ABAC0B363F6E12E0BD80197100863DAD97E96998BBBB25CAC8" },
{ name = "statistex", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "statistex", source = "hex", outer_checksum = "FF9D8BEE7035028AB4742FF52FC80A2AA35CECE833CF5319009B52F1B5A86C27" },
{ name = "table", version = "0.1.2", build_tools = ["mix"], requirements = [], otp_app = "table", source = "hex", outer_checksum = "7E99BC7EFEF806315C7E65640724BF165C3061CDC5D854060F74468367065029" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
]

[requirements]
gleam_erlang = "~> 0.19"
gleam_json = "~> 0.5"
gleam_stdlib = "~> 0.29"
gleeunit = "~> 0.10"
glychee = "~> 0.2"
gleam_erlang = { version = "~> 0.23" }
gleam_json = { version = "~> 0.7" }
gleam_stdlib = { version = "~> 0.34" }
gleeunit = { version = "~> 0.11" }
glychee = { version = "~> 0.3" }
4 changes: 2 additions & 2 deletions src/nakai.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//// - A future experimental DOM renderer (meant for use in the browser) that isn't
//// actually done yet.

import gleam/string_builder.{StringBuilder}
import nakai/html.{Node}
import gleam/string_builder.{type StringBuilder}
import nakai/html.{type Node}
import nakai/internal/render

/// Renders a full HTML document from the given tree, into a `StringBuilder`.
Expand Down
2 changes: 1 addition & 1 deletion src/nakai/experimental/on.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nakai/html/attrs.{Attr}
import nakai/html/attrs.{type Attr, Attr}

pub fn click(script: String) -> Attr(a) {
Attr(name: "onclick", value: script)
Expand Down
4 changes: 2 additions & 2 deletions src/nakai/experimental/web_components.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nakai/html.{Element, LeafElement, Node}
import nakai/html/attrs.{Attr}
import nakai/html.{type Node, Element, LeafElement}
import nakai/html/attrs.{type Attr}

pub fn slot(attrs: List(Attr(a))) -> Node(a) {
LeafElement(tag: "slot", attrs: attrs)
Expand Down
12 changes: 1 addition & 11 deletions src/nakai/html.gleam

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/nakai/html/attrs.gleam

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/nakai/internal/document.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gleam/option.{Option}
import gleam/option.{type Option}
import gleam/list
import gleam/string_builder.{StringBuilder}
import gleam/string_builder.{type StringBuilder}

pub const encoding = "
<meta charset=\"utf-8\" />
Expand Down
12 changes: 7 additions & 5 deletions src/nakai/internal/render.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import gleam/list
import gleam/option
import gleam/string_builder.{StringBuilder}
import gleam/string_builder.{type StringBuilder}
import gleam/string
import nakai/html.{Node}
import nakai/html/attrs.{Attr, Event}
import nakai/internal/document.{Document}
import nakai/html.{type Node}
import nakai/html/attrs.{type Attr, Attr, Event}
import nakai/internal/document.{type Document}

type Builder(a, output) {
Builder(map: fn(Node(a)) -> output, fold: fn(List(output)) -> output)
Expand Down Expand Up @@ -166,7 +166,9 @@ fn render_inline_node(tree: Node(a)) -> StringBuilder {
html.UnsafeInlineHtml(content) -> string_builder.from_string(content)

html.Script(script) ->
render_inline_node(html.Element("script", [], [html.Text(script)]))
render_inline_node(
html.Element("script", [attrs.type_("module")], [html.Text(script)]),
)

html.Nothing -> string_builder.new()
}
Expand Down
8 changes: 4 additions & 4 deletions test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ runs:
steps:
- uses: erlef/setup-beam@v1
with:
elixir-version: "1.14"
otp-version: "25.2"
gleam-version: "0.28.3"
rebar3-version: "3.20.0"
elixir-version: "1.15"
otp-version: "26.1"
gleam-version: "0.33.0"
rebar3-version: "3.22.1"

- run: |
gleam format
Expand Down
60 changes: 46 additions & 14 deletions test/nakai/codegen.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Not actually a test, but having this file in test/ prevents it from being published :^)

import gleam/dynamic.{Dynamic}
import gleam/dynamic.{type Dynamic}
import gleam/erlang/file
import gleam/json
import gleam/list
Expand Down Expand Up @@ -42,21 +42,43 @@ fn codegen_element(element: ElementDescription) -> String {
case element {
Element(name, leaf) if leaf == False ->
"
/// The [HTML `<" <> name <> ">` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/" <> name <> ")
pub fn " <> name <> "(attrs: List(Attr(a)), children: List(Node(a))) -> Node(a) {
Element(tag: \"" <> name <> "\", attrs: attrs, children: children)
/// The [HTML `<"
<> name
<> ">` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/"
<> name
<> ")
pub fn "
<> name
<> "(attrs: List(Attr(a)), children: List(Node(a))) -> Node(a) {
Element(tag: \""
<> name
<> "\", attrs: attrs, children: children)
}
/// Shorthand for `html." <> name <> "(attrs, children: [html.Text(text)])`
pub fn " <> name <> "_text(attrs: List(Attr(a)), text: String) -> Node(a) {
Element(tag: \"" <> name <> "\", attrs: attrs, children: [Text(text)])
/// Shorthand for `html."
<> name
<> "(attrs, children: [html.Text(text)])`
pub fn "
<> name
<> "_text(attrs: List(Attr(a)), text: String) -> Node(a) {
Element(tag: \""
<> name
<> "\", attrs: attrs, children: [Text(text)])
}
"
Element(name, leaf) if leaf == True ->
"
/// The [HTML `<" <> name <> " />` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/" <> name <> ")
pub fn " <> name <> "(attrs: List(Attr(a))) -> Node(a) {
LeafElement(tag: \"" <> name <> "\", attrs: attrs)
/// The [HTML `<"
<> name
<> " />` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/"
<> name
<> ")
pub fn "
<> name
<> "(attrs: List(Attr(a))) -> Node(a) {
LeafElement(tag: \""
<> name
<> "\", attrs: attrs)
}
"
_ -> panic
Expand Down Expand Up @@ -128,14 +150,24 @@ fn codegen_attr(attr: AttrDescription) -> String {
case attr {
Attr(_) ->
"
pub fn " <> func_name <> "(value: String) -> Attr(a) {
Attr(name: \"" <> name <> "\", value: value)
pub fn "
<> func_name
<> "(value: String) -> Attr(a) {
Attr(name: \""
<> name
<> "\", value: value)
}
"
ConstAttr(_, value) ->
"
pub fn " <> func_name <> "() -> Attr(a) {
Attr(name: \"" <> name <> "\", value: \"" <> value <> "\")
pub fn "
<> func_name
<> "() -> Attr(a) {
Attr(name: \""
<> name
<> "\", value: \""
<> value
<> "\")
}
"
}
Expand Down
35 changes: 13 additions & 22 deletions test/nakai/integration/info.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,22 @@ import nakai/html/attrs
import snapshot

pub fn navigation() {
html.nav(
[],
[
html.ul(
[],
[
html.li([], [html.a_text([attrs.href("/home")], "home")]),
html.li([], [html.a_text([attrs.href("/about")], "about")]),
],
),
],
)
html.nav([], [
html.ul([], [
html.li([], [html.a_text([attrs.href("/home")], "home")]),
html.li([], [html.a_text([attrs.href("/about")], "about")]),
]),
])
}

pub fn app() {
html.div(
[],
[
html.Html([attrs.lang("en-US")], [navigation()]),
html.Head([html.title("hello, computer!")]),
html.Body([attrs.class("post")], []),
html.h1_text([], "hello, computer!"),
html.p_text([], "this is a paragraph"),
],
)
html.div([], [
html.Html([attrs.lang("en-US")], [navigation()]),
html.Head([html.title("hello, computer!")]),
html.Body([attrs.class("post")], []),
html.h1_text([], "hello, computer!"),
html.p_text([], "this is a paragraph"),
])
}

pub fn app_test() {
Expand Down
11 changes: 4 additions & 7 deletions test/nakai/integration/puppies.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ fn puppies_list() {
}

pub fn app() {
html.Html(
[attrs.lang("en-US")],
[
html.Head([html.title("List of puppies!")]),
html.div([], [puppies_list()]),
],
)
html.Html([attrs.lang("en-US")], [
html.Head([html.title("List of puppies!")]),
html.div([], [puppies_list()]),
])
}

pub fn app_test() {
Expand Down
Loading

0 comments on commit 7bf097d

Please sign in to comment.