encre_css/plugins/flexbox/order/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "flexbox")]
3use crate::prelude::build_plugin::*;
4
5#[derive(Debug)]
6pub(crate) struct PluginDefinition;
7
8impl Plugin for PluginDefinition {
9    fn can_handle(&self, context: ContextCanHandle) -> bool {
10        matches!(context.modifier, Modifier::Builtin { value, .. } if ["first", "last", "none"].contains(&&**value)
11                    || value.parse::<usize>().is_ok_and(|v| v != 0))
12    }
13
14    fn handle(&self, context: &mut ContextHandle) {
15        match context.modifier {
16            Modifier::Builtin {
17                is_negative, value, ..
18            } => match *value {
19                "first" => context.buffer.line("order: -9999;"),
20                "last" => context.buffer.line("order: 9999;"),
21                "none" => context.buffer.line("order: 0;"),
22                _ => context.buffer.line(format_args!(
23                    "order: {}{value};",
24                    format_negative(is_negative)
25                )),
26            },
27            Modifier::Arbitrary { .. } => unreachable!(),
28        }
29    }
30}