encre_css/plugins/layout/aspect_ratio/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "layout")]
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, .. } => ["auto", "square", "video"].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                "auto" => context.buffer.line("aspect-ratio: auto;"),
20                "square" => context.buffer.line("aspect-ratio: 1 / 1;"),
21                "video" => context.buffer.line("aspect-ratio: 16 / 9;"),
22                _ => unreachable!(),
23            },
24            Modifier::Arbitrary { value, .. } => context
25                .buffer
26                .line(format_args!("aspect-ratio: {};", value.replace('/', " / "),)),
27        }
28    }
29}