Skip to content

Commit bfe34c5

Browse files
committed
feat(docs): made perseus client-side documentable
Still need to sort out some dependency issues.
1 parent 5bb9bd3 commit bfe34c5

31 files changed

+186
-187
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Cargo.lock
33
pkg/
44
.tribble/
5-
.idea/
65

76
target_engine/
87
target_wasm/

packages/perseus/src/error_views.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use crate::{errors::*, reactor::Reactor};
33
use crate::{i18n::Translator, reactor::RenderMode, state::TemplateState};
44
use fmterr::fmt_err;
55
use serde::{Deserialize, Serialize};
6-
#[cfg(client)]
6+
#[cfg(any(client, doc))]
77
use std::sync::Arc;
88
#[cfg(engine)]
99
use sycamore::prelude::create_scope_immediate;
10-
#[cfg(client)]
10+
#[cfg(any(client, doc))]
1111
use sycamore::prelude::{create_child_scope, try_use_context, ScopeDisposer};
1212
use sycamore::{
1313
prelude::{view, Scope},
@@ -49,7 +49,7 @@ pub struct ErrorViews<G: Html> {
4949
/// This will be extracted by the `PerseusApp` creation process and put in a
5050
/// place where it can be safely extracted. The replacement function
5151
/// will panic if called, so this should **never** be manually executed.
52-
#[cfg(client)]
52+
#[cfg(any(client, doc))]
5353
panic_handler: Arc<
5454
dyn Fn(Scope, ClientError, ErrorContext, ErrorPosition) -> (View<SsrNode>, View<G>)
5555
+ Send
@@ -93,7 +93,7 @@ impl<G: Html> ErrorViews<G> {
9393
_ => false,
9494
}
9595
}),
96-
#[cfg(client)]
96+
#[cfg(any(client, doc))]
9797
panic_handler: Arc::new(handler),
9898
}
9999
}
@@ -125,7 +125,7 @@ impl<G: Html> ErrorViews<G> {
125125
/// Returns `true` if the given error, which must have occurred during a
126126
/// subsequent load, should be displayed as a popup, as opposed to
127127
/// occupying the entire page/widget.
128-
#[cfg(client)]
128+
#[cfg(any(client, doc))]
129129
pub(crate) fn subsequent_err_should_be_popup(&self, err: &ClientError) -> bool {
130130
!(self.subsequent_load_determinant)(err)
131131
}
@@ -171,7 +171,7 @@ impl<G: Html> ErrorViews<G> {
171171
})
172172
}
173173
}
174-
#[cfg(client)]
174+
#[cfg(any(client, doc))]
175175
impl<G: Html> ErrorViews<G> {
176176
/// Invokes the user's handling function, producing head/body views for the
177177
/// given error. From the given scope, this will determine the

packages/perseus/src/i18n/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// This module file is controlled, because it's used as an external module as
22
// well
33

4-
#[cfg(client)]
4+
#[cfg(any(client, doc))]
55
mod client_translations_manager;
6-
#[cfg(client)]
6+
#[cfg(any(client, doc))]
77
mod locale_detector;
88
mod locales;
99
mod translations_manager;
1010

11-
#[cfg(client)]
11+
#[cfg(any(client, doc))]
1212
pub(crate) use client_translations_manager::ClientTranslationsManager;
13-
#[cfg(client)]
13+
#[cfg(any(client, doc))]
1414
pub(crate) use locale_detector::detect_locale;
1515
pub use locales::Locales;
1616
pub use translations_manager::{

packages/perseus/src/init.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ use crate::{
1010
stores::MutableStore,
1111
template::{Entity, Forever, Template},
1212
};
13-
#[cfg(client)]
13+
#[cfg(any(client, doc))]
1414
use crate::{
1515
error_views::{ErrorContext, ErrorPosition},
1616
errors::ClientError,
1717
};
1818
use crate::{errors::PluginError, template::Capsule};
1919
use crate::{stores::ImmutableStore, template::EntityMap};
2020
use futures::Future;
21-
#[cfg(client)]
21+
#[cfg(any(client, doc))]
2222
use std::marker::PhantomData;
2323
#[cfg(engine)]
2424
use std::pin::Pin;
25-
#[cfg(client)]
25+
#[cfg(any(client, doc))]
2626
use std::rc::Rc;
2727
use std::{any::TypeId, sync::Arc};
2828
use std::{collections::HashMap, panic::PanicInfo};
@@ -160,21 +160,21 @@ pub struct PerseusAppBase<G: Html, M: MutableStore, T: TranslationsManager> {
160160
#[cfg(engine)]
161161
pub(crate) static_dir: String,
162162
/// A handler for panics on the browser-side.
163-
#[cfg(client)]
163+
#[cfg(any(client, doc))]
164164
pub(crate) panic_handler: Option<Box<dyn Fn(&PanicInfo) + Send + Sync + 'static>>,
165165
/// A duplicate of the app's error handling function intended for panic
166166
/// handling. This must be extracted as an owned value and provided in a
167167
/// thread-safe manner to the panic hook system.
168168
///
169169
/// This is in an `Arc` because panic hooks are `Fn`s, not `FnOnce`s.
170-
#[cfg(client)]
170+
#[cfg(any(client, doc))]
171171
pub(crate) panic_handler_view: Arc<
172172
dyn Fn(Scope, ClientError, ErrorContext, ErrorPosition) -> (View<SsrNode>, View<G>)
173173
+ Send
174174
+ Sync,
175175
>,
176176
// We need this on the client-side to account for the unused type parameters
177-
#[cfg(client)]
177+
#[cfg(any(client, doc))]
178178
_marker: PhantomData<(M, T)>,
179179
}
180180
impl<G: Html, M: MutableStore, T: TranslationsManager> std::fmt::Debug for PerseusAppBase<G, M, T> {
@@ -190,7 +190,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> std::fmt::Debug for Perse
190190
.field("locale", &self.locales)
191191
.field("plugins", &self.plugins)
192192
.field("index_view", &self.index_view);
193-
#[cfg(client)]
193+
#[cfg(any(client, doc))]
194194
{
195195
return debug
196196
.field(
@@ -251,7 +251,7 @@ impl<G: Html, T: TranslationsManager> PerseusAppBase<G, FsMutableStore, T> {
251251
/// This is asynchronous because it creates a translations manager in the
252252
/// background.
253253
// It makes no sense to implement `Default` on this, so we silence Clippy deliberately
254-
#[cfg(client)]
254+
#[cfg(any(client, doc))]
255255
#[allow(clippy::new_without_default)]
256256
pub fn new() -> Self {
257257
Self::new_wasm()
@@ -354,7 +354,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
354354
// By default, we won't use any plugins
355355
#[cfg(engine)]
356356
plugins: Arc::new(Plugins::new()),
357-
#[cfg(client)]
357+
#[cfg(any(client, doc))]
358358
plugins: Rc::new(Plugins::new()),
359359
#[cfg(engine)]
360360
immutable_store: ImmutableStore::new("./dist".to_string()),
@@ -366,17 +366,17 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
366366
index_view: DFLT_INDEX_VIEW.to_string(),
367367
#[cfg(engine)]
368368
static_dir: "./static".to_string(),
369-
#[cfg(client)]
369+
#[cfg(any(client, doc))]
370370
panic_handler: None,
371-
#[cfg(client)]
371+
#[cfg(any(client, doc))]
372372
panic_handler_view: ErrorViews::unlocalized_development_default().take_panic_handler(),
373-
#[cfg(client)]
373+
#[cfg(any(client, doc))]
374374
_marker: PhantomData,
375375
}
376376
}
377377
/// Internal function for Wasm initialization. This should never be called
378378
/// by the user!
379-
#[cfg(client)]
379+
#[cfg(any(client, doc))]
380380
#[doc(hidden)]
381381
fn new_wasm() -> Self {
382382
Self {
@@ -543,7 +543,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
543543
// error views.
544544
#[allow(unused_mut)]
545545
pub fn error_views(mut self, mut val: ErrorViews<G>) -> Self {
546-
#[cfg(client)]
546+
#[cfg(any(client, doc))]
547547
{
548548
let panic_handler = val.take_panic_handler();
549549
self.error_views = Some(Rc::new(val));
@@ -666,7 +666,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
666666
/// Sets the plugins that the app will use. See [`Plugins`] for
667667
/// further details.
668668
pub fn plugins(mut self, val: Plugins) -> Self {
669-
#[cfg(client)]
669+
#[cfg(any(client, doc))]
670670
{
671671
self.plugins = Rc::new(val);
672672
}
@@ -771,7 +771,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
771771
#[allow(unused_variables)]
772772
#[allow(unused_mut)]
773773
pub fn panic_handler(mut self, val: impl Fn(&PanicInfo) + Send + Sync + 'static) -> Self {
774-
#[cfg(client)]
774+
#[cfg(any(client, doc))]
775775
{
776776
self.panic_handler = Some(Box::new(val));
777777
}
@@ -908,7 +908,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
908908
// self.entities.clone()
909909
// }
910910
// /// Gets the [`ErrorViews`] used in the app. This returns an `Rc`.
911-
// #[cfg(client)]
911+
// #[cfg(any(client, doc))]
912912
// pub fn get_error_views(&self) -> Rc<ErrorViews<G>> {
913913
// self.error_views.clone()
914914
// }
@@ -978,7 +978,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
978978
// self.plugins.clone()
979979
// }
980980
// /// Gets the plugins registered for the app.
981-
// #[cfg(client)]
981+
// #[cfg(any(client, doc))]
982982
// pub fn get_plugins(&self) -> Rc<Plugins> {
983983
// self.plugins.clone()
984984
// }
@@ -1039,7 +1039,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
10391039
/// # Future panics
10401040
/// If this is called more than once, the view panic handler will panic when
10411041
/// called.
1042-
#[cfg(client)]
1042+
#[cfg(any(client, doc))]
10431043
pub fn take_panic_handlers(
10441044
&mut self,
10451045
) -> (

packages/perseus/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub mod template;
5252
/// General utilities that may be useful while building Perseus apps.
5353
pub mod utils;
5454

55-
#[cfg(all(feature = "client-helpers", client))]
55+
#[cfg(all(feature = "client-helpers", any(client, doc)))]
5656
mod client;
5757
mod init;
5858
mod page_data;
@@ -90,9 +90,9 @@ pub type Request = ();
9090
pub use perseus_macro::*;
9191

9292
// Browser-side only
93-
#[cfg(client)]
93+
#[cfg(any(client, doc))]
9494
pub use crate::utils::checkpoint;
95-
#[cfg(all(feature = "client-helpers", client))]
95+
#[cfg(all(feature = "client-helpers", any(client, doc)))]
9696
pub use client::{run_client, ClientReturn};
9797

9898
/// Internal utilities for lower-level work.
@@ -102,7 +102,7 @@ pub mod internal {
102102
}
103103
/// Internal utilities for logging. These are just re-exports so that users
104104
/// don't have to have `web_sys` and `wasm_bindgen` to use `web_log!`.
105-
#[cfg(client)]
105+
#[cfg(any(client, doc))]
106106
#[doc(hidden)]
107107
pub mod log {
108108
pub use wasm_bindgen::JsValue;

packages/perseus/src/reactor/global_state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Reactor;
2-
#[cfg(client)]
2+
#[cfg(any(client, doc))]
33
use crate::state::FrozenGlobalState;
44
use crate::{
55
errors::*,
@@ -96,7 +96,7 @@ impl<G: Html> Reactor<G> {
9696
/// Note: on the engine-side, there is no such thing as frozen state, and
9797
/// the active state will always be empty, so this will simply return
9898
/// `None`.
99-
#[cfg(client)]
99+
#[cfg(any(client, doc))]
100100
fn get_held_global_state<S>(&self) -> Result<Option<S::Rx>, ClientError>
101101
where
102102
S: MakeRx + Serialize + DeserializeOwned,
@@ -141,7 +141,7 @@ impl<G: Html> Reactor<G> {
141141
/// register anything in the state store. This may return an error on a
142142
/// downcast failure (which is probably the user's fault for providing
143143
/// the wrong type argument, but it's still an invariant failure).
144-
#[cfg(client)]
144+
#[cfg(any(client, doc))]
145145
fn get_active_global_state<S>(&self) -> Result<Option<S::Rx>, ClientError>
146146
where
147147
S: MakeRx + Serialize + DeserializeOwned,
@@ -155,7 +155,7 @@ impl<G: Html> Reactor<G> {
155155
/// the thaw preferences have already been accounted for.
156156
///
157157
/// This assumes that the app actually supports global state.
158-
#[cfg(client)]
158+
#[cfg(any(client, doc))]
159159
fn get_frozen_global_state_and_register<S>(&self) -> Result<Option<S::Rx>, ClientError>
160160
where
161161
S: MakeRx + Serialize + DeserializeOwned,

0 commit comments

Comments
 (0)