1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
use ecow::EcoString;
use heck::ToKebabCase;
use serde::Serialize;
use crate::html::Html;
/// Details about a documentation page and its children.
#[derive(Debug, Serialize)]
pub struct PageModel {
pub route: EcoString,
pub title: EcoString,
pub description: EcoString,
pub part: Option<&'static str>,
pub outline: Vec<OutlineItem>,
pub body: BodyModel,
pub children: Vec<Self>,
}
impl PageModel {
pub fn with_route(self, route: &str) -> Self {
Self { route: route.into(), ..self }
}
pub fn with_part(self, part: &'static str) -> Self {
Self { part: Some(part), ..self }
}
}
/// An element in the "On This Page" outline.
#[derive(Debug, Clone, Serialize)]
pub struct OutlineItem {
pub id: EcoString,
pub name: EcoString,
pub children: Vec<Self>,
}
impl OutlineItem {
/// Create an outline item from a name with auto-generated id.
pub fn from_name(name: &str) -> Self {
Self {
id: name.to_kebab_case().into(),
name: name.into(),
children: vec![],
}
}
}
/// Details about the body of a documentation page.
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "kind", content = "content")]
pub enum BodyModel {
Html(Html),
Category(CategoryModel),
Func(FuncModel),
Group(GroupModel),
Type(TypeModel),
Symbols(SymbolsModel),
Packages(Html),
}
/// Details about a category.
#[derive(Debug, Serialize)]
pub struct CategoryModel {
pub name: EcoString,
pub details: Html,
pub items: Vec<CategoryItem>,
pub shorthands: Option<ShorthandsModel>,
}
/// Details about a category item.
#[derive(Debug, Serialize)]
pub struct CategoryItem {
pub name: EcoString,
pub route: EcoString,
pub oneliner: EcoString,
pub code: bool,
}
/// Details about a function.
#[derive(Debug, Serialize)]
pub struct FuncModel {
pub path: Vec<EcoString>,
pub name: EcoString,
pub title: &'static str,
pub keywords: &'static [&'static str],
pub oneliner: &'static str,
pub element: bool,
pub details: Html,
/// This example is only for nested function models. Others can have
/// their example directly in their details.
pub example: Option<Html>,
#[serde(rename = "self")]
pub self_: bool,
pub params: Vec<ParamModel>,
pub returns: Vec<&'static str>,
pub scope: Vec<FuncModel>,
}
/// Details about a function parameter.
#[derive(Debug, Serialize)]
pub struct ParamModel {
pub name: &'static str,
pub details: Html,
pub example: Option<Html>,
pub types: Vec<&'static str>,
pub strings: Vec<StrParam>,
pub default: Option<Html>,
pub positional: bool,
pub named: bool,
pub required: bool,
pub variadic: bool,
pub settable: bool,
}
/// A specific string that can be passed as an argument.
#[derive(Debug, Serialize)]
pub struct StrParam {
pub string: EcoString,
pub details: Html,
}
/// Details about a group of functions.
#[derive(Debug, Serialize)]
pub struct GroupModel {
pub name: EcoString,
pub title: EcoString,
pub details: Html,
pub functions: Vec<FuncModel>,
}
/// Details about a type.
#[derive(Debug, Serialize)]
pub struct TypeModel {
pub name: &'static str,
pub title: &'static str,
pub keywords: &'static [&'static str],
pub oneliner: &'static str,
pub details: Html,
pub constructor: Option<FuncModel>,
pub scope: Vec<FuncModel>,
}
/// A collection of symbols.
#[derive(Debug, Serialize)]
pub struct SymbolsModel {
pub name: &'static str,
pub details: Html,
pub list: Vec<SymbolModel>,
}
/// Details about a symbol.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SymbolModel {
pub name: EcoString,
pub codepoint: u32,
pub accent: bool,
pub unicode_name: Option<EcoString>,
pub alternates: Vec<EcoString>,
pub markup_shorthand: Option<&'static str>,
pub math_shorthand: Option<&'static str>,
}
/// Shorthands listed on a category page.
#[derive(Debug, Serialize)]
pub struct ShorthandsModel {
pub markup: Vec<SymbolModel>,
pub math: Vec<SymbolModel>,
}
|