mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-03 13:44:14 +01:00
feat(docgen): initial implementation of html doc generator
Implement a complete Rust library and CLI tool for generating self-contained HTML documentation from schemars::Schema (JSON Schema) objects. Core Features: - Library API with `generate_html()` function and `Options` struct - CLI binary accepting JSON Schema input files with optional title override - Tera-based HTML templating with base template and reusable macros - Markdown rendering for schema descriptions via pulldown-cmark - Dark/light theme support following system preferences - Searchable properties with instant search functionality - Collapsible nested structures for complex schemas - Responsive design for mobile, tablet, and desktop Library Components: - `generator.rs`: Main HTML generation logic with Tera template engine - `prepare.rs`: Schema preprocessing for template rendering (1667 lines) - `lib.rs`: Public API with SchemaExt trait for typed schema accessors - `main.rs`: CLI interface using clap for argument parsing Template System: - `base.html`: Main HTML structure with header, sidebar, and content areas - `macros.html`: Reusable Tera macros for rendering schema components - `style.css`: Complete CSS with CSS variables for theming (955 lines)
This commit is contained in:
commit
c85edf242f
13 files changed
+5997
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
use clap::Parser;
|
||||
use schemars_docgen::Options;
|
||||
use schemars_docgen::generate_html;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "schemars-docgen")]
|
||||
#[command(about = "Generate HTML documentation from JSON Schema")]
|
||||
struct Cli {
|
||||
/// Input JSON Schema file
|
||||
input: PathBuf,
|
||||
|
||||
/// Output HTML file
|
||||
#[arg(short, long)]
|
||||
output: Option<PathBuf>,
|
||||
|
||||
/// Schema title (overrides schema title from the schema)
|
||||
#[arg(short, long)]
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let schema_json = std::fs::read_to_string(&cli.input)?;
|
||||
let schema: schemars::Schema = serde_json::from_str(&schema_json)?;
|
||||
|
||||
let options = Options {
|
||||
title_override: cli.title,
|
||||
};
|
||||
|
||||
let html = generate_html(&schema, &options)?;
|
||||
|
||||
let output_path = cli.output.unwrap_or_else(|| {
|
||||
let mut path = cli.input.clone();
|
||||
path.set_extension("html");
|
||||
path
|
||||
});
|
||||
|
||||
std::fs::write(&output_path, html)?;
|
||||
println!("Generated documentation: {}", output_path.display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user