Skip to content

Commit

Permalink
Add hash to base0x custom generated schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden committed Oct 22, 2024
1 parent c216652 commit 5cc49d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions tinted-builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### Changed

- `Base16Scheme` palette hex values are now prepended with a hash `#` to
allow text editors to optionally highlight the color. This is optional
under the `0.11.2` builder specification

## 0.8.0 - 2024-10-05

## Added
Expand Down
8 changes: 5 additions & 3 deletions tinted-builder/src/scheme/base16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl fmt::Display for Base16Scheme {
palette_vec.sort_by_key(|k| k.0.clone());

for (key, value) in palette_vec {
writeln!(f, " {}: \"{}\"", key, value)?;
writeln!(f, " {}: \"#{}\"", key, value)?;
}
Ok(())
}
Expand Down Expand Up @@ -136,7 +136,9 @@ impl Serialize for Base16Scheme {
state.serialize_field("name", &self.name)?;
state.serialize_field("slug", &self.slug)?;
state.serialize_field("author", &self.author)?;
state.serialize_field("description", &self.description)?;
if let Some(description) = &self.description {
state.serialize_field("description", description)?;
}
state.serialize_field("variant", &self.variant)?;

// Collect and sort the palette by key
Expand All @@ -160,7 +162,7 @@ impl<'a> Serialize for SortedPalette<'a> {
{
let mut map = serializer.serialize_map(Some(self.0.len()))?;
for (key, value) in &self.0 {
map.serialize_entry(key, &value.to_hex())?;
map.serialize_entry(key, format!("#{}", &value.to_hex()).as_str())?;
}
map.end()
}
Expand Down

0 comments on commit 5cc49d0

Please sign in to comment.