Skip to content

Commit

Permalink
Don't return prefix hash with Color::to_hex method
Browse files Browse the repository at this point in the history
Release 0.9.2
  • Loading branch information
JamyGolden committed Jul 12, 2024
1 parent 2a68bbb commit 7196ba7
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 36 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.9.2] - 2024-06-24

### Fixed

- Use latest tinted-builder lib which does not generate schemes with
a hash prefix value

## [0.9.1] - 2024-06-24

### Fixed
Expand Down Expand Up @@ -111,6 +118,7 @@
- `sync` subcommand support to sync with latest Tinted Theming schemes
- `build` subcommand to trigger theme template build

[0.9.2]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/tinted-theming/tinted-builder-rust/compare/v0.7.0...v0.8.0
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tinted-builder-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tinted-builder-rust"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
authors = ["Jamy Golden <code@jamygolden.com>", "Tinted Theming <tintedtheming@proton.me>"]
license = "MIT OR Apache-2.0"
Expand All @@ -24,7 +24,7 @@ strip-ansi-escapes = "0.2.0"

[dependencies.tinted-builder]
path = "../tinted-builder"
version = "0.4.4"
version = "0.4.5"

[[bin]]
name = "tinted-builder-rust"
Expand Down
6 changes: 6 additions & 0 deletions tinted-builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.4.5 - 2024-07-12

## Fixed

- Remove hash from `Color::to_hex` returned string

## 0.4.4 - 2024-06-22

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion tinted-builder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tinted-builder"
description = "A Tinted Theming template builder which uses yaml color schemes to generate theme files."
version = "0.4.4"
version = "0.4.5"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tinted-builder/src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(crate) fn slugify(input: &str) -> String {
}
}

let re = Regex::new(r"-+").unwrap();
let re = Regex::new(r"-+").expect("Unable to unwrap regex");
let cleaned_slug = re.replace_all(&slug, "-").to_string();

cleaned_slug.trim_matches('-').to_string()
Expand Down
22 changes: 10 additions & 12 deletions tinted-builder/src/scheme/color.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::fmt;

use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Color {
Expand All @@ -12,28 +12,26 @@ pub struct Color {

impl Color {
pub fn new(hex_color: String) -> Result<Color> {
let hex_full = match process_hex_input(&hex_color) {
Some(valid_hex) => valid_hex,
None => {
anyhow::bail!("Provided hex value is not formatted correctly");
}
};

let hex_full = process_hex_input(&hex_color)
.ok_or_else(|| anyhow::anyhow!("Provided hex value is not formatted correctly"))?;
let hex: (String, String, String) = (
hex_full[0..2].to_lowercase(),
hex_full[2..4].to_lowercase(),
hex_full[4..6].to_lowercase(),
);
let rgb = hex_to_rgb(&hex)
.unwrap_or_else(|_| panic!("Unable to convert hex value to rgb: {}", hex_full));
let (r, g, b) = rgb;
let dec: (f32, f32, f32) = (r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0);
.map_err(|_| anyhow!("Unable to convert hex value to rgb: {}", hex_full))?;
let dec: (f32, f32, f32) = (
rgb.0 as f32 / 255.0,
rgb.1 as f32 / 255.0,
rgb.2 as f32 / 255.0,
);

Ok(Color { hex, rgb, dec })
}

pub fn to_hex(&self) -> String {
format!("#{}{}{}", &self.hex.0, &self.hex.1, &self.hex.2)
format!("{}{}{}", &self.hex.0, &self.hex.1, &self.hex.2)
}
}

Expand Down
36 changes: 18 additions & 18 deletions tinted-builder/tests/general.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
use anyhow::Result;
use tinted_builder::{Scheme, Template};

const SCHEME_SILK_LIGHT: &str = r#"
const SCHEME_SILK_LIGHT: &str = r##"
system: "base16"
name: "Silk Light"
slug: "siłk light"
author: "Gabriel Fontes (https://github.com/Misterio77)"
variant: "light"
palette:
base00: "E9F1EF"
base01: "CCD4D3"
base02: "90B7B6"
base03: "5C787B"
base04: "4B5B5F"
base05: "385156"
base06: "0e3c46"
base07: "D2FAFF"
base08: "CF432E"
base09: "D27F46"
base0A: "CFAD25"
base0B: "6CA38C"
base0C: "329CA2"
base0D: "39AAC9"
base0E: "6E6582"
base0F: "865369"
"#;
base00: "#E9F1EF"
base01: "#CCD4D3"
base02: "#90B7B6"
base03: "#5C787B"
base04: "#4B5B5F"
base05: "#385156"
base06: "#0e3c46"
base07: "#D2FAFF"
base08: "#CF432E"
base09: "#D27F46"
base0A: "#CFAD25"
base0B: "#6CA38C"
base0C: "#329CA2"
base0D: "#39AAC9"
base0E: "#6E6582"
base0F: "#865369"
"##;

const SCHEME_CRAZY: &str = r#"
system: "base16"
Expand Down

0 comments on commit 7196ba7

Please sign in to comment.