Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Token![_] spacing in docs #1766

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions codegen/src/css.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::workspace_path;
use anyhow::Result;
use indoc::{formatdoc, indoc};
use std::cmp::Ordering;
use std::fs;
use syn_codegen::Definitions;

Expand Down Expand Up @@ -30,17 +31,36 @@ pub fn generate(defs: &Definitions) -> Result<()> {
}
"};
for (ty, repr) in &defs.tokens {
let padding = ".".repeat((repr.len() + 8).saturating_sub(ty.len()));
styles += &formatdoc! {"
let macro_len = "Token![]".len() + repr.len();
let ty_len = ty.len();
styles.push('\n');
styles += &match Ord::cmp(&macro_len, &ty_len) {
Ordering::Less => {
formatdoc! {"
a.struct[title=\"struct syn::token::{ty}\"] {{
\tfont-size: calc(100% * {macro_len} / {ty_len});
}}

a.struct[title=\"struct syn::token::{ty}\"]::before {{
\tcontent: \"Token![{repr}]\";
}}
a.struct[title=\"struct syn::token::{ty}\"]::before {{
\tcontent: \"Token![{repr}]\";
\tfont-size: calc(100% * {ty_len} / {macro_len});
}}
"}
}
Ordering::Equal => unreachable!(),
Ordering::Greater => {
let padding = ".".repeat(macro_len.saturating_sub(ty.len()));
formatdoc! {"
a.struct[title=\"struct syn::token::{ty}\"]::before {{
\tcontent: \"Token![{repr}]\";
}}

a.struct[title=\"struct syn::token::{ty}\"]::after {{
\tcontent: \"{padding}\";
}}
"};
a.struct[title=\"struct syn::token::{ty}\"]::after {{
\tcontent: \"{padding}\";
}}
"}
}
};
}

let css_path = workspace_path::get("src/gen/token.css");
Expand Down
9 changes: 5 additions & 4 deletions src/gen/token.css

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

Loading