pyo3_stub_gen/docgen/
config.rs1use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct DocGenConfig {
9 #[serde(rename = "output-dir", default = "default_output_dir")]
11 pub output_dir: PathBuf,
12
13 #[serde(rename = "json-output", default = "default_json_output")]
15 pub json_output: String,
16
17 #[serde(rename = "separate-pages", default = "default_separate_pages")]
19 pub separate_pages: bool,
20
21 #[serde(rename = "intro-message", default)]
23 pub intro_message: Option<String>,
24
25 #[serde(rename = "index-title", default)]
27 pub index_title: Option<String>,
28
29 #[serde(rename = "contents-table", default)]
31 pub contents_table: bool,
32}
33
34impl Default for DocGenConfig {
35 fn default() -> Self {
36 Self {
37 output_dir: default_output_dir(),
38 json_output: default_json_output(),
39 separate_pages: default_separate_pages(),
40 intro_message: None,
41 index_title: None,
42 contents_table: false,
43 }
44 }
45}
46
47fn default_output_dir() -> PathBuf {
48 PathBuf::from("docs/api")
49}
50
51fn default_json_output() -> String {
52 "api_reference.json".to_string()
53}
54
55fn default_separate_pages() -> bool {
56 true
57}
58
59impl DocGenConfig {
60 pub fn to_relative_posix_path(&self, base_dir: &std::path::Path) -> String {
62 let relative_path = if self.output_dir.is_absolute() {
63 self.output_dir
64 .strip_prefix(base_dir)
65 .unwrap_or(&self.output_dir)
66 } else {
67 &self.output_dir
68 };
69
70 relative_path
72 .components()
73 .filter_map(|c| match c {
74 std::path::Component::Normal(s) => Some(s.to_string_lossy().into_owned()),
75 _ => None,
76 })
77 .collect::<Vec<_>>()
78 .join("/")
79 }
80}