Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Update the code generation to use a pinned version of the palette JSON
  by using a pinned commit hash
- Update the LICENSE to be Catppuccin
- update usages of `Flavour` to `Flavor` and `Colour` to `Color`
  • Loading branch information
MAHcodes committed May 18, 2024
1 parent 51e8546 commit 27add12
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 106 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 MAH
Copyright (c) 2024 Catppuccin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion codegen/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 MAH
Copyright (c) 2024 Catppuccin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
84 changes: 50 additions & 34 deletions codegen/src/catppuccin.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ pub type Colors {
)
}

pub type Flavour {
Flavour(name: String, order: Int, dark: Bool, colors: Colors)
pub type Flavor {
Flavor(name: String, emoji: String, order: Int, dark: Bool, colors: Colors)
}

pub type Palette {
Palette(latte: Flavour, frappe: Flavour, macchiato: Flavour, mocha: Flavour)
Palette(latte: Flavor, frappe: Flavor, macchiato: Flavor, mocha: Flavor)
}

fn fetch_palette() -> String {
let url =
"https://raw.githubusercontent.com/catppuccin/palette/main/palette.json"
"https://raw.githubusercontent.com/catppuccin/palette/d751858ffffbff1ed19064ceba69d2a5515ec2bb/palette.json"
let assert Ok(req) = request.to(url)
let assert Ok(resp) = httpc.send(req)
resp.body
Expand Down Expand Up @@ -128,21 +128,22 @@ fn parse_palette(palette_string: String) -> Palette {
field("mantle", color_decoder),
field("crust", color_decoder),
)
let flavour_decoder =
dynamic.decode4(
Flavour,
let flavor_decoder =
dynamic.decode5(
Flavor,
field("name", string),
field("emoji", string),
field("order", int),
field("dark", bool),
field("colors", colors_decoder),
)
let palette_decoder =
dynamic.decode4(
Palette,
field("latte", flavour_decoder),
field("frappe", flavour_decoder),
field("macchiato", flavour_decoder),
field("mocha", flavour_decoder),
field("latte", flavor_decoder),
field("frappe", flavor_decoder),
field("macchiato", flavor_decoder),
field("mocha", flavor_decoder),
)

let assert Ok(palette) = json.decode(palette_string, palette_decoder)
Expand Down Expand Up @@ -171,10 +172,10 @@ fn generate_catppuccin(palette: Palette) {
[
template_header(),
template_opaque_colors(),
template_flavour(palette.latte, "latte"),
template_flavour(palette.frappe, "frappe"),
template_flavour(palette.macchiato, "macchiato"),
template_flavour(palette.mocha, "mocha"),
template_flavor(palette.latte, "latte"),
template_flavor(palette.frappe, "frappe"),
template_flavor(palette.macchiato, "macchiato"),
template_flavor(palette.mocha, "mocha"),
]
|> string.concat

Expand All @@ -188,8 +189,8 @@ fn template_header() -> String {
import gleam/result
import gleam_community/colour
pub opaque type Flavour {
Flavour(name: String, order: Int, dark: Bool, colors: Colors)
pub opaque type Flavor {
Flavor(name: String, emoji: String, order: Int, dark: Bool, colors: Colors)
}
type Colors {
Expand Down Expand Up @@ -224,19 +225,28 @@ type Colors {
}
pub opaque type Color {
Color(name: String, order: Int, accent: Bool, colour: Result(colour.Colour, Nil))
Color(
name: String,
order: Int,
accent: Bool,
colour: Result(colour.Colour, Nil),
)
}
pub fn flavor_name(flavor: Flavor) -> String {
flavor.name
}
pub fn flavour_name(flavour: Flavour) -> String {
flavour.name
pub fn emoji(flavor: Flavor) -> String {
flavor.emoji
}
pub fn flavour_order(flavour: Flavour) -> Int {
flavour.order
pub fn flavor_order(flavor: Flavor) -> Int {
flavor.order
}
pub fn dark(flavour: Flavour) -> Bool {
flavour.dark
pub fn dark(flavor: Flavor) -> Bool {
flavor.dark
}
pub fn color_name(color: Color) -> String {
Expand All @@ -257,26 +267,32 @@ pub fn accent(color: Color) -> Bool {
pub fn to_colour(color: Color) -> colour.Colour {
color.colour
|> result.unwrap(colour.black)
}"
}
fn template_flavour(flavour: Flavour, key: String) -> String {
/// alias for `to_colour`
///
pub const to_color: fn(Color) -> colour.Colour = to_colour"
}

fn template_flavor(flavor: Flavor, key: String) -> String {
let assert Ok(glormatted) =
"\n
pub fn {key}() -> Flavour {
Flavour(
pub fn {key}() -> Flavor {
Flavor(
name: \"{name}\",
emoji: \"{emoji}\",
order: {order},
dark: {dark},
colors: Colors({colors}
),
)
}"
|> replace("key", key)
|> then("name", flavour.name)
|> then("order", int.to_string(flavour.order))
|> then("dark", to_string(flavour.dark))
|> then("colors", template_colors(flavour.colors))
|> then("name", flavor.name)
|> then("emoji", flavor.emoji)
|> then("order", int.to_string(flavor.order))
|> then("dark", to_string(flavor.dark))
|> then("colors", template_colors(flavor.colors))
glormatted
}

Expand Down Expand Up @@ -335,8 +351,8 @@ fn template_color(color: Color, key: String) -> String {
fn template_opaque_color(key: String) -> String {
let assert Ok(glormatted) =
"\n
pub fn {key}(flavour: Flavour) -> Color {
flavour.colors.{key}
pub fn {key}(flavor: Flavor) -> Color {
flavor.colors.{key}
}"
|> replace("key", key)
glormatted
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "catppuccin"
version = "2.0.1"
version = "3.0.0"

description = "⭐️ Soothing pastel library for Gleam"
licences = ["MIT"]
Expand Down

0 comments on commit 27add12

Please sign in to comment.