Skip to content

Commit

Permalink
feat(whiskers)!: switch to tera, use rich context objects (#150)
Browse files Browse the repository at this point in the history
* feat(whiskers)!: rewrite from scratch with tera and rich context

* feat(whiskers): convert demo example to tera

* feat(whiskers): convert frontmatter example to tera

* feat(whiskers): convert simple single-file example to tera

* feat(whiskers): convert overrides example to tera

* docs(whiskers): update for 2.0

* docs(whiskers): update overrides section(s)

* chore(whiskers): add beta suffix to version number

* Revert "chore(whiskers): add beta suffix to version number"

This reverts commit 2d60034.

* feat(whiskers): bring back 0.6 opacity red in demo example

* docs(whiskers): document the --dry-run flag
  • Loading branch information
backwardspy authored Mar 31, 2024
1 parent 5540590 commit 696578a
Show file tree
Hide file tree
Showing 48 changed files with 2,350 additions and 1,643 deletions.
37 changes: 26 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "catppuccin-whiskers"
version = "1.1.4"
version = "2.0.0"
authors = ["backwardspy <[email protected]>"]
edition = "2021"
description = "Soothing port creation tool for the high-spirited!"
Expand All @@ -9,27 +9,42 @@ homepage = "https://github.com/catppuccin/toolbox/tree/main/whiskers"
repository = "https://github.com/catppuccin/toolbox"
license = "MIT"

[lib]
name = "whiskers"
path = "src/lib.rs"

[[bin]]
name = "whiskers"
path = "src/main.rs"

[lints.clippy]
all = "warn"
pedantic = "warn"
nursery = "warn"
unwrap_used = "warn"
missing_errors_doc = "allow"
implicit_hasher = "allow"
cast_possible_truncation = "allow"
cast_sign_loss = "allow"

[dependencies]
anyhow = "1.0"
base64 = "0.22"
catppuccin = { version = "2.1", features = ["css-colors"] }
indexmap = { version = "2.2", features = ["serde"] }
catppuccin = { version = "2.1", features = ["serde", "css-colors"] }
clap = { version = "4.5", features = ["derive"] }
clap-stdin = "0.4"
color-eyre = { version = "0.6", default-features = false }
clap-stdin = "0.4.0"
css-colors = "1.0"
handlebars = "5.1"
regex = "1.10"
indexmap = { version = "2.2", features = ["serde"] }
itertools = "0.12"
lzma-rust = "0.1"
rmp-serde = "1.1"
semver = { version = "1.0.22", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_json = "1.0"
serde_yaml = "0.9"
tempfile = "3.10"
tempfile = "3.10.1"
tera = { version = "1.19", features = ["preserve_order"] }
thiserror = "1.0"
titlecase = "2.2"
json-patch = "1.2"

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
495 changes: 252 additions & 243 deletions README.md

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions examples/demo/input.hbs

This file was deleted.

28 changes: 28 additions & 0 deletions examples/demo/input.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
whiskers:
version: "2.0.0"
---
## Demo

**flavor:** {{ flavor.name }}

### Colours
{% set lightred = red | add(lightness=10) -%}
{% set darkred = red | sub(lightness=10) -%}
{% set palered = red | mix(color=base, amount=0.3) -%}
{% set fadered1 = red | mod(opacity=0.6) -%}
{% set fadered2 = red | mod(opacity=0.5) -%}

- **red:** #{{ red.hex }} / {{ css_rgb(color=red) }} / {{ css_hsl(color=red) }}
- **components:** r: {{ red.rgb.r }} / {{ red.rgb.r / 255 | trunc(places=2) }}, g: {{ red.rgb.g }} / {{ red.rgb.g / 255 | trunc(places=2) }}, b: {{ red.rgb.b }} / {{ red.rgb.b / 255 | trunc(places=2) }}
- **alpha:** {{ fadered1.opacity }} / {{ fadered1.opacity / 255 | trunc(places=2) }}
- **10% lighter:** #{{ lightred.hex }} / {{ css_rgb(color=lightred) }} / {{ css_hsl(color=lightred) }}
- **10% darker:** #{{ darkred.hex }} / {{ css_rgb(color=darkred) }} / {{ css_hsl(color=darkred) }}

- **30% mix with base:** #{{ palered.hex }} / {{ css_rgb(color=palered) }} / {{ css_hsl(color=palered) }}

- **50% opacity:** #{{ fadered2.hex }} / {{ css_rgba(color=fadered2) }} / {{ css_hsla(color=fadered2) }}

### Conditionals

this is a {{ if(cond=flavor.dark, t="dark", f="light") }} theme
2 changes: 1 addition & 1 deletion examples/demo/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ clean:

# Generate a single flavor, e.g. "mocha"
gen flavor:
@{{whiskers_cmd}} input.hbs {{flavor}} -o {{output}}/{{flavor}}.md
@{{whiskers_cmd}} input.tera -f {{flavor}} > {{output}}/{{flavor}}.md

# Generate all four flavors
all: setup (gen "latte") (gen "frappe") (gen "macchiato") (gen "mocha")
13 changes: 4 additions & 9 deletions examples/demo/output/frappe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
**flavor:** Frappé

### Colours

- **red:** #e78284 / rgb(231, 130, 132) / hsl(359, 68%, 71%)
- **components:** r: 231 / 0.91, g: 130 / 0.51, b: 132 / 0.52
- **alpha:** 153 / 0.60
- **10% lighter:** #f0aeb0 / rgb(240, 174, 176) / hsl(358, 69%, 81%)
- **10% lighter:** #f0aeb0 / rgb(240, 174, 176) / hsl(359, 68%, 81%)
- **10% darker:** #df5759 / rgb(223, 87, 89) / hsl(359, 68%, 61%)

- **30% mix with base:** #684c59 / rgb(104, 76, 89) / hsl(332, 16%, 35%)
- **30% mix with base:** #684b59 / rgb(104, 75, 89) / hsl(331, 16%, 35%)

- **50% opacity:** #e7838480 / rgba(231, 131, 132, 0.50) / hsla(359, 67%, 71%, 0.50)
- **50% opacity:** #e7828480 / rgba(231, 130, 132, 0.50) / hsla(359, 68%, 71%, 0.50)

### Conditionals

this is a dark theme

### Misc

unquote this: false
this is a dark theme
13 changes: 4 additions & 9 deletions examples/demo/output/latte.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
**flavor:** Latte

### Colours

- **red:** #d20f39 / rgb(210, 15, 57) / hsl(347, 87%, 44%)
- **components:** r: 210 / 0.82, g: 15 / 0.06, b: 57 / 0.22
- **alpha:** 153 / 0.60
- **10% lighter:** #f02652 / rgb(240, 38, 82) / hsl(347, 87%, 55%)
- **10% darker:** #a20c2c / rgb(162, 12, 44) / hsl(347, 86%, 34%)
- **10% darker:** #a20c2c / rgb(162, 12, 44) / hsl(347, 87%, 34%)

- **30% mix with base:** #e7adbd / rgb(231, 173, 189) / hsl(343, 55%, 79%)
- **30% mix with base:** #e6adbc / rgb(230, 173, 188) / hsl(344, 53%, 79%)

- **50% opacity:** #d30f3a80 / rgba(211, 15, 58, 0.50) / hsla(347, 87%, 44%, 0.50)
- **50% opacity:** #d20f3980 / rgba(210, 15, 57, 0.50) / hsla(347, 87%, 44%, 0.50)

### Conditionals

this is a light theme

### Misc

unquote this: true
this is a light theme
11 changes: 3 additions & 8 deletions examples/demo/output/macchiato.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
**flavor:** Macchiato

### Colours

- **red:** #ed8796 / rgb(237, 135, 150) / hsl(351, 74%, 73%)
- **components:** r: 237 / 0.93, g: 135 / 0.53, b: 150 / 0.59
- **alpha:** 153 / 0.60
- **10% lighter:** #f4b4be / rgb(244, 180, 190) / hsl(351, 75%, 83%)
- **10% lighter:** #f4b4be / rgb(244, 180, 190) / hsl(351, 74%, 83%)
- **10% darker:** #e65a6f / rgb(230, 90, 111) / hsl(351, 74%, 63%)

- **30% mix with base:** #624455 / rgb(98, 68, 85) / hsl(326, 18%, 33%)
- **30% mix with base:** #614455 / rgb(97, 68, 85) / hsl(325, 18%, 33%)

- **50% opacity:** #ed879680 / rgba(237, 135, 150, 0.50) / hsla(351, 74%, 73%, 0.50)

### Conditionals

this is a dark theme

### Misc

unquote this: false
this is a dark theme
11 changes: 3 additions & 8 deletions examples/demo/output/mocha.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
**flavor:** Mocha

### Colours

- **red:** #f38ba8 / rgb(243, 139, 168) / hsl(343, 81%, 75%)
- **components:** r: 243 / 0.95, g: 139 / 0.55, b: 168 / 0.66
- **alpha:** 153 / 0.60
- **10% lighter:** #f8bacc / rgb(248, 186, 204) / hsl(343, 82%, 85%)
- **10% lighter:** #f8bacc / rgb(248, 186, 204) / hsl(343, 81%, 85%)
- **10% darker:** #ee5c85 / rgb(238, 92, 133) / hsl(343, 81%, 65%)

- **30% mix with base:** #5e4054 / rgb(94, 64, 84) / hsl(320, 19%, 31%)
- **30% mix with base:** #5e3f53 / rgb(94, 63, 83) / hsl(321, 20%, 31%)

- **50% opacity:** #f38ba880 / rgba(243, 139, 168, 0.50) / hsla(343, 81%, 75%, 0.50)

### Conditionals

this is a dark theme

### Misc

unquote this: false
this is a dark theme
File renamed without changes.
41 changes: 0 additions & 41 deletions examples/frontmatter/input.hbs

This file was deleted.

39 changes: 39 additions & 0 deletions examples/frontmatter/input.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
whiskers:
version: "2.0.0"
dark_accent: mauve
light_accent: pink
---
{% set parent = if(cond=flavor.dark, t='darcula', f='default') -%}
{% set accent = if(cond=flavor.dark, t=dark_accent, f=light_accent) -%}

## Demo With Frontmatter

**flavor:** {{ flavor.name }}

This file also contains variables that have been defined in the frontmatter, as shown below:

### Frontmatter Variables

- **parent** is {{ parent }}
- **accent** is #{{ flavor.colors[accent].hex }}

### Colours

- **red:** #{{ red.hex }} / {{ css_rgb(color=red) }} / {{ css_hsl(color=red) }}
- **components:** r: {{ red.rgb.r }} / {{ red.rgb.r / 255 | trunc(places=2) }}, g: {{ red.rgb.g }} / {{ red.rgb.g / 255 | trunc(places=2) }}, b: {{ red.rgb.b }} / {{ red.rgb.b / 255 | trunc(places=2) }}
- **alpha:** {{ red.opacity }} / {{ red.opacity / 255 | trunc(places=2) }}
{% set lightred = red | add(lightness=10) -%}
- **10% lighter:** #{{ lightred.hex }} / {{ css_rgb(color=lightred) }} / {{ css_hsl(color=lightred) }}
{% set darkred = red | sub(lightness=10) -%}
- **10% darker:** #{{ darkred.hex }} / {{ css_rgb(color=darkred) }} / {{ css_hsl(color=darkred) }}

{% set palered = red | mix(color=base, amount=0.3) -%}
- **30% mix with base:** #{{ palered.hex }} / {{ css_rgb(color=palered) }} / {{ css_hsl(color=palered) }}

{% set fadered = red | mod(opacity=0.5) -%}
- **50% opacity:** #{{ fadered.hex }} / {{ css_rgba(color=fadered) }} / {{ css_hsla(color=fadered) }}

### Conditionals

this is a {{ if(cond=flavor.dark, t="dark", f="light") }} theme
2 changes: 1 addition & 1 deletion examples/frontmatter/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ clean:

# Generate a single flavor, e.g. "mocha"
gen flavor:
@{{whiskers_cmd}} input.hbs {{flavor}} -o {{output}}/{{flavor}}.md
@{{whiskers_cmd}} input.tera --flavor {{flavor}} > {{output}}/{{flavor}}.md

# Generate all four flavors
all: setup (gen "latte") (gen "frappe") (gen "macchiato") (gen "mocha")
14 changes: 5 additions & 9 deletions examples/frontmatter/output/frappe.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ This file also contains variables that have been defined in the frontmatter, as

- **red:** #e78284 / rgb(231, 130, 132) / hsl(359, 68%, 71%)
- **components:** r: 231 / 0.91, g: 130 / 0.51, b: 132 / 0.52
- **alpha:** 153 / 0.60
- **10% lighter:** #f0aeb0 / rgb(240, 174, 176) / hsl(358, 69%, 81%)
- **alpha:** 255 / 1.00
- **10% lighter:** #f0aeb0 / rgb(240, 174, 176) / hsl(359, 68%, 81%)
- **10% darker:** #df5759 / rgb(223, 87, 89) / hsl(359, 68%, 61%)

- **30% mix with base:** #684c59 / rgb(104, 76, 89) / hsl(332, 16%, 35%)
- **30% mix with base:** #684b59 / rgb(104, 75, 89) / hsl(331, 16%, 35%)

- **50% opacity:** #e7838480 / rgba(231, 131, 132, 0.50) / hsla(359, 67%, 71%, 0.50)
- **50% opacity:** #e7828480 / rgba(231, 130, 132, 0.50) / hsla(359, 68%, 71%, 0.50)

### Conditionals

this is a dark theme

### Misc

unquote this: false
this is a dark theme
14 changes: 5 additions & 9 deletions examples/frontmatter/output/latte.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ This file also contains variables that have been defined in the frontmatter, as

- **red:** #d20f39 / rgb(210, 15, 57) / hsl(347, 87%, 44%)
- **components:** r: 210 / 0.82, g: 15 / 0.06, b: 57 / 0.22
- **alpha:** 153 / 0.60
- **alpha:** 255 / 1.00
- **10% lighter:** #f02652 / rgb(240, 38, 82) / hsl(347, 87%, 55%)
- **10% darker:** #a20c2c / rgb(162, 12, 44) / hsl(347, 86%, 34%)
- **10% darker:** #a20c2c / rgb(162, 12, 44) / hsl(347, 87%, 34%)

- **30% mix with base:** #e7adbd / rgb(231, 173, 189) / hsl(343, 55%, 79%)
- **30% mix with base:** #e6adbc / rgb(230, 173, 188) / hsl(344, 53%, 79%)

- **50% opacity:** #d30f3a80 / rgba(211, 15, 58, 0.50) / hsla(347, 87%, 44%, 0.50)
- **50% opacity:** #d20f3980 / rgba(210, 15, 57, 0.50) / hsla(347, 87%, 44%, 0.50)

### Conditionals

this is a light theme

### Misc

unquote this: true
this is a light theme
Loading

0 comments on commit 696578a

Please sign in to comment.