valkyrie_docgen/examples/
mod.rs1use crate::items::*;
2use std::rc::Rc;
3use yew::prelude::*;
4
5pub struct Full;
6
7pub struct Sidebar {}
8
9impl Renderable for Sidebar {
10 fn render(&self) -> Html {
11 html! {
12 <aside class="sidebar">
13 <div class="sidebar-menu">{"☰"}</div>
14 <a href="#">
15 <div class="logo-container rust-logo">
16 <img src="https://docs.rs/rust-logo-20210119-1.51.0-nightly-c5a96fb79.png" alt="logo"/>
17 </div>
18 </a>
19 <p class="location">{"Struct Captures"}</p>
20 <div class="sidebar-elems">
21 <div class="block items"><a class="sidebar-title" href="#">{"Methods"}</a>
22 <div class="sidebar-links">
23 <a href="#">{"expand"}</a>
24 <a href="#">{"get"}</a>
25 <a href="#">{"iter"}</a>
26 </div>
27 <a class="sidebar-title" href="#">{"Trait Implementations"}</a>
28 <div class="sidebar-links">
29 <a href="#">{"Debug"}</a>
30 <a href="#">{"Index<&'str>"}</a>
31 <a href="#">{"Index<usize>"}</a>
32 </div>
33 <a class="sidebar-title" href="#">{"Auto Trait Implementations"}</a>
34 <div class="sidebar-links">
35 <a href="#">{"RefUnwindSafe"}</a>
36 <a href="#">{"Send"}</a>
37 <a href="#">{"Sync"}</a>
38 <a href="#">{"Unpin"}</a>
39 <a href="#">{"UnwindSafe"}</a>
40 </div>
41 <a class="sidebar-title" href="#">{"Blanket Implementations"}</a>
42 <div class="sidebar-links">
43 <a href="#">{"Any"}</a>
44 <a href="#">{"Borrow<T>"}</a>
45 </div>
46 </div>
47 <p class="location"><a href="#">{"regex"}</a>{"::"}<a href="#">{"bytes"}</a></p>
48 <div class="block struct">
49 <h3>{"Structs"}</h3>
50 <ul>
51 <li><a href="#" title="By-reference adaptor for a `Replacer`" class="struct">{"ReplacerRef"}</a></li>
52 <li><a href="#" title="A set of matches returned by a regex set." class="struct">{"SetMatches"}</a>
53 </li>
54 <li><a href="#" title="An owned iterator over the set of matches from a regex set."
55 class="struct">{"SetMatchesIntoIter"}</a></li>
56 <li><a href="#" title="A borrowed iterator over the set of matches from a regex set."
57 class="struct">{"SetMatchesIter"}</a></li>
58 <li><a href="#" title="Yields all substrings delimited by a regular expression match."
59 class="struct">{"Split"}</a>
60 </li>
61 <li><a href="#" title="Yields at most `N` substrings delimited by a regular expression match."
62 class="struct">{"SplitN"}</a></li>
63 <li><a href="#"
64 title="An iterator that yields all capturing matches in the order in which they appear in the regex."
65 class="struct">{"SubCaptureMatches"}</a></li>
66 </ul>
67 </div>
68 <div class="block trait">
69 <h3>{"Traits"}</h3>
70 <ul>
71 <li><a href="#" title="Replacer describes types that can be used to replace matches in a byte string."
72 class="trait">{"Replacer"}</a></li>
73 </ul>
74 </div>
75 </div>
76 </aside>
77 }
78 }
79}
80
81pub fn get_toc_title() -> TableOfContentsArray {
82 TableOfContentsArray(vec![
83 TableOfContentsItem(
84 html! {<a href="#heading-2" title="线程">{"线程"}</a>},
85 vec![html! {
86 <a href="#heading-3" title="并发 (concurrency) 和并行(Parallelism)">
87 {"并发 (concurrency) 和并行(Parallelism)"}
88 </a>
89 }],
90 ),
91 TableOfContentsItem(html! {<a href="#heading-0" title="上下文切换">{"上下文切换"}</a>}, vec![]),
92 TableOfContentsItem(html! {<a href="#heading-1" title="进程">{"进程"}</a>}, vec![]),
93 TableOfContentsItem(
94 html! {<a href="#heading-2" title="线程">{"线程"}</a>},
95 vec![
96 html! {
97 <a href="#heading-3" title="并发 (concurrency) 和并行(Parallelism)">
98 {"并发 (concurrency) 和并行(Parallelism)"}
99 </a>
100 },
101 html! {
102 <a href="#heading-5" title="非阻塞 IO 和事件驱动">
103 {"非阻塞 IO 和事件驱动"}
104 </a>
105 },
106 ],
107 ),
108 TableOfContentsItem(
109 html! {<a href="#heading-6" title="协程 (coroutine)">{"协程 (coroutine)"}</a>},
110 vec![
111 html! {<a href="#heading-7">{"Generator: 半协程"}</a>},
112 html! {<a href="#heading-8">{"Async/Await: 协程 + 异步 = 支持异步任务调度的协程"}</a>},
113 html! {<a href="#heading-9">{"React Fiber: 框架层控制的支持同步任务和优先级的协程"}</a>},
114 ],
115 ),
116 ])
117}
118
119pub fn example(input: &str) -> Html {
120 let class = Class {
121 name: String::from(input),
122 path: "AA".to_string(),
123 generic: vec![Typing::from("T"), Typing::from("U"), Typing::from("char")],
124 traits: vec![],
125 };
126 let class_traits =
127 RcList::from(
128 &["Debug", "Display", "Debug", "Display", "Debug", "Display", "Debug", "Display", "Debug", "Display"] as &[_]
129 );
130 let e = Extends {
131 id: 1,
132 generic: RcList::from(&["T", "U", "V", "R", "u8"] as &[_]),
133 version: String::new(),
134 class: Rc::new(class),
135 class_typing: RcList::from(&["X", "T", "Y", "char"] as &[_]),
136 class_traits: class_traits.clone(),
137 class_bounds: RcList(vec![
138 Rc::new(TraitBoundItem { left: Typing::from("T"), right: Trait::from("Display") }),
139 Rc::new(TraitBoundItem { left: Typing::from("U"), right: Trait::from("Debug") }),
140 ]),
141 };
142
143 html! {
144 <>
145 {class_traits.build_table()}
146 <SignatureComponent::<Extends> data = e/>
147 </>
148 }
149}
150
151pub fn example2(input: &str) -> Html {
152 let class = Class {
153 name: String::from(input),
154 path: "AA".to_string(),
155 generic: vec![Typing::from("T"), Typing::from("U"), Typing::from("char")],
156 traits: vec![],
157 };
158 let e = Function {
159 name: String::from(input),
160 generic: RcList::from(&["u8", "u64", "char"] as &[_]),
161 version: String::new(),
162 class: Rc::new(class),
163 parameters: Parameter::Array(vec![
164 Parameter::Zelf(Some(true)),
165 Parameter::Zelf(Some(false)),
166 Parameter::PositionOnly,
167 Parameter::Zelf(None),
168 Parameter::KeyValueOnly,
169 ]),
170 is_multiline: None,
171 };
172 html! {
173 <SignatureComponent::<Function> data = e/>
174 }
175}
176
177impl Renderable for Full {
178 fn render(&self) -> Html {
179 let sidebar = Sidebar {}.render();
180 let toc = get_toc_title().render();
181
182 html! {
183 <>
184 <header></header>
185 {toc}
186 <main>
187 {sidebar}
188 <section>
189 <article>
190 {example("Template")}
191 {example("Component")}
192 {example2("Tuple")}
193 {example("Class")}
194 {example2("Method")}
195 {example("Function")}
196 {example2("get")}
197 {example("Set")}
198 {example2("plus")}
199 {example2("times")}
200 {example("None")}
201 {example("Null")}
202 </article>
203 </section>
204
205 </main>
206 </>
207 }
208 }
209}