gtk_ui_builder/ast/entries/
property.rs

1use crate::ast::entry::Entry;
2use crate::ast::entries::object::Object;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum PropertyValue {
6    Text(String),
7    Entry(Object)
8}
9
10impl PropertyValue {
11    pub fn dbg(&self) -> String {
12        match self {
13            PropertyValue::Text(text) => text.clone(),
14            PropertyValue::Entry(entry) => entry.dbg()
15        }
16    }
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct Property {
21    pub name: String,
22    pub value: PropertyValue
23}
24
25impl Property {
26    pub fn entry(name: String, value: PropertyValue) -> Entry {
27        Entry::Property(Self { name, value })
28    }
29
30    /// Get pretty string description of this entry
31    pub fn dbg(&self) -> String {
32        format!(
33            "Property {{\n  name: {},\n  value: {}\n}}",
34            self.name,
35            self.value.dbg().lines().map(|line| String::from("  ") + line + "\n").collect::<String>().trim()
36        )
37    }
38
39    /// Get XML description of this entry
40    pub fn get_xml(&self) -> String {
41        format!("<property name=\"{}\">{}</property>", self.name, {
42            match &self.value {
43                PropertyValue::Text(text) => text.clone(),
44                PropertyValue::Entry(entry) => entry.get_xml()
45            }
46        })
47    }
48}