cercis-html 1.2.3

HTML generator tool for cercis
Documentation
use html_escape::encode_safe;
use std::borrow::Cow;

use crate::prelude::*;

#[derive(Clone)]
pub struct VContent<'a> {
    content: Cow<'a, str>,
    is_raw: Option<bool>,
}

impl<'a> VContent<'a> {
    pub fn new(content: impl Into<Cow<'a, str>>) -> Self {
        Self {
            content: content.into(),
            is_raw: None,
        }
    }

    pub fn raw(mut self, value: bool) -> Self {
        self.is_raw = Some(value);

        self
    }
}

impl Render for VContent<'_> {
    fn render(&self) -> String {
        match self.is_raw {
            Some(val) if val => self.content.to_string(),
            _ => encode_safe(&self.content).to_string(),
        }
    }
}