cercis_html/
content.rs

1use html_escape::encode_safe;
2use std::borrow::Cow;
3
4use crate::prelude::*;
5
6#[derive(Clone)]
7pub struct VContent<'a> {
8    content: Cow<'a, str>,
9    is_raw: Option<bool>,
10}
11
12impl<'a> VContent<'a> {
13    pub fn new(content: impl Into<Cow<'a, str>>) -> Self {
14        Self {
15            content: content.into(),
16            is_raw: None,
17        }
18    }
19
20    pub fn raw(mut self, value: bool) -> Self {
21        self.is_raw = Some(value);
22
23        self
24    }
25}
26
27impl Render for VContent<'_> {
28    fn render(&self) -> String {
29        match self.is_raw {
30            Some(val) if val => self.content.to_string(),
31            _ => encode_safe(&self.content).to_string(),
32        }
33    }
34}