stawege-html-plugin 0.1.2

HTML template engine plugin for Stawege.
Documentation
use crate::{AttributeParseState, Attributes};

#[derive(Debug)]
pub struct AttributeBuilder {
    pub key: String,
    pub value: String,
    pub state: AttributeParseState,
}

impl AttributeBuilder {
    pub fn new() -> AttributeBuilder {
        Self::default()
    }

    pub fn is_in_quote(&self) -> bool {
        matches!(self.state, AttributeParseState::QuotedValue(..))
    }

    pub fn pop_attribute_to(&mut self, attributes: &mut Attributes) -> &mut AttributeBuilder {
        if !self.key.is_empty() {
            attributes.push(&self.key, &self.value);
        }
        self.key.clear();
        self.value.clear();
        self.state = AttributeParseState::Key;
        self
    }

    pub fn push_char_to_key(&mut self, char: char) -> &mut AttributeBuilder {
        self.key.push(char);
        self
    }

    pub fn push_char_to_value(&mut self, char: char) -> &mut AttributeBuilder {
        self.value.push(char);
        self
    }

    pub fn key_state(&mut self) -> &mut AttributeBuilder {
        self.state = AttributeParseState::Key;
        self
    }

    pub fn assign_state(&mut self) -> &mut AttributeBuilder {
        self.state = AttributeParseState::Assign;
        self
    }

    pub fn value_state(&mut self) -> &mut AttributeBuilder {
        self.state = AttributeParseState::Value;
        self
    }

    pub fn quoted_value_state(&mut self, quote: char) -> &mut AttributeBuilder {
        self.state = AttributeParseState::QuotedValue(quote);
        self
    }
}

// ----------------------------
// Default trait implementation
// ----------------------------

impl Default for AttributeBuilder {
    fn default() -> Self {
        Self {
            key: String::new(),
            value: String::new(),
            state: AttributeParseState::Key,
        }
    }
}