Add manual maud class collector script

This commit is contained in:
Tristan D. 2025-03-24 15:41:21 +01:00
parent 9c75092d12
commit 011c8c1a41
Signed by: tristan
SSH key fingerprint: SHA256:9oFM1J63hYWJjCnLG6C0fxBS15rwNcWwdQNMOHYKJ/4
6 changed files with 84 additions and 8 deletions

View file

@ -0,0 +1,71 @@
#!/usr/bin/env rust-script
//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest. Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! regex = "1"
//! walkdir = "2"
//! ```
use std::{
fs::{self, File},
io::{self, Write},
path::Path,
};
use regex::Regex;
use walkdir::WalkDir;
fn main() -> io::Result<()> {
// Define the regex pattern to extract classes
let re = Regex::new(r"(?: \.(?P<tag>[\w-]+))").expect("Invalid regex pattern");
// Define the source directory to scan
let source_dir = "./src"; // Change this to your source directory
// Define the output file
let output_file = "./style/extracted-classes.txt";
let mut file = File::create(output_file)?;
println!("Scanning directory: {}", source_dir);
// Walk through the directory structure
for entry in WalkDir::new(source_dir)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().is_file() && e.path().extension().map_or(false, |ext| ext == "rs")
})
{
let path = entry.path();
println!("Processing file: {}", path.display());
let content = fs::read_to_string(path)?;
let mut classes = Vec::new();
// Extract all classes using the regex
for cap in re.captures_iter(&content) {
if let Some(tag_match) = cap.name("tag") {
let class = tag_match.as_str().to_string();
classes.push(class.clone());
}
}
// If classes were found, write them to the output file
if !classes.is_empty() {
writeln!(
file,
"class=\"{}\" <!-- {} -->",
classes.join(" "),
path.display()
)?;
}
}
println!(
"Class extraction complete. Output written to {}",
output_file
);
Ok(())
}

View file

@ -65,16 +65,16 @@ impl UiController {
#[tracing::instrument]
async fn index(State(_): State<AppState>) -> impl IntoResponse {
main_page(maud! {
div class="container p-4 mx-auto" {
h1 class="mb-4 text-2xl font-bold" {
div .container .p-4 .mx-auto {
h1 .m-4 .text-2xl .font-bold {
"LLM Chat App"
}
div class="p-6 bg-white rounded-lg shadow-md" {
div #chat class="mb-4" {
div .p-6 .bg-white .rounded-lg .shadow-md {
div #chat .m-4 {
// Chat messages will appear here
}
form id="chat-form" {
textarea #user-input class="p-2 m-2 w-full rounded-lg border" data-bind-msginput placeholder="Type your message..." {}
textarea #user-input .p-2 .m-2 .w-full .rounded-lg .border data-bind-msginput placeholder="Type your message..." {}
button #send-btn class="btn" type="button" data-on-click="@get('/msg')" {
"Send"
}

View file

@ -0,0 +1,3 @@
class="into_response" <!-- ./src/assets.rs -->
class="selector merge_mode into selector merge_mode into container p-4 mx-auto m-4 text-2xl font-bold p-6 bg-white rounded-lg shadow-md m-4 p-2 m-2 w-full rounded-lg border render" <!-- ./src/ui/mod.rs -->
class="into_response into_response with_default_directive from_env_lossy pretty with_env_filter init body size_hint exact map merge merge fallback_service method_not_allowed_fallback layer layer layer layer layer with_state" <!-- ./src/main.rs -->

View file

@ -122,7 +122,6 @@ line-height: inherit; }
.m-8{margin:2rem;}
.mx-auto{margin-left:auto;margin-right:auto;}
.mb-2{margin-bottom:0.5rem;}
.mb-4{margin-bottom:1rem;}
.inline-block{display:inline-block;}
.h1{height:0.25rem;}
.w-full{width:100%;}

View file

@ -3,7 +3,7 @@ import {
defineConfig,
presetAttributify,
presetIcons,
presetWind,
presetWind3,
presetTagify,
presetTypography,
transformerDirectives,
@ -23,6 +23,7 @@ export default defineConfig({
"src/**/*.rs",
"*/src/**/*.rs",
"*/style/*.scss",
"**/extracted-classes.txt",
],
},
cli: {
@ -32,12 +33,13 @@ export default defineConfig({
"src/**/*.rs",
"*/src/**/*.rs",
"*/style/*.scss",
"**/extracted-classes.txt",
],
outFile: "./style/uno.css",
},
},
presets: [
presetWind(),
presetWind3({}),
presetAttributify({}),
presetTagify({}),
presetIcons({}),

View file

@ -166,6 +166,7 @@
wasm-bindgen-cli_0_2_100
cargo-outdated
cargo-release
rust-script
calc
# jre8 # needed for xmlls
dart-sass