use super::cssbuf::{CssBuf, CssHead};
use super::transform::handle_parsed;
use super::Style;
use crate::file_context::FileContext;
use crate::{Error, Parsed, ScopeRef};
#[derive(Clone, Copy, Debug)]
pub struct Format {
pub style: Style,
pub precision: usize,
}
impl Format {
pub fn introspect() -> Self {
Self {
style: Style::Introspection,
..Default::default()
}
}
pub fn is_compressed(&self) -> bool {
self.style == Style::Compressed
}
pub fn is_introspection(&self) -> bool {
self.style == Style::Introspection
}
pub fn write_root(
&self,
items: Parsed,
globals: ScopeRef,
file_context: &impl FileContext,
) -> Result<Vec<u8>, Error> {
let mut head = CssHead::new();
let mut body = CssBuf::new(*self);
handle_parsed(
items,
&mut head,
None,
&mut body,
globals,
file_context,
)?;
Ok(head.combine_final(body))
}
pub fn get_indent(&self, len: usize) -> &'static str {
static INDENT: &str = "\n ";
if self.is_compressed() {
""
} else {
&INDENT[..(len + 1)]
}
}
}
impl Default for Format {
fn default() -> Format {
Format {
style: Style::Expanded,
precision: 10,
}
}
}
pub struct Formatted<'a, T> {
pub(crate) value: &'a T,
pub(crate) format: Format,
}