-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(whiskers): add colors object in context #104
Conversation
This would be fantastic, along with the HSL changes I mentioned in Discord in a separate PR. |
This would probably be a good time to use the new standardized palette format that I talked to @backwardspy about; let accent_names = ["rosewater", ..., "lavender"];
context["colors"] = colors
.into_fields_iter()
.map(|(name, c)| {
(
name.to_string(),
json!({
"hex": c.hex().to_ascii_lowercase(),
"isAccent": accent_names.contains(&name),
}),
)
})
.collect(); which could be used like {{#each colors}}
{{#if this.accent}}
func ({{../flavor}}) {{titlecase @key}}() Color {
return Color{
Hex: "#{{this.hex}}",
RGB: [3]uint32{ {{red_i this.hex}}, {{green_i this.hex}}, {{blue_i this.hex}}},
HSL: [3]float32{ {{hsl this.hex}}},
}
}
{{/if}}
{{/each}} The use case for ports would be
After a second look, I'm actually not a fan of using functions to generate the colors, I think it'd be better if all the colors came from our color definitions first.
$ deno
Deno 1.37.1
> import tinycolor from "https://esm.sh/tinycolor2"
undefined
> tinycolor("#000")
{
_originalInput: "#000",
_r: 0,
_g: 0,
_b: 0,
_a: 1,
_roundA: 1,
_format: "hex",
_gradientType: undefined,
_ok: true
} |
@nekowinston that's actually how whiskers worked originally, but i hit several issues passing full objects around the handlebars context, specifically when accepting them as arguments to the helper macros. after fixing that (by not using the helper macro), i ran into another issue with that's why it's now colours-as-hexcodes with helper functions to convert them into other formats, because things like if you know of a way to make that all work with rich colour objects, i would certainly be interested in seeing it. the theory is nice, i just could not make it work well. |
that aside, this pr looks great. thanks, like you i'm not sure how we missed this off as a feature again! |
{{ lookup (darken colors.pink 10) "hex" }} would work, using subexpressions, but I'm not sure if I'm a fan of that. 🤔 Another option would be having an optional paramter, e.g {{ darken colors.pink 10 "rgb" }} Quick Gist in Deno https://gist.github.com/nekowinston/c3626cce3ad72eb84718cf74393e8e87 sorry if this is totally out of scope for this PR, I should probably create a new issue 😅 |
sounds good, let's play with some designs on a dedicated issue and i'll approve this PR |
I saw catppuccin/go#10 and was kinda surprised that we overlooked iterating colors, again.
This shortens the whole go lib template to: