Skip to content

Commit f64a0ff

Browse files
committed
Start CSV example
1 parent 367971d commit f64a0ff

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Examples showing how to do many things in Gleam!
2929
## Formats
3030

3131
- [Parsing TOML](./universal/test/formats/parsing_toml.gleam)
32+
- [Rendering CSV](./universal/test/formats/rendering_csv.gleam)
3233
- [Rendering HTML](./universal/test/formats/rendering_html.gleam)
3334
- [Rendering JSON](./universal/test/formats/rendering_json.gleam)
3435
- [Rendering XML](./universal/test/formats/rendering_xml.gleam)

universal/gleam.toml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,16 @@ name = "cookbook"
22
version = "1.0.0"
33
target = "javascript"
44

5-
# Fill out these fields if you intend to generate HTML documentation or publish
6-
# your project to the Hex package manager.
7-
#
8-
# description = ""
9-
# licences = ["Apache-2.0"]
10-
# repository = { type = "github", user = "", repo = "" }
11-
# links = [{ title = "Website", href = "" }]
12-
#
13-
# For a full reference of all the available options, you can have a look at
14-
# https://gleam.run/writing-gleam/gleam-toml/.
15-
165
[dependencies]
17-
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
18-
simplifile = ">= 2.1.0 and < 3.0.0"
19-
xmb = ">= 1.0.0 and < 2.0.0"
6+
envoy = ">= 1.0.2 and < 2.0.0"
7+
gleam_crypto = ">= 1.3.0 and < 2.0.0"
208
gleam_json = ">= 1.0.1 and < 2.0.0"
9+
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
10+
gsv = ">= 2.0.0 and < 3.0.0"
2111
lustre = ">= 4.4.4 and < 5.0.0"
22-
gleam_crypto = ">= 1.3.0 and < 2.0.0"
12+
simplifile = ">= 2.1.0 and < 3.0.0"
2313
tom = ">= 1.1.0 and < 2.0.0"
24-
envoy = ">= 1.0.2 and < 2.0.0"
14+
xmb = ">= 1.0.0 and < 2.0.0"
2515

2616
[dev-dependencies]
2717
gleeunit = ">= 1.0.0 and < 2.0.0"

universal/manifest.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ packages = [
1010
{ name = "gleam_otp", version = "0.12.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "CD5FC777E99673BDB390092DF85E34EAA6B8EE1882147496290AB3F45A4960B1" },
1111
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
1212
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
13+
{ name = "gsv", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gsv", source = "hex", outer_checksum = "DBC35126CB3621D305EC2412C9D43F90D496692BB58BA3BEDF70C1AD34143587" },
1314
{ name = "lustre", version = "4.4.4", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "35A8597B3054AFAF734A54979B7C92D8AB43273B843717F854CF5A05CF2BC00E" },
1415
{ name = "simplifile", version = "2.1.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "BDD04F5D31D6D34E2EDFAEF0B68A6297AEC939888C3BFCE61133DE13857F6DA2" },
1516
{ name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" },
@@ -23,6 +24,7 @@ gleam_crypto = { version = ">= 1.3.0 and < 2.0.0" }
2324
gleam_json = { version = ">= 1.0.1 and < 2.0.0" }
2425
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
2526
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
27+
gsv = { version = ">= 2.0.0 and < 3.0.0" }
2628
lustre = { version = ">= 4.4.4 and < 5.0.0" }
2729
simplifile = { version = ">= 2.1.0 and < 3.0.0" }
2830
tom = { version = ">= 1.1.0 and < 2.0.0" }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// # Rendering CSV
2+
////
3+
//// The gsv package can be used to parser and render CSV on all targets.
4+
////
5+
//// ## Dependencies
6+
////
7+
//// - https://hex.pm/packages/gsv
8+
9+
import gleam/dict
10+
import gleeunit/should
11+
import gsv
12+
13+
pub fn main_test() {
14+
let data = [
15+
dict.from_list([#("name", "Lucy"), #("score", "100"), #("colour", "Pink")]),
16+
dict.from_list([
17+
#("name", "Isaac"),
18+
#("youtube", "@IsaacHarrisHolt"),
19+
#("score", "99"),
20+
]),
21+
]
22+
23+
gsv.from_dicts(data, ",", gsv.Unix)
24+
|> should.equal(
25+
"colour,name,score,youtube
26+
Pink,Lucy,100,
27+
,Isaac,99,@IsaacHarrisHolt
28+
",
29+
)
30+
}

0 commit comments

Comments
 (0)