fix test failures

This commit is contained in:
Evan Almloff 2023-08-08 11:27:29 -07:00
parent aaded7981f
commit e43bdd815f
5 changed files with 20 additions and 7 deletions

View file

@ -88,15 +88,18 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus::prelude::*;
/// # #[inline_props]
/// # fn Index(cx: Scope) -> Element { todo!() }
/// # fn Other(cx: Scope) -> Element { todo!() }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
/// Index {},
/// #[route("/other")]
/// Other {},
/// }
/// let mut history = MemoryHistory::<Route>::default();
/// assert_eq!(history.can_go_back(), false);
///
/// history.push(Route::Index {});
/// history.push(Route::Other {});
/// assert_eq!(history.can_go_back(), true);
/// ```
#[must_use]

View file

@ -34,7 +34,7 @@ use crate::utils::use_router_internal::use_router_internal;
///
/// #[inline_props]
/// fn Index(cx: Scope) -> Element {
/// let path = use_route(&cx).unwrap();
/// let path: Route = use_route(&cx).unwrap();
/// render! {
/// h2 { "Current Path" }
/// p { "{path}" }

View file

@ -162,9 +162,9 @@ pub trait Routable: std::fmt::Display + std::str::FromStr + Clone + 'static {
///
/// #[derive(Routable, Clone, PartialEq, Debug)]
/// enum Route {
/// #[route("/")]
/// #[route("/home")]
/// Home {},
/// #[route("/about")]
/// #[route("/home/about")]
/// About {},
/// }
///

View file

@ -1,6 +1,7 @@
use super::cache::Segment;
use crate::cache::StringCache;
use dioxus_core::Attribute;
use dioxus_core::{prelude::*, AttributeValue, DynamicNode, RenderReturn};
use std::collections::HashMap;
use std::fmt::Write;
@ -90,8 +91,7 @@ impl Renderer {
write_value(buf, &attr.value)?;
}
} else {
write!(buf, " {}=", attr.name)?;
write_value(buf, &attr.value)?;
write_attribute(buf, &attr)?;
}
}
Segment::Node(idx) => match &template.dynamic_nodes[*idx] {
@ -282,6 +282,17 @@ pub(crate) fn truthy(value: &AttributeValue) -> bool {
}
}
pub(crate) fn write_attribute(buf: &mut impl Write, attr: &Attribute) -> std::fmt::Result {
let name = &attr.name;
match attr.value {
AttributeValue::Text(value) => write!(buf, " {name}=\"{value}\""),
AttributeValue::Bool(value) => write!(buf, " {name}={value}"),
AttributeValue::Int(value) => write!(buf, " {name}={value}"),
AttributeValue::Float(value) => write!(buf, " {name}={value}"),
_ => Ok(()),
}
}
pub(crate) fn write_value(buf: &mut impl Write, value: &AttributeValue) -> std::fmt::Result {
match value {
AttributeValue::Text(value) => write!(buf, "\"{}\"", value),

View file

@ -21,7 +21,6 @@ fn static_boolean_attributs() {
#[test]
fn dynamic_boolean_attributs() {
fn app(cx: Scope) -> Element {
let inner_html = "<div>1234</div>";
render! {
div { hidden: false }
div { hidden: true }