Skip to content

Commit

Permalink
color: generate functions using a macro (#4)
Browse files Browse the repository at this point in the history
* color: change to generating the function via a macro

* version: bump patch

* color: simplify doc generation
  • Loading branch information
MikaelFangel authored Jun 3, 2024
1 parent b1962de commit de490a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 168 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@
```elixir
def deps do
[
{:catppuccin, github: "MikaelFangel/elixir", tag: "v0.1.1"}
{:catppuccin, github: "MikaelFangel/elixir", tag: "v0.1.2"}
]
end
```
Expand Down
175 changes: 9 additions & 166 deletions lib/catppuccin/color.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule Catppuccin.Color do

alias Catppuccin.Flavor

@color_names ~w(rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender text subtext1 subtext0 overlay2 overlay1 overlay0 surface2 surface1 surface0 base mantle crust)

@typedoc """
Data structure representing a color i hex, rgb, and hsl.
"""
Expand Down Expand Up @@ -97,172 +99,13 @@ defmodule Catppuccin.Color do
Map.get(colors, color_name)
end

@doc """
Returns the color data for the rosewater color for a given flavor.
## Examples
iex> Catppuccin.latte |> Catppuccin.Color.rosewater
%Catppuccin.Color{
name: "Rosewater",
order: 0,
hex: "#dc8a78",
rgb: {220, 138, 120},
hsl: {10.799999999999995, 0.5882352941176472, 0.6666666666666667},
accent: true
}
for color_name <- @color_names do
Module.register_attribute(__MODULE__, :doc, accumulate: true)

"""
@spec rosewater({atom(), Flavor.t()}) :: Color.t() | nil
def rosewater(flavor), do: color_accessor(:rosewater, flavor)

@doc """
Returns the color data for the flamingo color for a given flavor.
"""
@spec flamingo({atom(), Flavor.t()}) :: Color.t() | nil
def flamingo(flavor), do: color_accessor(:flamingo, flavor)

@doc """
Returns the color data for the pink color for a given flavor.
"""
@spec pink({atom(), Flavor.t()}) :: Color.t() | nil
def pink(flavor), do: color_accessor(:pink, flavor)

@doc """
Returns the color data for the mauve color for a given flavor.
"""
@spec mauve({atom(), Flavor.t()}) :: Color.t() | nil
def mauve(flavor), do: color_accessor(:mauve, flavor)

@doc """
Returns the color data for the red color for a given flavor.
"""
@spec red({atom(), Flavor.t()}) :: Color.t() | nil
def red(flavor), do: color_accessor(:red, flavor)

@doc """
Returns the color data for the maroon color for a given flavor.
"""
@spec maroon({atom(), Flavor.t()}) :: Color.t() | nil
def maroon(flavor), do: color_accessor(:maroon, flavor)
@doc """
Returns the `#{color_name}` color for the given `flavor`.
"""

@doc """
Returns the color data for the peach color for a given flavor.
"""
@spec peach({atom(), Flavor.t()}) :: Color.t() | nil
def peach(flavor), do: color_accessor(:peach, flavor)

@doc """
Returns the color data for the yellow color for a given flavor.
"""
@spec yellow({atom(), Flavor.t()}) :: Color.t() | nil
def yellow(flavor), do: color_accessor(:yellow, flavor)

@doc """
Returns the color data for the green color for a given flavor.
"""
@spec green({atom(), Flavor.t()}) :: Color.t() | nil
def green(flavor), do: color_accessor(:green, flavor)

@doc """
Returns the color data for the teal color for a given flavor.
"""
@spec teal({atom(), Flavor.t()}) :: Color.t() | nil
def teal(flavor), do: color_accessor(:teal, flavor)

@doc """
Returns the color data for the sky color for a given flavor.
"""
@spec sky({atom(), Flavor.t()}) :: Color.t() | nil
def sky(flavor), do: color_accessor(:sky, flavor)

@doc """
Returns the color data for the sapphire color for a given flavor.
"""
@spec sapphire({atom(), Flavor.t()}) :: Color.t() | nil
def sapphire(flavor), do: color_accessor(:sapphire, flavor)

@doc """
Returns the color data for the blue color for a given flavor.
"""
@spec blue({atom(), Flavor.t()}) :: Color.t() | nil
def blue(flavor), do: color_accessor(:blue, flavor)

@doc """
Returns the color data for the lavender color for a given flavor.
"""
@spec lavender({atom(), Flavor.t()}) :: Color.t() | nil
def lavender(flavor), do: color_accessor(:lavender, flavor)

@doc """
Returns the color data for the test color for a given flavor.
"""
@spec text({atom(), Flavor.t()}) :: Color.t() | nil
def text(flavor), do: color_accessor(:text, flavor)

@doc """
Returns the color data for the subtext1 color for a given flavor.
"""
@spec subtext1({atom(), Flavor.t()}) :: Color.t() | nil
def subtext1(flavor), do: color_accessor(:subtext1, flavor)

@doc """
Returns the color data for the subtext0 color for a given flavor.
"""
@spec subtext0({atom(), Flavor.t()}) :: Color.t() | nil
def subtext0(flavor), do: color_accessor(:subtext0, flavor)

@doc """
Returns the color data for the overlay2 color for a given flavor.
"""
@spec overlay2({atom(), Flavor.t()}) :: Color.t() | nil
def overlay2(flavor), do: color_accessor(:overlay2, flavor)

@doc """
Returns the color data for the overlay1 color for a given flavor.
"""
@spec overlay1({atom(), Flavor.t()}) :: Color.t() | nil
def overlay1(flavor), do: color_accessor(:overlay1, flavor)

@doc """
Returns the color data for the overlay0 color for a given flavor.
"""
@spec overlay0({atom(), Flavor.t()}) :: Color.t() | nil
def overlay0(flavor), do: color_accessor(:overlay0, flavor)

@doc """
Returns the color data for the surface2 color for a given flavor.
"""
@spec surface2({atom(), Flavor.t()}) :: Color.t() | nil
def surface2(flavor), do: color_accessor(:surface2, flavor)

@doc """
Returns the color data for the surface1 color for a given flavor.
"""
@spec surface1({atom(), Flavor.t()}) :: Color.t() | nil
def surface1(flavor), do: color_accessor(:surface1, flavor)

@doc """
Returns the color data for the surface0 color for a given flavor.
"""
@spec surface0({atom(), Flavor.t()}) :: Color.t() | nil
def surface0(flavor), do: color_accessor(:surface0, flavor)

@doc """
Returns the color data for the base color for a given flavor.
"""
@spec base({atom(), Flavor.t()}) :: Color.t() | nil
def base(flavor), do: color_accessor(:base, flavor)

@doc """
Returns the color data for the mantle color for a given flavor.
"""
@spec mantle({atom(), Flavor.t()}) :: Color.t() | nil
def mantle(flavor), do: color_accessor(:mantle, flavor)

@doc """
Returns the color data for the crust color for a given flavor.
"""
@spec crust({atom(), Flavor.t()}) :: Color.t() | nil
def crust(flavor), do: color_accessor(:crust, flavor)
def unquote(:"#{color_name}")(flavor), do: color_accessor(unquote(:"#{color_name}"), flavor)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Catppuccin.MixProject do
def project do
[
app: :catppuccin,
version: "0.1.1",
version: "0.1.2",
elixir: "~> 1.15",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down

0 comments on commit de490a4

Please sign in to comment.