-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render token type names using Token! macro in documentation
- Loading branch information
Showing
5 changed files
with
1,062 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::workspace_path; | ||
use anyhow::Result; | ||
use indoc::{formatdoc, indoc}; | ||
use std::fs; | ||
use syn_codegen::Definitions; | ||
|
||
pub fn generate(defs: &Definitions) -> Result<()> { | ||
let mut styles = String::new(); | ||
for ty in defs.tokens.keys() { | ||
styles += &format!("a.struct[title=\"struct syn::token::{ty}\"],\n"); | ||
} | ||
styles.truncate(styles.len() - 2); | ||
styles += indoc! {" | ||
{ | ||
\tdisplay: inline-block; | ||
\tcolor: transparent; | ||
\twhite-space: nowrap; | ||
} | ||
"}; | ||
styles.push('\n'); | ||
for ty in defs.tokens.keys() { | ||
styles += &format!("a.struct[title=\"struct syn::token::{ty}\"]::before,\n"); | ||
} | ||
styles.truncate(styles.len() - 2); | ||
styles += indoc! {" | ||
{ | ||
\tdisplay: inline-block; | ||
\tcolor: var(--type-link-color); | ||
\twidth: 0; | ||
} | ||
"}; | ||
for (ty, repr) in &defs.tokens { | ||
let padding = ".".repeat((repr.len() + 8).saturating_sub(ty.len())); | ||
styles += &formatdoc! {" | ||
a.struct[title=\"struct syn::token::{ty}\"]::before {{ | ||
\tcontent: \"Token![{repr}]\"; | ||
}} | ||
a.struct[title=\"struct syn::token::{ty}\"]::after {{ | ||
\tcontent: \"{padding}\"; | ||
}} | ||
"}; | ||
} | ||
|
||
let css_path = workspace_path::get("src/gen/token.css"); | ||
fs::write(css_path, styles)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.