1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Clone, Debug, Serialize, Deserialize)]
5pub struct HxCompletion {
6 pub name: String,
7 pub desc: String,
8}
9
10impl From<&(&str, &str)> for HxCompletion {
11 fn from((name, desc): &(&str, &str)) -> Self {
12 Self {
13 name: name.to_string(),
14 desc: desc.to_string(),
15 }
16 }
17}
18
19fn to_hx_completion(values: Vec<(&str, &str)>) -> Vec<HxCompletion> {
20 values.iter().map(|x| x.into()).collect()
21}
22
23pub fn init_hx_tags() -> Vec<HxCompletion> {
25 let values = vec![
26 ("boost", include_str!("./md/attributes/hx-boost.md")),
27 ("delete", include_str!("./md/attributes/hx-delete.md")),
28 ("get", include_str!("./md/attributes/hx-get.md")),
29 ("include", include_str!("./md/attributes/hx-include.md")),
30 ("patch", include_str!("./md/attributes/hx-patch.md")),
31 ("post", include_str!("./md/attributes/hx-post.md")),
32 ("put", include_str!("./md/attributes/hx-put.md")),
33 ("swap", include_str!("./md/attributes/hx-swap.md")),
34 ("target", include_str!("./md/attributes/hx-target.md")),
35 ("trigger", include_str!("./md/attributes/hx-trigger.md")),
36 ("vals", include_str!("./md/attributes/hx-vals.md")),
37 ("push-url", include_str!("./md/attributes/hx-push-url.md")),
38 ("select", include_str!("./md/attributes/hx-select.md")),
39 ("ext", include_str!("./md/attributes/hx-ext.md")),
40 ("on", include_str!("./md/attributes/hx-on.md")),
41 (
42 "select-oob",
43 include_str!("./md/attributes/hx-select-oob.md"),
44 ),
45 ("swap-oob", include_str!("./md/attributes/hx-swap-oob.md")),
46 ("confirm", include_str!("./md/attributes/hx-confirm.md")),
47 ("disable", include_str!("./md/attributes/hx-disable.md")),
48 ("encoding", include_str!("./md/attributes/hx-encoding.md")),
49 ("headers", include_str!("./md/attributes/hx-headers.md")),
50 ("history", include_str!("./md/attributes/hx-history.md")),
51 (
52 "history-elt",
53 include_str!("./md/attributes/hx-history-elt.md"),
54 ),
55 ("indicator", include_str!("./md/attributes/hx-indicator.md")),
56 ("params", include_str!("./md/attributes/hx-params.md")),
57 ("preserve", include_str!("./md/attributes/hx-preserve.md")),
58 ("prompt", include_str!("./md/attributes/hx-prompt.md")),
59 (
60 "replace-url",
61 include_str!("./md/attributes/hx-replace-url.md"),
62 ),
63 ("request", include_str!("./md/attributes/hx-request.md")),
64 ("sync", include_str!("./md/attributes/hx-sync.md")),
65 ("validate", include_str!("./md/attributes/hx-validate.md")),
66 ];
67
68 to_hx_completion(values)
69}
70
71pub fn init_hx_values() -> HashMap<String, Vec<HxCompletion>> {
73 let mut hm = HashMap::new();
74
75 let hx_swap = to_hx_completion(vec![
76 ("innerHTML", include_str!("./md/hx-swap/innerHTML.md")),
77 ("outerHTML", include_str!("./md/hx-swap/outerHTML.md")),
78 ("afterbegin", include_str!("./md/hx-swap/afterbegin.md")),
79 ("afterend", include_str!("./md/hx-swap/afterend.md")),
80 ("beforebegin", include_str!("./md/hx-swap/beforebegin.md")),
81 ("beforeend", include_str!("./md/hx-swap/beforeend.md")),
82 ("delete", include_str!("./md/hx-swap/delete.md")),
83 ("none", include_str!("./md/hx-swap/none.md")),
84 ]);
85 hm.insert(String::from("hx-swap"), hx_swap);
86
87 let hx_target = to_hx_completion(vec![
88 ("closest", include_str!("./md/hx-target/closest.md")),
89 ("find", include_str!("./md/hx-target/find.md")),
90 ("next", include_str!("./md/hx-target/next.md")),
91 ("prev", include_str!("./md/hx-target/prev.md")),
92 ("this", include_str!("./md/hx-target/this.md")),
93 ]);
94 hm.insert(String::from("hx-target"), hx_target);
95
96 let hx_boost = to_hx_completion(vec![
97 ("true", include_str!("./md/hx-boost/true.md")),
98 ("false", include_str!("./md/hx-boost/false.md")),
99 ]);
100 hm.insert(String::from("hx-boost"), hx_boost);
101
102 let hx_trigger = to_hx_completion(vec![
103 ("click", include_str!("./md/hx-trigger/click.md")),
104 ("once", include_str!("./md/hx-trigger/once.md")),
105 ("changed", include_str!("./md/hx-trigger/changed.md")),
106 ("delay:", include_str!("./md/hx-trigger/delay.md")),
107 ("throttle:", include_str!("./md/hx-trigger/throttle.md")),
108 ("from:", include_str!("./md/hx-trigger/from.md")),
109 ("target:", include_str!("./md/hx-trigger/target.md")),
110 ("consume", include_str!("./md/hx-trigger/consume.md")),
111 ("queue:", include_str!("./md/hx-trigger/queue.md")),
112 ("keyup", include_str!("./md/hx-trigger/keyup.md")),
113 ("load", include_str!("./md/hx-trigger/load.md")),
114 ("revealed", include_str!("./md/hx-trigger/revealed.md")),
115 ("intersect", include_str!("./md/hx-trigger/intersect.md")),
116 ("every", include_str!("./md/hx-trigger/every.md")),
117 ]);
118 hm.insert(String::from("hx-trigger"), hx_trigger);
119
120 let hx_ext = to_hx_completion(vec![
121 ("ajax-header", include_str!("./md/hx-ext/ajax-header.md")),
122 ("alpine-morph", include_str!("./md/hx-ext/alpine-morph.md")),
123 ("class-tools", include_str!("./md/hx-ext/class-tools.md")),
124 (
125 "client-side-templates",
126 include_str!("./md/hx-ext/client-side-templates.md"),
127 ),
128 ("debug", include_str!("./md/hx-ext/debug.md")),
129 (
130 "disable-element",
131 include_str!("./md/hx-ext/disable-element.md"),
132 ),
133 ("event-header", include_str!("./md/hx-ext/event-header.md")),
134 ("head-support", include_str!("./md/hx-ext/head-support.md")),
135 ("include-vals", include_str!("./md/hx-ext/include-vals.md")),
136 ("json-enc", include_str!("./md/hx-ext/json-enc.md")),
137 ("morph", include_str!("./md/hx-ext/morph.md")),
138 (
139 "loading-states",
140 include_str!("./md/hx-ext/loading-states.md"),
141 ),
142 (
143 "method-override",
144 include_str!("./md/hx-ext/method-override.md"),
145 ),
146 (
147 "morphdom-swap",
148 include_str!("./md/hx-ext/morphdom-swap.md"),
149 ),
150 ("multi-swap", include_str!("./md/hx-ext/multi-swap.md")),
151 ("path-deps", include_str!("./md/hx-ext/path-deps.md")),
152 ("preload", include_str!("./md/hx-ext/preload.md")),
153 ("remove-me", include_str!("./md/hx-ext/remove-me.md")),
154 (
155 "response-targets",
156 include_str!("./md/hx-ext/response-targets.md"),
157 ),
158 ("restored", include_str!("./md/hx-ext/restored.md")),
159 ("sse", include_str!("./md/hx-ext/sse.md")),
160 ("ws", include_str!("./md/hx-ext/ws.md")),
161 ]);
162 hm.insert(String::from("hx-ext"), hx_ext);
163
164 let hx_push_ul = to_hx_completion(vec![
165 ("true", include_str!("./md/hx-push-url/true.md")),
166 ("false", include_str!("./md/hx-push-url/false.md")),
167 ]);
168 hm.insert(String::from("hx-push-ul"), hx_push_ul);
169
170 let hx_swap_ob = to_hx_completion(vec![
171 ("true", include_str!("./md/hx-swap-oob/true.md")),
172 ("innerHTML", include_str!("./md/hx-swap/innerHTML.md")),
173 ("outerHTML", include_str!("./md/hx-swap/outerHTML.md")),
174 ("afterbegin", include_str!("./md/hx-swap/afterbegin.md")),
175 ("afterend", include_str!("./md/hx-swap/afterend.md")),
176 ("beforebegin", include_str!("./md/hx-swap/beforebegin.md")),
177 ("beforeend", include_str!("./md/hx-swap/beforeend.md")),
178 ("delete", include_str!("./md/hx-swap/delete.md")),
179 ("none", include_str!("./md/hx-swap/none.md")),
180 ]);
181 hm.insert(String::from("hx-swap-ob"), hx_swap_ob);
182
183 let hx_history = to_hx_completion(vec![("false", include_str!("./md/hx-history/false.md"))]);
184 hm.insert(String::from("hx-history"), hx_history);
185
186 let hx_params = to_hx_completion(vec![
187 ("*", include_str!("./md/hx-params/star.md")),
188 ("none", include_str!("./md/hx-params/none.md")),
189 ("not", include_str!("./md/hx-params/not.md")),
190 ]);
191 hm.insert(String::from("hx-params"), hx_params);
192
193 let hx_replace_ul = to_hx_completion(vec![
194 ("true", include_str!("./md/hx-replace-url/true.md")),
195 ("false", include_str!("./md/hx-replace-url/false.md")),
196 ]);
197 hm.insert(String::from("hx-replace-ul"), hx_replace_ul);
198
199 let hx_sync = to_hx_completion(vec![
200 ("drop", include_str!("./md/hx-sync/drop.md")),
201 ("abort", include_str!("./md/hx-sync/abort.md")),
202 ("replace", include_str!("./md/hx-sync/replace.md")),
203 ("queue", include_str!("./md/hx-sync/queue.md")),
204 ]);
205 hm.insert(String::from("hx-sync"), hx_sync);
206
207 hm
208}
209
210#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
228pub enum LangType {
229 Template,
230 JavaScript,
231 Backend,
232}
233
234pub enum LangTypes {
238 One(LangType),
239 Two { first: LangType, second: LangType },
240}
241
242impl LangTypes {
243 pub fn one(lang_type: LangType) -> Self {
244 Self::One(lang_type)
245 }
246
247 pub fn two(lang_types: (LangType, LangType)) -> Self {
248 Self::Two {
249 first: lang_types.0,
250 second: lang_types.1,
251 }
252 }
253
254 pub fn is_lang(&self, lang_type: LangType) -> bool {
256 match self {
257 LangTypes::One(lang) => lang == &lang_type,
258 LangTypes::Two { first, second } => first == &lang_type || second == &lang_type,
259 }
260 }
261
262 pub fn get(&self) -> LangType {
263 match self {
264 LangTypes::One(lang) => *lang,
265 LangTypes::Two { first, .. } => *first,
266 }
267 }
268}
269
270impl From<usize> for LangType {
271 fn from(value: usize) -> Self {
272 match value {
273 0 => LangType::Template,
274 1 => LangType::JavaScript,
275 2 => LangType::Backend,
276 _ => LangType::Backend,
277 }
278 }
279}