93
93
}
94
94
}
95
95
96
- /// The options for constructing a Perseus app. These encompass all the
97
- /// information Perseus needs to know to create your app. Every Perseus app
98
- /// using the engine must export one of these.
99
- ///
100
- /// Note that this is an interim storage point, it's not depended on by any part
101
- /// of the core logic, and therefore custom engines can entirely ignore this.
96
+ /// The options for constructing a Perseus app. This `struct` will tie
97
+ /// together all your code, declaring to Perseus where your templates,
98
+ /// error pages, static content, etc. are.
102
99
#[ derive( Debug ) ]
103
100
pub struct PerseusAppBase < G : Html , M : MutableStore , T : TranslationsManager > {
104
101
/// The HTML ID of the root `<div>` element into which Perseus will be
@@ -157,8 +154,8 @@ pub struct PerseusAppBase<G: Html, M: MutableStore, T: TranslationsManager> {
157
154
// because things are completely generic there
158
155
impl < G : Html , T : TranslationsManager > PerseusAppBase < G , FsMutableStore , T > {
159
156
/// Creates a new instance of a Perseus app using the default
160
- /// filesystem-based mutable store. For most apps, this will be sufficient.
161
- /// Note that this initializes the translations manager as a dummy, and
157
+ /// filesystem-based mutable store (see [`FsMutableStore`]) . For most apps, this will be sufficient.
158
+ /// Note that this initializes the translations manager as a dummy (see [`FsTranslationsManager`]) , and
162
159
/// adds no templates or error pages.
163
160
///
164
161
/// In development, you can get away with defining no error pages, but
@@ -174,8 +171,8 @@ impl<G: Html, T: TranslationsManager> PerseusAppBase<G, FsMutableStore, T> {
174
171
Self :: new_with_mutable_store ( FsMutableStore :: new ( "./dist/mutable" . to_string ( ) ) )
175
172
}
176
173
/// Creates a new instance of a Perseus app using the default
177
- /// filesystem-based mutable store. For most apps, this will be sufficient.
178
- /// Note that this initializes the translations manager as a dummy, and
174
+ /// filesystem-based mutable store (see [`FsMutableStore`]) . For most apps, this will be sufficient.
175
+ /// Note that this initializes the translations manager as a dummy (see [`FsTranslationsManager`]) , and
179
176
/// adds no templates or error pages.
180
177
///
181
178
/// In development, you can get away with defining no error pages, but
@@ -195,8 +192,8 @@ impl<G: Html, T: TranslationsManager> PerseusAppBase<G, FsMutableStore, T> {
195
192
// automatically for them
196
193
impl < G : Html , M : MutableStore > PerseusAppBase < G , M , FsTranslationsManager > {
197
194
/// The same as `.locales_and_translations_manager()`, but this accepts a
198
- /// literal `Locales` `struct`, which means this can be used when you're
199
- /// using `FsTranslationsManager` but when you don't know if your app is
195
+ /// literal [ `Locales`] `struct`, which means this can be used when you're
196
+ /// using [ `FsTranslationsManager`] but when you don't know if your app is
200
197
/// using i18n or not (almost always middleware).
201
198
pub fn locales_lit_and_translations_manager ( mut self , locales : Locales ) -> Self {
202
199
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -233,7 +230,7 @@ impl<G: Html, M: MutableStore> PerseusAppBase<G, M, FsTranslationsManager> {
233
230
self
234
231
}
235
232
/// Sets the internationalization information for an app using the default
236
- /// translations manager (`FsTranslationsManager`). This handles locale
233
+ /// translations manager ([ `FsTranslationsManager`] ). This handles locale
237
234
/// caching and the like automatically for you, though you could
238
235
/// alternatively use `.locales()` and `.translations_manager()`
239
236
/// independently to customize various behaviors. This takes the same
@@ -260,7 +257,8 @@ impl<G: Html, M: MutableStore> PerseusAppBase<G, M, FsTranslationsManager> {
260
257
// manager
261
258
impl < G : Html , M : MutableStore , T : TranslationsManager > PerseusAppBase < G , M , T > {
262
259
/// Creates a new instance of a Perseus app, with the default options and a
263
- /// custom mutable store.
260
+ /// customizable [`MutableStore`], using the default dummy [`FsTranslationsManager`]
261
+ /// by default (though this can be changed).
264
262
#[ allow( unused_variables) ]
265
263
pub fn new_with_mutable_store ( mutable_store : M ) -> Self {
266
264
Self {
@@ -302,6 +300,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
302
300
/// Internal function for Wasm initialization. This should never be called
303
301
/// by the user!
304
302
#[ cfg( target_arch = "wasm32" ) ]
303
+ #[ doc( hidden) ]
305
304
fn new_wasm ( ) -> Self {
306
305
Self {
307
306
root : "root" . to_string ( ) ,
@@ -328,12 +327,18 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
328
327
329
328
// Setters (these all consume `self`)
330
329
/// Sets the HTML ID of the `<div>` element at which to insert Perseus.
330
+ /// In your index view, this should use [`PerseusRoot`].
331
+ ///
332
+ /// *Note:* if you're using string HTML, the `<div>` with this ID MUST look
333
+ /// *exactly* like this: `<div id="some-id-here"></div>`, spacing and
334
+ /// all!
331
335
pub fn root ( mut self , val : & str ) -> Self {
332
336
self . root = val. to_string ( ) ;
333
337
self
334
338
}
335
339
/// Sets the location of the directory storing static assets to be hosted
336
- /// under the URL `/.perseus/static/`.
340
+ /// under the URL `/.perseus/static/`. By default, this is `static/` at
341
+ /// the root of your project.
337
342
#[ allow( unused_variables) ]
338
343
#[ allow( unused_mut) ]
339
344
pub fn static_dir ( mut self , val : & str ) -> Self {
@@ -345,22 +350,27 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
345
350
}
346
351
/// Sets all the app's templates. This takes a vector of boxed functions
347
352
/// that return templates.
353
+ ///
354
+ /// Usually, it's preferred to run `.template()` once for each template,
355
+ /// rather than manually constructing this more inconvenient type.
348
356
pub fn templates ( mut self , val : Vec < Box < dyn Fn ( ) -> Template < G > > > ) -> Self {
349
357
self . template_getters . 0 = val;
350
358
self
351
359
}
352
360
/// Adds a single new template to the app (convenience function). This takes
353
- /// a function that returns a template.
361
+ /// a *function that returns a template* (for internal reasons).
362
+ ///
363
+ /// See [`Template`] for further details.
354
364
pub fn template ( mut self , val : impl Fn ( ) -> Template < G > + ' static ) -> Self {
355
365
self . template_getters . 0 . push ( Box :: new ( val) ) ;
356
366
self
357
367
}
358
- /// Sets the app's error pages.
368
+ /// Sets the app's error pages. See [`ErrorPages`] for further details.
359
369
pub fn error_pages ( mut self , val : impl Fn ( ) -> ErrorPages < G > + ' static ) -> Self {
360
370
self . error_pages = ErrorPagesGetter ( Box :: new ( val) ) ;
361
371
self
362
372
}
363
- /// Sets the app's global state creator .
373
+ /// Sets the app's [`GlobalStateCreator`] .
364
374
#[ allow( unused_variables) ]
365
375
#[ allow( unused_mut) ]
366
376
pub fn global_state_creator ( mut self , val : GlobalStateCreator ) -> Self {
@@ -376,7 +386,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
376
386
/// supported.
377
387
///
378
388
/// Note that this does not update the translations manager, which must be
379
- /// done separately (if you're using `FsTranslationsManager`, the default,
389
+ /// done separately (if you're using [ `FsTranslationsManager`] , the default,
380
390
/// you can use `.locales_and_translations_manager()` to set both at
381
391
/// once).
382
392
///
@@ -393,23 +403,23 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
393
403
} ;
394
404
self
395
405
}
396
- /// Sets the locales information directly based on an instance of `Locales`.
406
+ /// Sets the locales information directly based on an instance of [ `Locales`] .
397
407
/// Usually, end users will use `.locales()` instead for a friendlier
398
408
/// interface.
399
409
pub fn locales_lit ( mut self , val : Locales ) -> Self {
400
410
self . locales = val;
401
411
self
402
412
}
403
413
/// Sets the translations manager. If you're using the default translations
404
- /// manager (`FsTranslationsManager`), you can use
414
+ /// manager ([ `FsTranslationsManager`] ), you can use
405
415
/// `.locales_and_translations_manager()` to set this automatically
406
416
/// based on the locales information. This takes a `Future<Output = T>`,
407
417
/// where `T` is your translations manager's type.
408
418
///
409
419
/// The reason that this takes a `Future` is to avoid the use of `.await` in
410
420
/// your app definition code, which must be synchronous due to constraints
411
- /// of Perseus' client -side systems. When your code is run on the
412
- /// server, the `Future` will be `.await`ed on, but on Wasm, it will be
421
+ /// of Perseus' browser -side systems. When your code is run on the
422
+ /// server, the `Future` will be `.await`ed on, but in Wasm, it will be
413
423
/// discarded and ignored, since the translations manager isn't needed in
414
424
/// Wasm.
415
425
///
@@ -444,7 +454,8 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
444
454
}
445
455
/// Sets all the app's static aliases. This takes a map of URLs (e.g.
446
456
/// `/file`) to resource paths, relative to the project directory (e.g.
447
- /// `style.css`).
457
+ /// `style.css`). Generally, calling `.static_alias()` many times is
458
+ /// preferred.
448
459
#[ allow( unused_variables) ]
449
460
#[ allow( unused_mut) ]
450
461
pub fn static_aliases ( mut self , val : HashMap < String , String > ) -> Self {
@@ -454,8 +465,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
454
465
}
455
466
self
456
467
}
457
- /// Adds a single static alias (convenience function). This takes a URL path
458
- /// (e.g. `/file`) followed by a path to a resource (which must be within
468
+ /// Adds a single static alias. This takes a URL path (e.g. `/file`) followed by a path to a resource (which must be within
459
469
/// the project directory, e.g. `style.css`).
460
470
#[ allow( unused_variables) ]
461
471
#[ allow( unused_mut) ]
@@ -466,12 +476,13 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
466
476
. insert ( url. to_string ( ) , resource. to_string ( ) ) ;
467
477
self
468
478
}
469
- /// Sets the plugins that the app will use.
479
+ /// Sets the plugins that the app will use. See [`Plugins`] for
480
+ /// further details.
470
481
pub fn plugins ( mut self , val : Plugins < G > ) -> Self {
471
482
self . plugins = Rc :: new ( val) ;
472
483
self
473
484
}
474
- /// Sets the mutable store for the app to use, which you would change for
485
+ /// Sets the [`MutableStore`] for the app to use, which you would change for
475
486
/// some production server environments if you wanted to store build
476
487
/// artifacts that can change at runtime in a place other than on the
477
488
/// filesystem (created for serverless functions specifically).
@@ -484,7 +495,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
484
495
}
485
496
self
486
497
}
487
- /// Sets the immutable store for the app to use. You should almost never
498
+ /// Sets the [`ImmutableStore`] for the app to use. You should almost never
488
499
/// need to change this unless you're not working with the CLI.
489
500
#[ allow( unused_variables) ]
490
501
#[ allow( unused_mut) ]
@@ -550,7 +561,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
550
561
/// this into `::get_html_shell()` to do that).
551
562
///
552
563
/// Note that this automatically adds `<!DOCTYPE html>` to the start of the
553
- /// HTMl shell produced, which can only be overriden with a control plugin
564
+ /// HTML shell produced, which can only be overriden with a control plugin
554
565
/// (though you should really never do this in Perseus, which targets
555
566
/// HTML on the web).
556
567
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -715,7 +726,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
715
726
716
727
map
717
728
}
718
- /// Gets the error pages used in the app. This returns an `Rc`.
729
+ /// Gets the [`ErrorPages`] used in the app. This returns an `Rc`.
719
730
pub fn get_error_pages ( & self ) -> ErrorPages < G > {
720
731
let mut error_pages = ( self . error_pages . 0 ) ( ) ;
721
732
let extra_error_pages = self
@@ -732,7 +743,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
732
743
733
744
error_pages
734
745
}
735
- /// Gets the global state creator . This can't be directly modified by
746
+ /// Gets the [`GlobalStateCreator`] . This can't be directly modified by
736
747
/// plugins because of reactive type complexities.
737
748
#[ cfg( not( target_arch = "wasm32" ) ) ]
738
749
pub fn get_global_state_creator ( & self ) -> Arc < GlobalStateCreator > {
@@ -748,7 +759,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
748
759
. run ( locales. clone ( ) , self . plugins . get_plugin_data ( ) )
749
760
. unwrap_or ( locales)
750
761
}
751
- /// Gets the server-side translations manager . Like the mutable store, this
762
+ /// Gets the server-side [`TranslationsManager`] . Like the mutable store, this
752
763
/// can't be modified by plugins due to trait complexities.
753
764
///
754
765
/// This involves evaluating the future stored for the translations manager,
@@ -760,7 +771,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
760
771
Tm :: Full ( tm) => tm. await ,
761
772
}
762
773
}
763
- /// Gets the immutable store .
774
+ /// Gets the [`ImmutableStore`] .
764
775
#[ cfg( not( target_arch = "wasm32" ) ) ]
765
776
pub fn get_immutable_store ( & self ) -> ImmutableStore {
766
777
let immutable_store = self . immutable_store . clone ( ) ;
@@ -771,7 +782,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
771
782
. run ( immutable_store. clone ( ) , self . plugins . get_plugin_data ( ) )
772
783
. unwrap_or ( immutable_store)
773
784
}
774
- /// Gets the mutable store . This can't be modified by plugins due to trait
785
+ /// Gets the [`MutableStore`] . This can't be modified by plugins due to trait
775
786
/// complexities, so plugins should instead expose a function that the user
776
787
/// can use to manually set it.
777
788
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -838,7 +849,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
838
849
}
839
850
840
851
/// The component that represents the entrypoint at which Perseus will inject
841
- /// itself. You can use this with the `.index_view()` method of `PerseusApp` to
852
+ /// itself. You can use this with the `.index_view()` method of [`PerseusAppBase`] to
842
853
/// avoid having to create the entrypoint `<div>` manually.
843
854
#[ component]
844
855
#[ allow( non_snake_case) ]
@@ -852,13 +863,13 @@ use crate::i18n::FsTranslationsManager;
852
863
use crate :: stores:: FsMutableStore ;
853
864
854
865
/// An alias for the usual kind of Perseus app, which uses the filesystem-based
855
- /// mutable store and translations manager.
866
+ /// mutable store and translations manager. See [`PerseusAppBase`] for details.
856
867
pub type PerseusApp < G > = PerseusAppBase < G , FsMutableStore , FsTranslationsManager > ;
857
- /// An alias for a Perseus app that uses a custom mutable store type.
868
+ /// An alias for a Perseus app that uses a custom mutable store type. See [`PerseusAppBase`] for details.
858
869
pub type PerseusAppWithMutableStore < G , M > = PerseusAppBase < G , M , FsTranslationsManager > ;
859
- /// An alias for a Perseus app that uses a custom translations manager type.
870
+ /// An alias for a Perseus app that uses a custom translations manager type. See [`PerseusAppBase`] for details.
860
871
pub type PerseusAppWithTranslationsManager < G , T > = PerseusAppBase < G , FsMutableStore , T > ;
861
872
/// An alias for a fully customizable Perseus app that can accept a custom
862
873
/// mutable store and a custom translations manager. Alternatively, you could
863
- /// just use `PerseusAppBase` directly.
874
+ /// just use [ `PerseusAppBase`] directly.
864
875
pub type PerseusAppWithMutableStoreAndTranslationsManager < G , M , T > = PerseusAppBase < G , M , T > ;
0 commit comments