♻️ (pagetop): Separa handle_component() en 2 métodos
`Theme::handle_component()` se divide en `setup_component()` (síncrono, muta por tipo con la macro homónima) y `render_component()` (async, decide el renderizado con su propia macro). Aplica mismo criterio que ya separa `Component::setup()` de `prepare()`.
This commit is contained in:
parent
1e2d171805
commit
28f1eee391
15 changed files with 185 additions and 170 deletions
|
|
@ -13,7 +13,7 @@ async fn setup() {
|
|||
/// Replaces the default `Template` composition (`Header` + `Content` + `Footer`) with a fixed
|
||||
/// marker string, for both `CoreTemplates::Standard` and `CoreTemplates::Admin`. Mirrors how
|
||||
/// a real theme (e.g. `pagetop-bootsier`) tells its own layout apart from PageTop's default: by
|
||||
/// intercepting the `Template` component in `handle_component()`, not by swapping which
|
||||
/// intercepting the `Template` component in `render_component()`, not by swapping which
|
||||
/// `TemplateRef` gets resolved.
|
||||
struct MarkerTheme;
|
||||
|
||||
|
|
@ -26,12 +26,12 @@ impl Extension for MarkerTheme {
|
|||
|
||||
#[async_trait]
|
||||
impl Theme for MarkerTheme {
|
||||
async fn handle_component(
|
||||
async fn render_component(
|
||||
&self,
|
||||
component: &mut dyn Component,
|
||||
component: &dyn Component,
|
||||
_cx: &mut Context,
|
||||
) -> Option<Result<Markup, ComponentError>> {
|
||||
let template = (*component).downcast_ref::<layout::Template>()?;
|
||||
let template = component.downcast_ref::<layout::Template>()?;
|
||||
template.template().downcast_ref::<CoreTemplates>()?;
|
||||
Some(Ok(html! { "marker-template-output" }))
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ impl Theme for MarkerTheme {
|
|||
// `Theme::default_template()`/`admin_template()` were removed: `Context::template()` always
|
||||
// resolves `Default`/`Admin` to the core `CoreTemplates::Standard`/`Admin` identity, regardless
|
||||
// of which theme is active. Themes customize the actual rendering by intercepting the `Template`
|
||||
// component in `handle_component()` instead (see the tests further below).
|
||||
// component in `render_component()` instead (see the tests further below).
|
||||
|
||||
#[pagetop::test]
|
||||
async fn default_template_identity_is_independent_of_theme() {
|
||||
|
|
@ -74,7 +74,7 @@ async fn explicit_template_is_not_overridden_by_a_later_with_theme() {
|
|||
assert_eq!(cx.template().name(), "admin");
|
||||
}
|
||||
|
||||
// **< A theme customizes rendering via `handle_component()` >**************************************
|
||||
// **< A theme customizes rendering via `render_component()` >**************************************
|
||||
|
||||
#[pagetop::test]
|
||||
async fn without_a_matching_theme_the_default_composition_is_used() {
|
||||
|
|
@ -89,7 +89,7 @@ async fn without_a_matching_theme_the_default_composition_is_used() {
|
|||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn theme_replaces_template_rendering_via_handle_component() {
|
||||
async fn theme_replaces_template_rendering_via_render_component() {
|
||||
setup().await;
|
||||
|
||||
let mut template = layout::Template::default();
|
||||
|
|
@ -99,7 +99,7 @@ async fn theme_replaces_template_rendering_via_handle_component() {
|
|||
assert_eq!(html, "marker-template-output");
|
||||
}
|
||||
|
||||
// **< Page::render() reaches the active theme's `handle_component()` >*****************************
|
||||
// **< Page::render() reaches the active theme's `render_component()` >*****************************
|
||||
|
||||
#[pagetop::test]
|
||||
async fn page_admin_render_reflects_the_active_theme_template() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue