#base-16 #color-scheme #yaml #render-template #base24 #tinted-theming

tinted-builder

A Tinted Theming template builder which uses yaml color schemes to generate theme files

14 releases (7 breaking)

0.8.0 Oct 5, 2024
0.6.0 Aug 31, 2024
0.5.0 Jul 12, 2024

#211 in Template engine

Download history 70/week @ 2024-07-14 4/week @ 2024-07-21 40/week @ 2024-07-28 1/week @ 2024-08-04 7/week @ 2024-08-11 219/week @ 2024-08-18 144/week @ 2024-08-25 216/week @ 2024-09-01 25/week @ 2024-09-08 74/week @ 2024-09-15 129/week @ 2024-09-22 201/week @ 2024-09-29 181/week @ 2024-10-06 32/week @ 2024-10-13 27/week @ 2024-10-20 11/week @ 2024-10-27

333 downloads per month
Used in 3 crates

MIT/Apache

31KB
530 lines

tinted-builder

Matrix Chat Crates.io Tests

A Rust library to generate base16 and base24 templates using the 0.11.1 builder specification.

This library exposes a Scheme and Template struct which you can use to generate your own themes using base16 and base24 templates and 0.11.1 compliant base16 and base24 scheme files.

Internally tinted-builder uses ribboncurls to render the templates.

Installation

cargo add tinted-builder

Usage

use tinted_builder::{Scheme, Template};

let template = String::from(r#"/* Some CSS file with {{scheme-name}} theme */
.someCssSelector { background-color: #{{base00-hex}} }
.someOtherCssSelector { background-color: #{{base0F-hex}} }"#);
let scheme_str = r#"system: "base16"
name: "UwUnicorn"
author: "Fernando Marques (https://github.com/RakkiUwU) and Gabriel Fontes (https://github.com/Misterio77)"
variant: "dark"
palette:
  base00: "241b26"
  base01: "2f2a3f"
  base02: "46354a"
  base03: "6c3cb2"
  base04: "7e5f83"
  base05: "eed5d9"
  base06: "d9c2c6"
  base07: "e4ccd0"
  base08: "877bb6"
  base09: "de5b44"
  base0A: "a84a73"
  base0B: "c965bf"
  base0C: "9c5fce"
  base0D: "6a9eb5"
  base0E: "78a38f"
  base0F: "a3a079""#;
let scheme = Scheme::Base16(serde_yaml::from_str(&scheme_str).unwrap());
let template = Template::new(template, scheme);
let output = template
  .render()
  .unwrap();

  assert_eq!(output, r#"/* Some CSS file with UwUnicorn theme */
.someCssSelector { background-color: #241b26 }
.someOtherCssSelector { background-color: #a3a079 }"#);
  1. Create a scheme (Scheme) enum variant while providing the deserialized data into into the variant: Scheme::Base16(serde_yaml::from_str(&scheme_str).unwrap()) in this case
  2. Create a template by passing the serialized mustache text and the Scheme variant in step 1 into the Template struct: Template::new(mustache_text, scheme). The template.render() method takes the scheme, generates the variables defined in the 0.11.1 builder specification and returns a new string.
  3. Render the template by running a method which returns a Result<String, TintedBuilderError> type: let output = template.render().unwrap();

Contributing

Contributions are welcome! Have a look at CONTRIBUTING.md for more information.

License

Ribboncurls is dual-licensed under the [Apache 2.0] and [MIT] licenses. For more information about the licenses of the projects used by Ribboncurls, have a look at LICENSES-THIRD-PARTY.md.

Dependencies

~7–19MB
~230K SLoC