Sheetshow.Style (Sheetshow v0.1.0)

Copy Markdown View Source

How a cell looks: a plain map with atom keys, so styles compose with Map.merge/2 and read well when inspected.

%{bold: true, background: "#FFF2CC", number_format: "0.00%"}
KeyValue
:bold, :italic, :underline, :strikethroughboolean()
:font_sizepoints, a positive integer
:font_family"Roboto"
:colortext colour, "#RRGGBB"
:backgroundfill colour, "#RRGGBB"
:horizontal:left, :center or :right
:vertical:top, :middle or :bottom
:wrap:overflow, :clip or :wrap
:number_formata Sheets pattern, "#,##0.00", "yyyy-mm-dd"
:col_widthpixels, a positive integer
:row_heightpixels, a positive integer

:col_width and :row_height describe the column and row the cell sits in rather than the cell; writers lift them out. Validation happens where a style is about to be written, not when you build it.

Summary

Functions

A "#RRGGBB" colour as {red, green, blue} in 0..255.

Every key a style may have.

{red, green, blue} in 0..255 as "#RRGGBB".

Whether the term is a valid style.

Checks every key and value.

Types

color()

@type color() :: String.t()

t()

@type t() :: %{optional(atom()) => term()}

Functions

hex_to_rgb(arg)

@spec hex_to_rgb(color()) :: {0..255, 0..255, 0..255}

A "#RRGGBB" colour as {red, green, blue} in 0..255.

iex> Sheetshow.Style.hex_to_rgb("#FF8800")
{255, 136, 0}

keys()

@spec keys() :: [atom()]

Every key a style may have.

rgb_to_hex(arg)

@spec rgb_to_hex({0..255, 0..255, 0..255}) :: color()

{red, green, blue} in 0..255 as "#RRGGBB".

iex> Sheetshow.Style.rgb_to_hex({255, 136, 0})
"#FF8800"

valid?(style)

@spec valid?(term()) :: boolean()

Whether the term is a valid style.

validate(style)

@spec validate(term()) :: :ok | {:error, Sheetshow.Error.t()}

Checks every key and value.

iex> Sheetshow.Style.validate(%{bold: true, horizontal: :center})
:ok
iex> {:error, %Sheetshow.Error{reason: :invalid_style, details: %{key: :bolt}}} =
...>   Sheetshow.Style.validate(%{bolt: true})
iex> {:error, %Sheetshow.Error{details: %{key: :font_size, value: 0}}} =
...>   Sheetshow.Style.validate(%{font_size: 0})