diff --git a/darm_test/scripts/collect-maud-classes.rs b/darm_test/scripts/collect-maud-classes.rs new file mode 100755 index 0000000..a84b080 --- /dev/null +++ b/darm_test/scripts/collect-maud-classes.rs @@ -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[\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(()) +} diff --git a/darm_test/src/ui/mod.rs b/darm_test/src/ui/mod.rs index b7dd90e..975fe6c 100644 --- a/darm_test/src/ui/mod.rs +++ b/darm_test/src/ui/mod.rs @@ -65,16 +65,16 @@ impl UiController { #[tracing::instrument] async fn index(State(_): State) -> 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" } diff --git a/darm_test/style/extracted-classes.txt b/darm_test/style/extracted-classes.txt new file mode 100644 index 0000000..b2f9999 --- /dev/null +++ b/darm_test/style/extracted-classes.txt @@ -0,0 +1,3 @@ +class="into_response" +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" +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" diff --git a/darm_test/style/uno.css b/darm_test/style/uno.css index 5c09b25..762b42b 100644 --- a/darm_test/style/uno.css +++ b/darm_test/style/uno.css @@ -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%;} diff --git a/darm_test/uno.config.ts b/darm_test/uno.config.ts index 75e1f55..418dfd6 100644 --- a/darm_test/uno.config.ts +++ b/darm_test/uno.config.ts @@ -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({}), diff --git a/flake.nix b/flake.nix index 298438e..a79ec3d 100644 --- a/flake.nix +++ b/flake.nix @@ -166,6 +166,7 @@ wasm-bindgen-cli_0_2_100 cargo-outdated cargo-release + rust-script calc # jre8 # needed for xmlls dart-sass