base16cs
A library for defining a palette of base colors in canonical CIE L*a*b* colorspace values, and then deriving other colorspace values from them.
This library also provides serializers and deserializers for palettes, and a template renderer (Liquid, by default) for injecting palette and color variables into a template for renders.
Examples
Define a palette, derive values, and serialize
use ;
use Serializable;
// Define a canonical palette
let palette = new;
// Derive with computed sRGB values
let derived_palette = from;
// Serialize (to YAML)
let serialized = derived_palette.serialize.unwrap;
assert_eq!;
Load a serialized base palette, derive, then inject into a Liquid template
use ;
use LiquidTemplate;
let palette_yaml = read_to_string.unwrap;
let palette = from_yaml.unwrap;
let template = parse_file.unwrap;
// `template.render()` will take care of deriving `palette` for us.
println!;
Liquid template render with palette injection
When a Liquid template is rendered, it will be injected with a Liquid object
keyed to "palette". The Liquid object value is a serialization of a
DerivedPalette.
Let's say /path/to/template.liquid contains:
Palette name: {{ palette.name }}
Palette colors:
{%- for color in palette.colors -%}
{{ color.base.name }}: #{{ color.srgb_hex }}
{%- endfor -%}
Rendering this with the palette above would result in:
Palette name: My Palette
Palette colors:
bg: #fef3da