Skip to content

Commit a348995

Browse files
committed
Switch to mise, update precious config, and fix various linting issues
1 parent 4547cdf commit a348995

File tree

12 files changed

+165
-176
lines changed

12 files changed

+165
-176
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
2-
members = [ "generator", "integration", "macros" ]
3-
exclude = [ "test-project" ]
2+
members = ["generator", "integration", "macros"]
3+
exclude = ["test-project"]
44
resolver = "2"
55

66
[workspace.metadata.release]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
This repo contains a [tool to generate Rust code from Tailwind CSS](generator)
2-
and [a set of macros for working with that generated code](macros).
1+
This repo contains a [tool to generate Rust code from Tailwind CSS](generator) and
2+
[a set of macros for working with that generated code](macros).
33

44
See the docs for those crates for more details.
55

_typos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[default.extend-words]
2+
# These are mod names for these groups of CSS classes.
3+
siz = "siz"
4+
typ = "typ"

dev/bin/install-dev-tools.sh

Lines changed: 0 additions & 50 deletions
This file was deleted.

generator/Changes.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,40 @@
88

99
## v0.3.0 - 2023-02-18
1010

11-
- The generated code now groups CSS classes into modules instead of
12-
structs. This prevents stack overflows that happened when the structs were
13-
put on the stack. Thanks to @mdochdev for identifying the issue and
14-
suggesting this fix. GH #4.
11+
- The generated code now groups CSS classes into modules instead of structs. This prevents stack
12+
overflows that happened when the structs were put on the stack. Thanks to @mdochdev for
13+
identifying the issue and suggesting this fix. GH #4.
1514

1615
- Updated the class categories for the latest TailwindCSS version, 3.2.7.
1716

1817
## v0.2.0 - 2023-02-05
1918

2019
- Updated the class categories for the latest TailwindCSS version, 3.2.4.
2120

22-
- Updated the docs to make it clearer how to configure `tailwind.config.js`
23-
depending on whether or not you're using the macros, what templating system
24-
you're using, etc.
21+
- Updated the docs to make it clearer how to configure `tailwind.config.js` depending on whether or
22+
not you're using the macros, what templating system you're using, etc.
2523

2624
## v0.1.4 - 2022-04-24
2725

28-
- Added a new `--tailwindcss` argument. This can be used to provide the path
29-
to the `tailwindcss` executable.
26+
- Added a new `--tailwindcss` argument. This can be used to provide the path to the `tailwindcss`
27+
executable.
3028

3129
## v0.1.3 - 2022-02-17
3230

3331
- Documentation fixes.
3432

3533
## v0.1.2 - 2022-02-14
3634

37-
- Fixed the handling of CSS class names with periods and forward slashes. The
38-
generated Rust code included an escape for these names, so they'd end up as
39-
things like `w-0\.5` or `w-3\/5` in your HTML, which is wrong. They should
40-
not have a backslash escape in the generated HTML. Note that this also means
41-
that the tailwind extractor code in the generator's `README.md` was wrong as
42-
well. It has also been fixed.
35+
- Fixed the handling of CSS class names with periods and forward slashes. The generated Rust code
36+
included an escape for these names, so they'd end up as things like `w-0\.5` or `w-3\/5` in your
37+
HTML, which is wrong. They should not have a backslash escape in the generated HTML. Note that
38+
this also means that the tailwind extractor code in the generator's `README.md` was wrong as well.
39+
It has also been fixed.
4340

4441
## v0.1.1 - 2022-02-08
4542

46-
- Fixed the repository metadata for the crate. Thanks to @overlisted on the
47-
Dioxus Discord for pointing this out.
43+
- Fixed the repository metadata for the crate. Thanks to @overlisted on the Dioxus Discord for
44+
pointing this out.
4845

4946
## v0.1.0 - 2022-02-08
5047

generator/README.md

Lines changed: 50 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
The `tailwindcss-to-rust` CLI tool generates Rust code that allows you to
2-
refer to Tailwind classes from your Rust code. This means that any attempt to
3-
use a nonexistent class will lead to a compile-time error, and you can use
4-
code completion to list available classes.
1+
The `tailwindcss-to-rust` CLI tool generates Rust code that allows you to refer to Tailwind classes
2+
from your Rust code. This means that any attempt to use a nonexistent class will lead to a
3+
compile-time error, and you can use code completion to list available classes.
54

