encre_css/plugins/grid/gap/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias("grid", "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, .. } => spacing::is_matching_builtin_spacing(value),
12            Modifier::Arbitrary { prefix, value, .. } => {
13                prefix.is_empty() && is_matching_length(value)
14            }
15        }
16    }
17
18    fn handle(&self, context: &mut ContextHandle) {
19        match context.modifier {
20            Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
21                "gap: {};",
22                spacing::get(value, *is_negative).unwrap()
23            )),
24            Modifier::Arbitrary { value, .. } => {
25                context.buffer.line(format_args!("gap: {value};"));
26            }
27        }
28    }
29}
30
31#[derive(Debug)]
32pub(crate) struct PluginXDefinition;
33
34impl Plugin for PluginXDefinition {
35    fn can_handle(&self, context: ContextCanHandle) -> bool {
36        match context.modifier {
37            Modifier::Builtin { value, .. } => spacing::is_matching_builtin_spacing(value),
38            Modifier::Arbitrary { value, .. } => is_matching_length(value),
39        }
40    }
41
42    fn handle(&self, context: &mut ContextHandle) {
43        match context.modifier {
44            Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
45                "column-gap: {};",
46                spacing::get(value, *is_negative).unwrap()
47            )),
48            Modifier::Arbitrary { value, .. } => {
49                context.buffer.line(format_args!("column-gap: {value};"));
50            }
51        }
52    }
53}
54
55#[derive(Debug)]
56pub(crate) struct PluginYDefinition;
57
58impl Plugin for PluginYDefinition {
59    fn can_handle(&self, context: ContextCanHandle) -> bool {
60        match context.modifier {
61            Modifier::Builtin { value, .. } => spacing::is_matching_builtin_spacing(value),
62            Modifier::Arbitrary { value, .. } => is_matching_length(value),
63        }
64    }
65
66    fn handle(&self, context: &mut ContextHandle) {
67        match context.modifier {
68            Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
69                "row-gap: {};",
70                spacing::get(value, *is_negative).unwrap()
71            )),
72            Modifier::Arbitrary { value, .. } => {
73                context.buffer.line(format_args!("row-gap: {value};"));
74            }
75        }
76    }
77}