♻️ (pagetop): with_prop() acepta impl Into<PropsOp>

`FlexItem`, `Margin` y `Padding` se pasan directamente gracias a `From`
 hacia `PropsOp`, sin `PropsOp::flex_item()`/`margin()`/`padding()` ni
`.into()` explícito. Revisadas todas las llamadas en el código para
simplificarlas.
This commit is contained in:
Manuel Cillero 2026-09-13 01:38:33 +02:00
parent 50e4b42fe4
commit 3c3ffc91e6
49 changed files with 141 additions and 165 deletions

View file

@ -3,7 +3,7 @@ use pagetop::prelude::*;
#[pagetop::test]
async fn default_flex_item_adds_nothing() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(FlexItem::new()));
let props = Props::default().with_prop(FlexItem::new());
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
assert_eq!(html, "<span></span>");
@ -13,9 +13,7 @@ async fn default_flex_item_adds_nothing() {
#[pagetop::test]
async fn grow_adds_flex_grow_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_grow(flex::ItemGrow::Is1),
));
let props = Props::default().with_prop(FlexItem::new().with_grow(flex::ItemGrow::Is1));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -26,9 +24,7 @@ async fn grow_adds_flex_grow_style() {
#[pagetop::test]
async fn shrink_adds_flex_shrink_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_shrink(flex::ItemShrink::Is0),
));
let props = Props::default().with_prop(FlexItem::new().with_shrink(flex::ItemShrink::Is0));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -39,9 +35,8 @@ async fn shrink_adds_flex_shrink_style() {
#[pagetop::test]
async fn align_self_adds_matching_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_align_self(flex::ItemAlign::Center),
));
let props =
Props::default().with_prop(FlexItem::new().with_align_self(flex::ItemAlign::Center));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -52,9 +47,7 @@ async fn align_self_adds_matching_style() {
#[pagetop::test]
async fn order_adds_matching_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_order(flex::ItemOrder::First),
));
let props = Props::default().with_prop(FlexItem::new().with_order(flex::ItemOrder::First));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -65,9 +58,7 @@ async fn order_adds_matching_style() {
#[pagetop::test]
async fn size_percent_adds_flex_basis_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_size(flex::ItemSize::Percent33),
));
let props = Props::default().with_prop(FlexItem::new().with_size(flex::ItemSize::Percent33));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -78,9 +69,8 @@ async fn size_percent_adds_flex_basis_style() {
#[pagetop::test]
async fn size_custom_adds_flex_basis_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_size(flex::ItemSize::Custom(UnitValue::Zero)),
));
let props = Props::default()
.with_prop(FlexItem::new().with_size(flex::ItemSize::Custom(UnitValue::Zero)));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -91,9 +81,8 @@ async fn size_custom_adds_flex_basis_style() {
#[pagetop::test]
async fn offset_percent_adds_margin_inline_start_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_offset(flex::ItemOffset::Percent33),
));
let props =
Props::default().with_prop(FlexItem::new().with_offset(flex::ItemOffset::Percent33));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -104,9 +93,8 @@ async fn offset_percent_adds_margin_inline_start_style() {
#[pagetop::test]
async fn offset_custom_adds_margin_inline_start_style() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_offset(flex::ItemOffset::Custom(UnitValue::Px(16))),
));
let props = Props::default()
.with_prop(FlexItem::new().with_offset(flex::ItemOffset::Custom(UnitValue::Px(16))));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -117,7 +105,7 @@ async fn offset_custom_adds_margin_inline_start_style() {
#[pagetop::test]
async fn combines_several_facets_in_one_call() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
let props = Props::default().with_prop(
FlexItem::new()
.with_grow(flex::ItemGrow::Is1)
.with_shrink(flex::ItemShrink::Is0)
@ -125,7 +113,7 @@ async fn combines_several_facets_in_one_call() {
.with_order(flex::ItemOrder::Is2)
.with_size(flex::ItemSize::Custom(UnitValue::Zero))
.with_offset(flex::ItemOffset::Percent10),
));
);
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -146,9 +134,8 @@ async fn combines_several_facets_in_one_call() {
#[pagetop::test]
async fn size_at_a_breakpoint_combines_token_and_suffix() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
FlexItem::new().with_size_at(Breakpoint::Md, flex::ItemSize::Percent33),
));
let props = Props::default()
.with_prop(FlexItem::new().with_size_at(Breakpoint::Md, flex::ItemSize::Percent33));
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();
@ -163,12 +150,12 @@ async fn size_at_a_breakpoint_combines_token_and_suffix() {
#[pagetop::test]
async fn base_and_breakpoint_values_generate_one_class_each() {
let mut cx = Context::default();
let props = Props::default().with_prop(PropsOp::flex_item(
let props = Props::default().with_prop(
FlexItem::new()
.with_grow(flex::ItemGrow::Default)
.with_size(flex::ItemSize::Percent50)
.with_size_at(Breakpoint::Lg, flex::ItemSize::Percent25),
));
);
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
// `ItemGrow::Default` resolves to an empty CSS value, so it adds no class at all.
@ -180,7 +167,7 @@ async fn base_and_breakpoint_values_generate_one_class_each() {
async fn from_flex_item_for_props_op() {
let mut cx = Context::default();
let item = FlexItem::new().with_grow(flex::ItemGrow::Is1);
let props = Props::default().with_prop(item.into());
let props = Props::default().with_prop(item);
let html = html! { span (props.unpack(&mut cx)) {} }.into_string();
let assets = cx.render_assets().into_string();