65
**This tool has been tested with version 3.2.x of Tailwind.**
76

8-
The generated code allows you to use Tailwind CSS classes in your Rust
9-
frontend code with compile-time checking of names and code completion for
10-
class names. These classes are grouped together based on the heading in the
11-
Tailwind docs. It also generates code for the full list of Tailwind modifiers
12-
like `lg`, `hover`, etc.
7+
The generated code allows you to use Tailwind CSS classes in your Rust frontend code with
8+
compile-time checking of names and code completion for class names. These classes are grouped
9+
together based on the heading in the Tailwind docs. It also generates code for the full list of
10+
Tailwind modifiers like `lg`, `hover`, etc.
1311

14-
[**Check out the tailwindcss-to-rust-macros
15-
crate**](https://crates.io/crates/tailwindcss-to-rust-macros) for the most
16-
ergonomic way to use the code generated by this tool.
12+
[**Check out the tailwindcss-to-rust-macros crate**](https://crates.io/crates/tailwindcss-to-rust-macros)
13+
for the most ergonomic way to use the code generated by this tool.
1714

1815
So instead of this:
1916

@@ -27,8 +24,8 @@ You can write this:
2724
let class = C![C::spc::pt_4 C::pb_2 C::typ::text_white];
2825
```
2926

30-
Note that the typo in the first example, **"text-whit"** (missing the "e")
31-
would become a compile-time error if you wrote `C::typ::text_whit`.
27+
Note that the typo in the first example, **"text-whit"** (missing the "e") would become a
28+
compile-time error if you wrote `C::typ::text_whit`.
3229

3330
Here's a quick start recipe:
3431

@@ -38,23 +35,20 @@ Here's a quick start recipe:
3835
cargo install tailwindcss-to-rust
3936
```
4037

41-
2. [Install the `tailwindcss` CLI
42-
tool](https://tailwindcss.com/docs/installation). You can install it with
43-
`npm` or `npx`, or you can [download a standalone binary from the
44-
tailwindcss repo](https://github.com/tailwindlabs/tailwindcss/releases).
38+
2. [Install the `tailwindcss` CLI tool](https://tailwindcss.com/docs/installation). You can install
39+
it with `npm` or `npx`, or you can
40+
[download a standalone binary from the tailwindcss repo](https://github.com/tailwindlabs/tailwindcss/releases).
4541

4642
3. Create a `tailwind.config.js` file with the tool by running:
4743

4844
```sh
4945
tailwindcss init
5046
```
5147

52-
4. Edit this file however you like to add plugins or customize the generated
53-
CSS.
48+
4. Edit this file however you like to add plugins or customize the generated CSS.
5449

55-
5. Create a CSS input file for Tailwind. For the purposes of this example we
56-
will assume that it's located at `css/tailwind.css`. The standard file
57-
looks like this:
50+
5. Create a CSS input file for Tailwind. For the purposes of this example we will assume that it's
51+
located at `css/tailwind.css`. The standard file looks like this:
5852

5953
```css
6054
@tailwind base;
@@ -72,12 +66,10 @@ Here's a quick start recipe:
7266
--rustfmt
7367
```
7468

75-
**The `tailwindcss` executable must be in your `PATH` when you run
76-
`tailwindcss-to-rust` or you must provide the path to the executable in the
77-
`--tailwindcss` argument.**
69+
**The `tailwindcss` executable must be in your `PATH` when you run `tailwindcss-to-rust` or you
70+
must provide the path to the executable in the `--tailwindcss` argument.**
7871

79-
7. Edit your `tailwind.config.js` file to look in your Rust files for Tailwind
80-
class names:
72+
7. Edit your `tailwind.config.js` file to look in your Rust files for Tailwind class names:
8173

8274
```js
8375
/** @type {import('tailwindcss').Config} */
@@ -91,10 +83,7 @@ Here's a quick start recipe:
9183
if (rs.startsWith("two_")) {
9284
rs = rs.replace("two_", "2");
9385
}
94-
return rs
95-
.replaceAll("_of_", "/")
96-
.replaceAll("_p_", ".")
97-
.replaceAll("_", "-");
86+
return rs.replaceAll("_of_", "/").replaceAll("_p_", ".").replaceAll("_", "-");
9887
};
9988

10089
let one_class_re = "\\bC::[a-z0-9_]+::([a-z0-9_]+)\\b";
@@ -129,21 +118,15 @@ Here's a quick start recipe:
129118
};
130119
```
131120

132-
**Note that you may need to customize the regexes in the
133-
`extract` function to match your templating system!** The regexes in this
134-
example will match the syntax you'd use with the
135-
[tailwindcss-to-rust-macros](https://crates.io/crates/tailwindcss-to-rust-macros)
136-
crate.
121+
**Note that you may need to customize the regexes in the `extract` function to match your
122+
templating system!** The regexes in this example will match the syntax you'd use with the
123+
[tailwindcss-to-rust-macros](https://crates.io/crates/tailwindcss-to-rust-macros) crate.
137124

138-
For example, if you're using [askama](https://crates.io/crates/askama)
139-
without the macros then you will need to match something like this:
125+
For example, if you're using [askama](https://crates.io/crates/askama) without the macros then
126+
you will need to match something like this:
140127

141128
```html
142-
<div
143-
class="{{ M::hover }}:{{ C::bg::bg_rose_500 }} {{ C::bg::bg_rose_800 }}"
144-
>
145-
...
146-
</div>
129+
<div class="{{ M::hover }}:{{ C::bg::bg_rose_500 }} {{ C::bg::bg_rose_800 }}">...</div>
147130
```
148131

149132
The regexes for that would look something like this:
@@ -169,9 +152,9 @@ Here's a quick start recipe:
169152
<link data-trunk rel="css" href="/css/tailwind_compiled.css" />
170153
```
171154

172-
In this example, I'm using [Trunk](https://trunkrs.dev/), which is a great
173-
alternative to webpack for projects that want to use Rust -> WASM without any
174-
node.js tooling. My `Trunk.toml` looks like this:
155+
In this example, I'm using [Trunk](https://trunkrs.dev/), which is a great alternative to webpack
156+
for projects that want to use Rust -> WASM without any node.js tooling. My `Trunk.toml` looks like
157+
this:
175158
176159
```toml
177160
[build]
@@ -192,26 +175,23 @@ When I run `trunk` I have to make sure to ignore that generated file:
192175
trunk --ignore ./css/tailwind_compiled.css ...
193176
```
194177

195-
The generated names consist of all the class names present in the CSS file,
196-
except names that start with a dash (`-`), names that contain pseudo-elements,
197-
like `.placeholder-opacity-100::-moz-placeholder`, and names that contain
198-
modifiers like `lg` or `hover`. Names are transformed into Rust identifiers
199-
using the following algorithm:
178+
The generated names consist of all the class names present in the CSS file, except names that start
179+
with a dash (`-`), names that contain pseudo-elements, like
180+
`.placeholder-opacity-100::-moz-placeholder`, and names that contain modifiers like `lg` or `hover`.
181+
Names are transformed into Rust identifiers using the following algorithm:
200182

201183
- All backslash escapes are removed entirely, for example in `.inset-0\.5`.
202184
- All dashes (`-`) become underscores (`_`).
203185
- All periods (`.`) become `_p_`, so `.inset-2\.5` becomes `inset_2_p_5`.
204-
- All forward slashes (`/`) become `_of_`, so `.inset-2\/4` becomes
205-
`inset_2_of_4`.
206-
- If a name _starts_ with a `2`, as in `2xl`, it becomes `two_`, so the `2xl`
207-
modifier becomes `two_xl`.
186+
- All forward slashes (`/`) become `_of_`, so `.inset-2\/4` becomes `inset_2_of_4`.
187+
- If a name _starts_ with a `2`, as in `2xl`, it becomes `two_`, so the `2xl` modifier becomes
188+
`two_xl`.
208189
- The name `static` becomes `static_`.
209190

210-
The generated code provides two modules containing all of the relevant
211-
strings.
191+
The generated code provides two modules containing all of the relevant strings.
212192

213-
The `C` module contains a number of submodules, one for each group of classes
214-
as documented in the TailwindCSS docs. The groups are as follows:
193+
The `C` module contains a number of submodules, one for each group of classes as documented in the
194+
TailwindCSS docs. The groups are as follows:
215195

216196
```rust,ignore
217197
pub(crate) mod C {
@@ -262,20 +242,19 @@ pub(crate) mod C {
262242
}
263243
```
264244

265-
In your code, you can refer to classes with `C::typ::text_lg` or
266-
`C::lay::flex`. If you have any custom classes, these will end in an "unknown"
267-
group available from `C::unk`. Adding a way to put these custom classes in
268-
other groups is a todo item.
245+
In your code, you can refer to classes with `C::typ::text_lg` or `C::lay::flex`. If you have any
246+
custom classes, these will end in an "unknown" group available from `C::unk`. Adding a way to put
247+
these custom classes in other groups is a todo item.
269248

270-
The modifiers have their own module, `M`, which contains one field per
271-
modifier, so it's used as `M::lg` or `M::hover`. A few modifiers which are
272-
parameterizable are not included, like `aria-*`, `data-*`, etc.
249+
The modifiers have their own module, `M`, which contains one field per modifier, so it's used as
250+
`M::lg` or `M::hover`. A few modifiers which are parameterizable are not included, like `aria-*`,
251+
`data-*`, etc.
273252

274-
The best way to understand the generated modules is to open the generated code
275-
file in your editor and look at it.
253+
The best way to understand the generated modules is to open the generated code file in your editor
254+
and look at it.
276255

277-
Then you can import these consts in your code and use them to refer to
278-
Tailwind CSS class names with compile time checking:
256+
Then you can import these consts in your code and use them to refer to Tailwind CSS class names with
257+
compile time checking:
279258

280259
```rust,ignore
281260
element.set_class(C::lay::aspect_auto);

git/hooks/pre-commit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/bash
22

3+
declare -i status
34
status=0
45

56
PRECIOUS=$(which precious)
67
if [[ -z $PRECIOUS ]]; then
78
PRECIOUS=./bin/precious
89
fi
910

10-
"$PRECIOUS" lint -s
11-
if (( $? != 0 )); then
11+
if ! "$PRECIOUS" lint -s; then
1212
status+=1
1313
fi
1414

macros/Changes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
## v0.1.3 - 2023-02-18
22

3-
- Updated the docs to reflect the changes in version 0.3.0 of the
4-
tailwindcss-to-rust code generator.
3+
- Updated the docs to reflect the changes in version 0.3.0 of the tailwindcss-to-rust code
4+
generator.
55

66
## v0.1.2 - 2022-02-17
77

88
- Documentation and example fixes.
99

1010
## v0.1.1 - 2022-02-08
1111

12-
- Fixed the repository metadata for this crate. Thanks to @overlisted on the
13-
Dioxus Discord for pointing this out.
12+
- Fixed the repository metadata for this crate. Thanks to @overlisted on the Dioxus Discord for
13+
pointing this out.
1414

1515
## v0.1.0 - 2022-02-08
1616

macros/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
Helper macros for using the code generated by
22
[tailwindcss-to-rust](https://crates.io/crates/tailwindcss-to-rust).
33

4-
The generated code provides a number of static structs where each field is
5-
a class name or modifier (like "lg" or "hover"). In typical use, you need
6-
to combine multiple names and modifiers into a single string to be set as
7-
an element's `class` attribute. This crate provides two macros to make
4+
The generated code provides a number of static structs where each field is a class name or modifier
5+
(like "lg" or "hover"). In typical use, you need to combine multiple names and modifiers into a
6+
single string to be set as an element's `class` attribute. This crate provides two macros to make
87
using this a bit more ergonomic.
98

109
A [Dioxus](https://dioxuslabs.com/) example:

mise.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tools]
2+
node = "24.14.0"
3+
"npm:prettier" = "3.8.1"
4+
shellcheck = "0.11.0"
5+
shfmt = "3.13.0"
6+
taplo = "0.10.0"
7+
typos = "1.44.0"
8+
"github:houseabsolute/omegasort" = "0.1.3"
9+
"github:houseabsolute/precious" = "0.10.2"

0 commit comments

Comments
 (0)