1
2#![ no_implicit_prelude ]
3
4
5
6
7#[ cfg (feature = "runtime-askama") ]
8#[ macro_export ]
9macro_rules! askama {
10
11
12 (
13 $_resource_name : ident,
14 $_template_name : ident,
15 $_context_descriptor : tt,
16 $_content_type : tt,
17 $_template_path : literal,
18 $_description : literal
19 ) => {
20
21 #[ derive (::askama::Template) ]
22 #[ template (path = $_template_path) ]
23 #[ allow (non_camel_case_types) ]
24 pub(crate) struct $_template_name {
25 pub context : $crate::askama_context_type! ($_context_descriptor),
26 pub __is_production : bool,
27 pub __is_development : bool,
28 }
29
30 $crate::cfg_builder_askama_dynamic_disabled! {
31 #[ allow (non_camel_case_types) ]
32 pub(crate) struct $_resource_name {
33 template : $_template_name,
34 }
35 }
36
37 $crate::cfg_builder_askama_dynamic_enabled! {
38 #[ allow (non_camel_case_types) ]
39 pub(crate) struct $_resource_name {}
40 }
41
42 #[ allow (dead_code) ]
43 impl $_resource_name {
44
45 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
46 $crate::cfg_builder_askama_dynamic_disabled! {
47 let _self = Self {
48 template : Self::template_build (_extensions) ?,
49 };
50 }
51 $crate::cfg_builder_askama_dynamic_enabled! {
52 let _self = Self {};
53 }
54 $crate::hss::ServerResult::Ok (_self)
55 }
56
57 pub fn render (&self) -> $crate::hss::ServerResult<::std::string::String> {
58 $crate::cfg_builder_askama_dynamic_disabled! {
59 let _template = &self.template;
60 }
61 $crate::cfg_builder_askama_dynamic_enabled! {
62 let _template = Self::template_build (&$crate::hss::Extensions::new ()) ?;
64 let _template = &_template;
65 }
66 ::askama::Template::render (_template)
67 .map_err (|_error| ::std::io::Error::new (::std::io::ErrorKind::Other, ::std::format! ("[{:08x}] {}", 0x60beda55, _error)))
68 }
69
70 pub fn into_handler (self) -> impl $crate::hss::Handler {
71 $crate::hss::HandlerSimpleSyncWrapper::new (self)
72 }
73
74 fn template_build (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<$_template_name> {
75 let _context = $crate::askama_context_new! ($_context_descriptor, _extensions) ?;
76 let _template = $_template_name {
77 context : _context,
78 __is_production : $crate::cfg_if_production! ({ true } | { false }),
79 __is_development : $crate::cfg_if_production! ({ false } | { true }),
80 };
81 $crate::hss::ServerResult::Ok (_template)
82 }
83 }
84
85 impl $crate::StaticResource for $_resource_name {
86
87 fn content_type (&self) -> $crate::hss::ContentType {
88 $crate::resource_content_type! ($_content_type)
89 }
90
91 fn description (&self) -> &'static str {
92 $_description
93 }
94
95 fn into_handler_dyn (self) -> $crate::hss::HandlerDynArc {
96 let _handler = self.into_handler ();
97 let _handler = $crate::hss::HandlerDynArc::new (_handler);
98 _handler
99 }
100 }
101
102 impl $crate::hss::HandlerSimpleSync for $_resource_name {
103
104 fn handle (&self, _request : &$crate::hss::Request<$crate::hss::Body>, _response : &mut $crate::hss::Response<$crate::hss::Body>) -> $crate::hss::ServerResult {
105 use $crate::hss::ResponseExt as _;
106 use $crate::StaticResource as _;
107 let _body = self.render () ?;
108 _response.set_status_200 ();
109 _response.set_content_type (self.content_type ());
110 _response.set_body (_body);
111 $crate::hss::ServerResult::Ok (())
112 }
113 }
114 };
115}
116
117
118
119
120#[ cfg (feature = "runtime-askama") ]
121#[ macro_export ]
122macro_rules! askama_document {
123
124
125 (
126 $_resource_name : ident,
127 $_template_name : ident,
128 $_context_descriptor : tt,
129 $_content_type : tt,
130 $_template_path : literal,
131 $_body_path : literal,
132 $_title_path : literal,
133 $_metadata_path : literal,
134 $( $_refresher_name : ident, )?
135 $_description : literal
136 ) => {
137
138 #[ derive (::askama::Template) ]
139 #[ template (path = $_template_path) ]
140 #[ allow (non_camel_case_types) ]
141 pub(crate) struct $_template_name {
142 pub context : $crate::askama_context_type! ($_context_descriptor),
143 pub body : ::std::string::String,
144 pub title : ::std::string::String,
145 pub metadata : $crate::AskamaDocumentMetadata,
146 pub __is_production : bool,
147 pub __is_development : bool,
148 }
149
150 $crate::cfg_builder_askama_dynamic_disabled! {
151 #[ allow (non_camel_case_types) ]
152 pub(crate) struct $_resource_name {
153 template : $_template_name,
154 }
155 }
156
157 $crate::cfg_builder_askama_dynamic_enabled! {
158 #[ allow (non_camel_case_types) ]
159 pub(crate) struct $_resource_name {}
160 }
161
162 #[ allow (dead_code) ]
163 impl $_resource_name {
164
165 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
166 $crate::cfg_builder_askama_dynamic_disabled! {
167 let _self = Self {
168 template : Self::template_build (_extensions) ?,
169 };
170 }
171 $crate::cfg_builder_askama_dynamic_enabled! {
172 let _self = Self {};
173 }
174 $crate::hss::ServerResult::Ok (_self)
175 }
176
177 pub fn render (&self) -> $crate::hss::ServerResult<::std::string::String> {
178 $crate::cfg_builder_askama_dynamic_disabled! {
179 let _template = &self.template;
180 }
181 $crate::cfg_builder_askama_dynamic_enabled! {
182 let _template = Self::template_build (&$crate::hss::Extensions::new ()) ?;
184 let _template = &_template;
185 }
186 ::askama::Template::render (_template)
187 .map_err (|_error| ::std::io::Error::new (::std::io::ErrorKind::Other, ::std::format! ("[{:08x}] {}", 0x28df3421, _error)))
188 }
189
190 pub fn into_handler (self) -> impl $crate::hss::Handler {
191 $crate::hss::HandlerSimpleSyncWrapper::new (self)
192 }
193
194 fn template_build (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<$_template_name> {
195 use ::std::convert::From as _;
196 $crate::cfg_builder_askama_dynamic_disabled! {
197 $(
198 ::std::compile_error! ("`refresher` not supported without dynamic feature!");
199 type _refresher_type = $_refresher_name;
200 )?
201 let _body = ::std::string::String::from (::std::include_str! ($_body_path));
202 let _title = ::std::string::String::from (::std::include_str! ($_title_path));
203 let _metadata = ::std::include_str! ($_metadata_path);
204 let _metadata = $crate::AskamaDocumentMetadata::load_from_json (_metadata) ?;
205 }
206 $crate::cfg_builder_askama_dynamic_enabled! {
207 $( $_refresher_name::refresh () ?; )?
208 use $crate::hss::ResultExtWrap as _;
209 let _body = ::std::fs::read_to_string ($_body_path) .or_wrap (0x222c7659) ?;
210 let _title = ::std::fs::read_to_string ($_title_path) .or_wrap (0x32c4e114) ?;
211 let _metadata = ::std::fs::read_to_string ($_metadata_path) .or_wrap (0xc07d6b78) ?;
212 let _metadata = $crate::AskamaDocumentMetadata::load_from_json (&_metadata) ?;
213 }
214 let _context = $crate::askama_context_new! ($_context_descriptor, _extensions) ?;
215 let _template = $_template_name {
216 context : _context,
217 body : _body,
218 title : _title,
219 metadata : _metadata,
220 __is_production : $crate::cfg_if_production! ({ true } | { false }),
221 __is_development : $crate::cfg_if_production! ({ false } | { true }),
222 };
223 $crate::hss::ServerResult::Ok (_template)
224 }
225 }
226
227 impl $crate::StaticResource for $_resource_name {
228
229 fn content_type (&self) -> $crate::hss::ContentType {
230 $crate::resource_content_type! ($_content_type)
231 }
232
233 fn description (&self) -> &'static str {
234 $_description
235 }
236
237 fn into_handler_dyn (self) -> $crate::hss::HandlerDynArc {
238 let _handler = self.into_handler ();
239 let _handler = $crate::hss::HandlerDynArc::new (_handler);
240 _handler
241 }
242 }
243
244 impl $crate::hss::HandlerSimpleSync for $_resource_name {
245
246 fn handle (&self, _request : &$crate::hss::Request<$crate::hss::Body>, _response : &mut $crate::hss::Response<$crate::hss::Body>) -> $crate::hss::ServerResult {
247 use $crate::hss::ResponseExt as _;
248 use $crate::StaticResource as _;
249 let _body = self.render () ?;
250 _response.set_status_200 ();
251 _response.set_content_type (self.content_type ());
252 _response.set_body (_body);
253 $crate::hss::ServerResult::Ok (())
254 }
255 }
256 };
257}
258
259
260
261
262#[ cfg (feature = "runtime-askama") ]
263#[ macro_export ]
264macro_rules! askama_context_type {
265
266 ( $_context_type : ty ) => {
267 $crate::askama_context_type! ({ type : $_context_type })
268 };
269
270 ( { type : $_context_type : ty $( , $( $_ : tt )+ )* } ) => {
271 $_context_type
272 };
273}
274
275
276#[ cfg (feature = "runtime-askama") ]
277#[ macro_export ]
278macro_rules! askama_context_new {
279
280 ( $_context_type : ty, $_extensions : expr ) => {
281 $crate::askama_context_new! ({ type : $_context_type }, $_extensions)
282 };
283
284 ( { type : $_context_type : ty }, $_extensions : expr ) => {
285 {
286 let _extensions : &$crate::hss::Extensions = $_extensions;
287 <$_context_type as $crate::AskamaContext>::new_with_extensions (_extensions)
288 }
289 };
290
291 ( { type : $_context_type : ty, json : $_context_path : literal }, $_extensions : expr) => {
292 $crate::askama_context_new! ({ type : $_context_type, deserialize : ("json", $_context_path) }, $_extensions)
293 };
294 ( { type : $_context_type : ty, toml : $_context_path : literal }, $_extensions : expr) => {
295 $crate::askama_context_new! ({ type : $_context_type, deserialize : ("toml", $_context_path) }, $_extensions)
296 };
297 ( { type : $_context_type : ty, yaml : $_context_path : literal }, $_extensions : expr) => {
298 $crate::askama_context_new! ({ type : $_context_type, deserialize : ("yaml", $_context_path) }, $_extensions)
299 };
300
301 ( { type : $_context_type : ty, deserialize : ( $_context_encoding : literal, $_context_path : literal ) }, $_extensions : expr ) => {
302 {
303 $crate::cfg_builder_askama_dynamic_disabled! {
304 let _context = $crate::askama_context_new! ({ type : $_context_type, (deserialize, embedded) : ($_context_encoding, $_context_path)}, $_extensions);
305 }
306 $crate::cfg_builder_askama_dynamic_enabled! {
307 let _context = $crate::askama_context_new! ({ type : $_context_type, (deserialize, dynamic) : ($_context_encoding, $_context_path)}, $_extensions);
308 }
309 _context
310 }
311 };
312
313 ( { type : $_context_type : ty, (deserialize, embedded) : ( $_context_encoding : literal, $_context_path : literal ) }, $_extensions : expr ) => {
314 {
315 let _encoding : &str = $_context_encoding;
316 let _data : &[u8] = ::std::include_bytes! ($_context_path);
317 let _extensions : &$crate::hss::Extensions = $_extensions;
318 <$_context_type as $crate::AskamaContext>::new_with_deserialization (_encoding, _data, _extensions)
319 }
320 };
321
322 ( { type : $_context_type : ty, (deserialize, dynamic) : ( $_context_encoding : literal, $_context_path : literal ) }, $_extensions : expr ) => {
323 {
324 use $crate::hss::ResultExtWrap as _;
325 let _encoding : &str = $_context_encoding;
326 let _data = ::std::fs::read ($_context_path) .or_wrap (0x98ea260c) ?;
327 let _extensions : &$crate::hss::Extensions = $_extensions;
328 <$_context_type as $crate::AskamaContext>::new_with_deserialization (_encoding, &_data, _extensions)
329 }
330 };
331}
332
333
334
335
336#[ macro_export ]
337macro_rules! resource {
338
339
340 ( $_resource_name : ident, $_content_type : tt, auto, $_resource_path : tt, $_description : literal ) => {
341 $crate::cfg_if_production! {{
342 $crate::resource! ($_resource_name, $_content_type, embedded, $_resource_path, $_description);
343 } | {
344 $crate::resource! ($_resource_name, $_content_type, dynamic, $_resource_path, $_description);
345 }}
346 };
347
348
349 ( $_resource_name : ident, $_content_type : tt, embedded, $_resource_path : tt, $_description : literal ) => {
350
351 #[ allow (non_camel_case_types) ]
352 pub(crate) struct $_resource_name ();
353
354 #[ allow (dead_code) ]
355 impl $_resource_name {
356
357 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
358 let _self = Self ();
359 $crate::hss::ServerResult::Ok (_self)
360 }
361
362 pub fn into_handler (self) -> impl $crate::hss::Handler {
363 self
364 }
365
366 const RESOURCE : $crate::hss::EmbeddedResource =
367 $crate::hss::EmbeddedResource::new_const (
368 ::std::include_bytes! ($crate::resource_path! ($_resource_path)),
369 ::std::option::Option::Some ($crate::resource_content_type! ($_content_type)),
370 );
371 }
372
373 impl $crate::StaticResource for $_resource_name {
374
375 fn content_type (&self) -> $crate::hss::ContentType {
376 $crate::resource_content_type! ($_content_type)
377 }
378
379 fn description (&self) -> &'static str {
380 $_description
381 }
382
383 fn into_handler_dyn (self) -> $crate::hss::HandlerDynArc {
384 let _handler = self.into_handler ();
385 let _handler = $crate::hss::HandlerDynArc::new (_handler);
386 _handler
387 }
388 }
389
390 impl $crate::hss::Handler for $_resource_name {
391
392 type Future = <$crate::hss::EmbeddedResource as $crate::hss::Handler>::Future;
393 type ResponseBody = <$crate::hss::EmbeddedResource as $crate::hss::Handler>::ResponseBody;
394 type ResponseBodyError = <$crate::hss::EmbeddedResource as $crate::hss::Handler>::ResponseBodyError;
395
396 fn handle (&self, _request : $crate::hss::Request<$crate::hss::Body>) -> Self::Future {
397 Self::RESOURCE.handle (_request)
398 }
399 }
400 };
401
402
403 ( $_resource_name : ident, $_content_type : tt, dynamic, $_resource_path : tt, $_description : literal ) => {
404
405 #[ allow (non_camel_case_types) ]
406 pub(crate) struct $_resource_name {
407 resource : $crate::hss::FileResource,
408 }
409
410 #[ allow (dead_code) ]
411 impl $_resource_name {
412
413 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
414 let _self = Self {
415 resource : $crate::hss::FileResource::new (
416 $crate::resource_path! ($_resource_path),
417 ::std::option::Option::Some ($crate::resource_content_type! ($_content_type)),
418 false,
419 )
420 };
421 $crate::hss::ServerResult::Ok (_self)
422 }
423
424 pub fn into_handler (self) -> impl $crate::hss::Handler {
425 self
426 }
427 }
428
429 impl $crate::StaticResource for $_resource_name {
430
431 fn content_type (&self) -> $crate::hss::ContentType {
432 $crate::resource_content_type! ($_content_type)
433 }
434
435 fn description (&self) -> &'static str {
436 $_description
437 }
438
439 fn into_handler_dyn (self) -> $crate::hss::HandlerDynArc {
440 let _handler = self.into_handler ();
441 let _handler = $crate::hss::HandlerDynArc::new (_handler);
442 _handler
443 }
444 }
445
446 impl $crate::hss::Handler for $_resource_name {
447
448 type Future = <$crate::hss::FileResource as $crate::hss::Handler>::Future;
449 type ResponseBody = <$crate::hss::FileResource as $crate::hss::Handler>::ResponseBody;
450 type ResponseBodyError = <$crate::hss::FileResource as $crate::hss::Handler>::ResponseBodyError;
451
452 fn handle (&self, _request : $crate::hss::Request<$crate::hss::Body>) -> Self::Future {
453 self.resource.handle (_request)
454 }
455 }
456 };
457}
458
459
460
461
462#[ macro_export ]
463#[ cfg (all (feature = "builder-assets-sass-dynamic", not (feature = "production"))) ]
464macro_rules! resource_sass_dynamic {
465
466 ( $_resource_name : ident, $_content_type : tt, $_source_path : tt, $_description : literal ) => {
467
468 #[ allow (non_camel_case_types) ]
469 pub(crate) struct $_resource_name {
470 source : &'static ::std::path::Path,
471 }
472
473 #[ allow (dead_code) ]
474 impl $_resource_name {
475
476 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
477 let _self = Self {
478 source : ::std::path::Path::new ($crate::resource_path! ($_source_path)),
479 };
480 $crate::hss::ServerResult::Ok (_self)
481 }
482
483 pub fn render (&self) -> $crate::hss::ServerResult<::std::string::String> {
484 $crate::support_sass::compile_sass (self.source)
485 .map_err (|_error| ::std::io::Error::new (::std::io::ErrorKind::Other, ::std::format! ("[{:08x}] {}", 0x548c29d4, _error)))
486 }
487
488 pub fn into_handler (self) -> impl $crate::hss::Handler {
489 $crate::hss::HandlerSimpleSyncWrapper::new (self)
490 }
491 }
492
493 impl $crate::StaticResource for $_resource_name {
494
495 fn content_type (&self) -> $crate::hss::ContentType {
496 $crate::resource_content_type! ($_content_type)
497 }
498
499 fn description (&self) -> &'static str {
500 $_description
501 }
502
503 fn into_handler_dyn (self) -> $crate::hss::HandlerDynArc {
504 let _handler = self.into_handler ();
505 let _handler = $crate::hss::HandlerDynArc::new (_handler);
506 _handler
507 }
508 }
509
510 impl $crate::hss::HandlerSimpleSync for $_resource_name {
511
512 fn handle (&self, _request : &$crate::hss::Request<$crate::hss::Body>, _response : &mut $crate::hss::Response<$crate::hss::Body>) -> $crate::hss::ServerResult {
513 use $crate::hss::ResponseExt as _;
514 use $crate::StaticResource as _;
515 let _body = self.render () ?;
516 _response.set_status_200 ();
517 _response.set_content_type (self.content_type ());
518 _response.set_body (_body);
519 $crate::hss::ServerResult::Ok (())
520 }
521 }
522 };
523}
524
525
526
527
528#[ macro_export ]
529#[ cfg (all (feature = "builder-markdown-dynamic", not (feature = "production"))) ]
530macro_rules! resource_markdown_dynamic {
531
532 ( $_resource_name : ident, $_content_type : tt, $_source_path : tt, $_header_path : tt, $_footer_path : tt, $_description : literal ) => {
533
534 #[ allow (non_camel_case_types) ]
535 pub(crate) struct $_resource_name {
536 source : &'static ::std::path::Path,
537 header : ::std::option::Option<&'static ::std::path::Path>,
538 footer : ::std::option::Option<&'static ::std::path::Path>,
539 }
540
541 #[ allow (dead_code) ]
542 impl $_resource_name {
543
544 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
545 let _self = Self {
546 source : ::std::path::Path::new ($crate::resource_path! ($_source_path)),
547 header : $crate::resource_path! ($_header_path) .map (::std::path::Path::new::<str>),
548 footer : $crate::resource_path! ($_footer_path) .map (::std::path::Path::new::<str>),
549 };
550 $crate::hss::ServerResult::Ok (_self)
551 }
552
553 pub fn render (&self) -> $crate::hss::ServerResult<::std::string::String> {
554 $crate::support_markdown::compile_markdown_html_from_path (self.source, self.header, self.footer, ::std::option::Option::None)
555 .map_err (|_error| ::std::io::Error::new (::std::io::ErrorKind::Other, ::std::format! ("[{:08x}] {}", 0x35c91763, _error)))
556 }
557
558 pub fn into_handler (self) -> impl $crate::hss::Handler {
559 $crate::hss::HandlerSimpleSyncWrapper::new (self)
560 }
561 }
562
563 impl $crate::StaticResource for $_resource_name {
564
565 fn content_type (&self) -> $crate::hss::ContentType {
566 $crate::resource_content_type! ($_content_type)
567 }
568
569 fn description (&self) -> &'static str {
570 $_description
571 }
572
573 fn into_handler_dyn (self) -> $crate::hss::HandlerDynArc {
574 let _handler = self.into_handler ();
575 let _handler = $crate::hss::HandlerDynArc::new (_handler);
576 _handler
577 }
578 }
579
580 impl $crate::hss::HandlerSimpleSync for $_resource_name {
581
582 fn handle (&self, _request : &$crate::hss::Request<$crate::hss::Body>, _response : &mut $crate::hss::Response<$crate::hss::Body>) -> $crate::hss::ServerResult {
583 use $crate::hss::ResponseExt as _;
584 use $crate::StaticResource as _;
585 let _body = self.render () ?;
586 _response.set_status_200 ();
587 _response.set_content_type (self.content_type ());
588 _response.set_body (_body);
589 $crate::hss::ServerResult::Ok (())
590 }
591 }
592 };
593}
594
595
596
597
598#[ macro_export ]
599#[ cfg (all (feature = "builder-markdown-dynamic", not (feature = "production"))) ]
600macro_rules! resource_markdown_refresher {
601
602 ( $_refresher_name : ident, $_source_path : tt, $_body_path : tt, $_title_path : tt, $_metadata_path : tt, $_frontmatter_path : tt ) => {
603
604 #[ allow (non_camel_case_types) ]
605 pub(crate) struct $_refresher_name {}
606
607 #[ allow (dead_code) ]
608 impl $_refresher_name {
609
610 fn refresh () -> $crate::hss::ServerResult {
611 $crate::support_markdown::compile_markdown_from_path_to_paths (
612 ::std::path::Path::new ($crate::resource_path! ($_source_path)),
613 ::std::option::Option::None,
614 ::std::option::Option::Some (::std::path::Path::new ($crate::resource_path! ($_body_path))),
615 ::std::option::Option::Some (::std::path::Path::new ($crate::resource_path! ($_title_path))),
616 ::std::option::Option::Some (::std::path::Path::new ($crate::resource_path! ($_metadata_path))),
617 ::std::option::Option::Some (::std::path::Path::new ($crate::resource_path! ($_frontmatter_path))),
618 )
619 .map_err (|_error| ::std::io::Error::new (::std::io::ErrorKind::Other, ::std::format! ("[{:08x}] {}", 0xec077645, _error)))
620 }
621 }
622 };
623}
624
625
626
627
628#[ macro_export ]
629macro_rules! route {
630
631
632 ( $_route_name : ident, $_resource_name : ty, $_route_path : literal, $_route_extensions : tt ) => {
633
634 #[ allow (non_camel_case_types) ]
635 pub(crate) struct $_route_name ($crate::hss::Route);
636
637 impl $_route_name {
638
639 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
640 use ::std::convert::From as _;
641 use $crate::StaticResource as _;
642 let _resource = <$_resource_name>::new (_extensions) ?;
643 let _path = ::std::string::String::from ($_route_path);
645 let _description = _resource.description ();
646 let _handler = $crate::hss::RouteHandler::HandlerDynArc (_resource.into_handler_dyn () .into_arc ());
647 let mut _extensions = $crate::route_extensions! ($_route_extensions);
648 if _extensions.get::<$crate::StaticRouteDebug> () .is_none () {
649 _extensions.insert ($crate::StaticRouteDebug::from_str_static (_description));
650 }
651 let mut _route = $crate::hss::Route {
652 path : _path,
653 handler : _handler,
654 extensions : _extensions,
655 };
656 let _self = Self (_route);
657 $crate::hss::ServerResult::Ok (_self)
658 }
659 }
660
661 impl $crate::StaticRoute for $_route_name {
662
663 fn into_route (self) -> $crate::hss::Route {
664 self.0
665 }
666 }
667
668 impl ::std::convert::Into<$crate::hss::Route> for $_route_name {
669
670 fn into (self) -> $crate::hss::Route {
671 use $crate::StaticRoute as _;
672 self.into_route ()
673 }
674 }
675 };
676}
677
678
679
680
681#[ cfg (feature = "runtime-sitemaps") ]
682#[ macro_export ]
683macro_rules! route_sitemap {
684
685
686 ( $_route_name : ident, $_route_path : literal, $_prefix : literal, $_format : ident, $_route_extensions : tt ) => {
687
688 #[ allow (non_camel_case_types) ]
689 pub(crate) struct $_route_name ($crate::hss::Route);
690
691 impl $_route_name {
692
693 pub fn new (_extensions : &$crate::hss::Extensions) -> $crate::hss::ServerResult<Self> {
694 use ::std::convert::From as _;
695 use $crate::StaticResource as _;
696 let _prefix = ::std::string::String::from ($_prefix);
697 let _format = $crate::SitemapFormat::from_str_must (::std::stringify! ($_format));
698 let _resource = $crate::RoutesSitemapResource::new (_prefix, _format, ::std::option::Option::Some (_extensions)) ?;
699 let _path = ::std::string::String::from ($_route_path);
701 let _description = _resource.description ();
702 let _handler = $crate::hss::RouteHandler::HandlerDynArc (_resource.into_handler_dyn () .into_arc ());
703 let mut _extensions = $crate::route_extensions! ($_route_extensions);
704 if _extensions.get::<$crate::StaticRouteDebug> () .is_none () {
705 _extensions.insert ($crate::StaticRouteDebug::from_str_static (_description));
706 }
707 let mut _route = $crate::hss::Route {
708 path : _path,
709 handler : _handler,
710 extensions : _extensions,
711 };
712 let _self = Self (_route);
713 $crate::hss::ServerResult::Ok (_self)
714 }
715 }
716
717 impl $crate::StaticRoute for $_route_name {
718
719 fn into_route (self) -> $crate::hss::Route {
720 self.0
721 }
722 }
723
724 impl ::std::convert::Into<$crate::hss::Route> for $_route_name {
725
726 fn into (self) -> $crate::hss::Route {
727 use $crate::StaticRoute as _;
728 self.into_route ()
729 }
730 }
731 };
732}
733
734
735
736
737#[ macro_export ]
738macro_rules! route_extensions {
739
740 ( $_extensions : tt ) => {
741 {
742 let mut _extensions = $crate::hss::Extensions::new ();
743 $crate::route_extensions_insert! (_extensions, $_extensions);
744 _extensions
745 }
746 };
747}
748
749
750#[ macro_export ]
751macro_rules! route_extensions_insert {
752
753 ( $_extensions : ident, () ) => {
754 };
755
756 ( $_extensions : ident, {} ) => {
757 };
758
759 ( $_extensions : ident, { $_key : ident $( , $( $_rest : tt )+ )* } ) => {
760 $crate::route_extensions_insert_one! ($_extensions, $_key);
761 $crate::route_extensions_insert! ($_extensions, { $( $( $_rest )* ),* });
762 };
763
764 ( $_extensions : ident, { $_key : ident : $_value : tt $( , $( $_rest : tt )+ )* } ) => {
765 $crate::route_extensions_insert_one! ($_extensions, $_key, $_value);
766 $crate::route_extensions_insert! ($_extensions, { $( $( $_rest )* ),* });
767 };
768}
769
770
771#[ macro_export ]
772macro_rules! route_extensions_insert_one {
773
774 ( $_extensions : ident, debug, $_debug : expr ) => {
775 $_extensions.insert ($crate::StaticRouteDebug::new ($_debug));
776 };
777
778 ( $_extensions : ident, sitemap ) => {
779 $_extensions.insert ($crate::RouteSitemapEntry::new ());
780 };
781 ( $_extensions : ident, sitemap, { frequency : $_frequency : ident } ) => {
782 {
783 let mut _entry = $crate::RouteSitemapEntry::new ();
784 _entry.frequency = $crate::SitemapFrequency::from_str_must (::std::stringify! ($_frequency));
785 $_extensions.insert (_entry);
786 }
787 };
788 ( $_extensions : ident, sitemap, { frequency : $_frequency : ident, priority : $_priority : ident } ) => {
789 {
790 let mut _entry = $crate::RouteSitemapEntry::new ();
791 _entry.frequency = $crate::SitemapFrequency::from_str_must (::std::stringify! ($_frequency));
792 _entry.priority = $crate::SitemapPriority::from_str_must (::std::stringify! ($_priority));
793 $_extensions.insert (_entry);
794 }
795 };
796 ( $_extensions : ident, sitemap, { frequency : $_frequency : ident, priority : $_priority : literal } ) => {
797 {
798 let mut _entry = $crate::RouteSitemapEntry::new ();
799 _entry.frequency = $crate::SitemapFrequency::from_str_must (::std::stringify! ($_frequency));
800 _entry.priority = $crate::SitemapPriority::from_str_must (::std::stringify! ($_priority));
801 $_extensions.insert (_entry);
802 }
803 };
804}
805
806
807
808
809#[ macro_export ]
810macro_rules! routes {
811
812
813 ( $_name : ident, [ $( $_route : ty, )* ] ) => {
814
815 #[ allow (non_camel_case_types) ]
816 pub(crate) struct $_name ($crate::hss::Routes);
817
818 impl $_name {
819
820 pub fn new () -> $crate::hss::ServerResult<Self> {
821 Self::new_with_extensions (::std::option::Option::None)
822 }
823
824 pub fn new_with_extensions (_extensions : ::std::option::Option<&$crate::hss::Extensions>) -> $crate::hss::ServerResult<Self> {
825 use ::std::iter::IntoIterator as _;
826 let _routes = Self::routes_with_extensions (_extensions) ?;
827 let mut _builder = $crate::hss::RoutesBuilder::new ();
828 for _route in _routes.into_iter () {
829 _builder = _builder.with_route_object (_route);
830 }
831 let _routes = _builder.build () ?;
832 let _self = Self (_routes);
833 $crate::hss::ServerResult::Ok (_self)
834 }
835 }
836
837 impl $_name {
838
839 pub fn routes () -> $crate::hss::ServerResult<::std::vec::Vec<$crate::hss::Route>> {
840 Self::routes_with_extensions (::std::option::Option::None)
841 }
842
843 pub fn routes_with_extensions (_extensions : ::std::option::Option<&$crate::hss::Extensions>) -> $crate::hss::ServerResult<::std::vec::Vec<$crate::hss::Route>> {
844 use $crate::StaticRoute as _;
845 let _extensions_none = $crate::hss::Extensions::new ();
846 let _extensions = _extensions.unwrap_or (&_extensions_none);
847 let _routes = ::std::vec! (
848 $(
849 {
850 let _route : $_route = <$_route>::new (_extensions) ?;
851 let _route = _route.into_route ();
853 _route
854 },
855 )*
856 );
857 $crate::hss::ServerResult::Ok (_routes)
858 }
859 }
860
861 impl $crate::StaticRoutes for $_name {
862
863 fn into_routes (self) -> $crate::hss::Routes {
864 self.0
865 }
866 }
867
868 impl ::std::convert::Into<$crate::hss::Routes> for $_name {
869
870 fn into (self) -> $crate::hss::Routes {
871 use $crate::StaticRoutes as _;
872 self.into_routes ()
873 }
874 }
875
876 impl $_name {
877
878 pub fn eprintln () -> $crate::hss::ServerResult {
879 use ::std::iter::IntoIterator as _;
880 let _routes = Self::routes () ?;
881 for _route in _routes.into_iter () {
882 if let ::std::option::Option::Some (_debug) = _route.extensions.get::<$crate::StaticRouteDebug> () {
883 ::std::eprintln! ("[dd] [825798f8] ** {} -> {:?}", _route.path, _debug);
884 } else {
885 ::std::eprintln! ("[dd] [df531ca1] ** {}", _route.path);
886 }
887 }
888 $crate::hss::ServerResult::Ok (())
889 }
890 }
891 };
892}
893
894
895
896
897#[ macro_export ]
898macro_rules! dependencies {
899
900
901 ( $_name : ident, [ $( $_dependency : literal, )* ] ) => {
902
903 #[ allow (non_camel_case_types) ]
904 pub(crate) struct $_name ();
905
906 impl $_name {
907
908 pub fn dependencies () -> ::std::vec::Vec<&'static ::std::path::Path> {
909 ::std::vec! (
910 $( ::std::path::Path::new ($_dependency), )*
911 )
912 }
913 }
914
915 impl $_name {
916
917 pub fn eprintln () -> () {
918 use ::std::iter::IntoIterator as _;
919 for _dependency in Self::dependencies () .into_iter () {
920 ::std::eprintln! ("[dd] [402419e4] !! {}", _dependency.display ());
921 }
922 }
923 }
924 };
925}
926
927
928
929
930#[ macro_export ]
931macro_rules! resource_content_type {
932
933 ( text ) => { $crate::hss::ContentType::Text };
934 ( html ) => { $crate::hss::ContentType::Html };
935 ( css ) => { $crate::hss::ContentType::Css };
936 ( js ) => { $crate::hss::ContentType::Js };
937
938 ( json ) => { $crate::hss::ContentType::Json };
939 ( xml ) => { $crate::hss::ContentType::Xml };
940
941 ( png ) => { $crate::hss::ContentType::Png };
942 ( jpeg ) => { $crate::hss::ContentType::Jpeg };
943 ( svg ) => { $crate::hss::ContentType::Svg };
944 ( icon ) => { $crate::hss::ContentType::Icon };
945
946 ( font_ttf ) => { $crate::hss::ContentType::FontTtf };
947 ( font_otf ) => { $crate::hss::ContentType::FontOtf };
948 ( font_woff ) => { $crate::hss::ContentType::FontWoff };
949 ( font_woff2 ) => { $crate::hss::ContentType::FontWoff2 };
950
951 ( unknown ) => { $crate::hss::ContentType::Unknown };
952
953}
954
955
956
957
958#[ macro_export ]
959macro_rules! builder_generated {
960
961
962 () => {
963 ::std::include! (::std::concat! (::std::env! ("OUT_DIR"), "/hss-builder-generated-default.in"));
964 };
965}
966
967
968
969
970#[ macro_export ]
971macro_rules! resource_path {
972
973
974 ( ( relative_to_crate, None ) ) => {
975 ::std::option::Option::None
976 };
977 ( ( relative_to_cwd, None ) ) => {
978 ::std::option::Option::None
979 };
980 ( None ) => {
981 ::std::option::Option::None
982 };
983
984
985 ( ( relative_to_crate, Some ( $_path : literal ) ) ) => {
986 ::std::option::Option::Some ( $crate::resource_path! ( ( relative_to_crate, $_path ) ) )
987 };
988 ( ( relative_to_cwd, Some ( $_path : literal ) ) ) => {
989 ::std::option::Option::Some ( $crate::resource_path! ( ( relative_to_cwd, $_path ) ) )
990 };
991 ( Some ( $_path : literal ) ) => {
992 ::std::option::Option::Some ( $crate::resource_path! ( $_path ) )
993 };
994
995 ( ( relative_to_crate, $_path : literal ) ) => {
996 ::std::concat! (::std::env! ("CARGO_MANIFEST_DIR"), "/", $_path)
997 };
998 ( ( relative_to_cwd, $_path : literal ) ) => {
999 $_path
1000 };
1001 ( $_path : literal ) => {
1002 $crate::resource_path! ( ( relative_to_crate, $_path ) )
1003 };
1004}
1005
1006
1007
1008
1009#[ macro_export ]
1010#[ cfg (feature = "production") ]
1011macro_rules! cfg_if_production {
1012 ( { $( $_then_token : tt )* } | { $( $_else_token : tt )* } ) => { $( $_then_token )* };
1013 ( { $( $_then_token : tt )* } ) => { $( $_then_token )* };
1014}
1015
1016#[ macro_export ]
1017#[ cfg (not (feature = "production")) ]
1018macro_rules! cfg_if_production {
1019 ( { $( $_then_token : tt )* } | { $( $_else_token : tt )* } ) => { $( $_else_token )* };
1020 ( { $( $_then_token : tt )* } ) => {};
1021}
1022
1023
1024
1025
1026#[ macro_export ]
1027#[ cfg (any (not (feature = "builder-askama-dynamic"), feature = "production")) ]
1028macro_rules! cfg_builder_askama_dynamic_disabled {
1029 ( $( $_token : tt )* ) => { $( $_token )* };
1030}
1031
1032#[ macro_export ]
1033#[ cfg (all (feature = "builder-askama-dynamic", not (feature = "production"))) ]
1034macro_rules! cfg_builder_askama_dynamic_disabled {
1035 ( $( $_token : tt )* ) => {};
1036}
1037
1038
1039#[ macro_export ]
1040#[ cfg (all (feature = "builder-askama-dynamic", not (feature = "production"))) ]
1041macro_rules! cfg_builder_askama_dynamic_enabled {
1042 ( $( $_token : tt )* ) => {
1043 $( $_token )*
1044 };
1045}
1046
1047#[ macro_export ]
1048#[ cfg (any (not (feature = "builder-askama-dynamic"), feature = "production")) ]
1049macro_rules! cfg_builder_askama_dynamic_enabled {
1050 ( $( $_token : tt )* ) => {};
1051}
1052