encre_css/plugins/flexbox/flex/
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        match context.modifier {
11            Modifier::Builtin { value, .. } => ["1", "auto", "initial", "none"].contains(value),
12            Modifier::Arbitrary { value, .. } => is_matching_all(value),
13        }
14    }
15
16    fn handle(&self, context: &mut ContextHandle) {
17        match context.modifier {
18            Modifier::Builtin { value, .. } => match *value {
19                "1" => context.buffer.line("flex: 1 1 0%;"),
20                "auto" => context.buffer.line("flex: 1 1 auto;"),
21                "initial" => context.buffer.line("flex: 0 1 auto;"),
22                "none" => context.buffer.line("flex: none;"),
23                _ => unreachable!(),
24            },
25            Modifier::Arbitrary { value, .. } => {
26                context.buffer.line(format_args!("flex: {value};"));
27            }
28        }
29    }
30}