encre_css/plugins/table/border_spacing/
mod.rs1#![doc = include_str!("README.md")]
2#![doc(alias = "table")]
3use crate::prelude::build_plugin::*;
4
5fn border_spacing_can_handle(context: &ContextCanHandle) -> bool {
6 match context.modifier {
7 Modifier::Builtin { value, .. } => spacing::is_matching_builtin_spacing(value),
8 Modifier::Arbitrary { value, prefix, .. } => prefix.is_empty() && is_matching_length(value),
9 }
10}
11
12fn border_spacing_handle(css_props: &[&str], context: &mut ContextHandle) {
13 match context.modifier {
14 Modifier::Builtin { is_negative, value } => {
15 for css_prop in css_props {
16 context.buffer.line(format_args!(
17 "{}: {};",
18 css_prop,
19 spacing::get(value, *is_negative).unwrap(),
20 ));
21 }
22 }
23 Modifier::Arbitrary { value, .. } => {
24 for css_prop in css_props {
25 context.buffer.line(format_args!("{css_prop}: {value};"));
26 }
27 }
28 }
29
30 context
31 .buffer
32 .line("border-spacing: var(--en-border-spacing-x) var(--en-border-spacing-y);");
33}
34
35#[derive(Debug)]
36pub(crate) struct PluginDefinition;
37
38impl Plugin for PluginDefinition {
39 fn can_handle(&self, context: ContextCanHandle) -> bool {
40 border_spacing_can_handle(&context)
41 }
42
43 fn handle(&self, context: &mut ContextHandle) {
44 border_spacing_handle(&["--en-border-spacing-x", "--en-border-spacing-y"], context);
45 }
46}
47
48#[derive(Debug)]
49pub(crate) struct PluginXDefinition;
50
51impl Plugin for PluginXDefinition {
52 fn can_handle(&self, context: ContextCanHandle) -> bool {
53 border_spacing_can_handle(&context)
54 }
55
56 fn handle(&self, context: &mut ContextHandle) {
57 border_spacing_handle(&["--en-border-spacing-x"], context);
58 }
59}
60
61#[derive(Debug)]
62pub(crate) struct PluginYDefinition;
63
64impl Plugin for PluginYDefinition {
65 fn can_handle(&self, context: ContextCanHandle) -> bool {
66 border_spacing_can_handle(&context)
67 }
68
69 fn handle(&self, context: &mut ContextHandle) {
70 border_spacing_handle(&["--en-border-spacing-y"], context);
71 }
72}