shapes_converter/shex_to_html/
html_shape.rs1use serde::Serialize;
2
3use super::{Name, ShapeTemplateEntry};
4
5#[derive(Serialize, Debug, PartialEq, Clone)]
6pub struct HtmlShape {
7 name: Name,
9
10 entries: Vec<ShapeTemplateEntry>,
12
13 extends: Vec<Name>,
15
16 parent: Name,
18
19 children: Vec<Name>,
21
22 pub svg_shape: Option<String>,
24}
25
26impl HtmlShape {
27 pub fn new(name: Name, parent: Name) -> HtmlShape {
28 HtmlShape {
29 name,
30 entries: Vec::new(),
31 extends: Vec::new(),
32 parent,
33 children: Vec::new(),
34 svg_shape: None,
35 }
36 }
37
38 pub fn add_entry(&mut self, entry: ShapeTemplateEntry) {
39 self.entries.push(entry)
40 }
41
42 pub fn name(&self) -> Name {
43 self.name.clone()
44 }
45
46 pub fn entries(&self) -> impl Iterator<Item = &ShapeTemplateEntry> {
47 self.entries.iter()
48 }
49
50 pub fn add_extends(&mut self, name: &Name) {
51 self.extends.push(name.clone())
52 }
53
54 pub fn extends(&self) -> impl Iterator<Item = &Name> {
55 self.extends.iter()
56 }
57
58 pub fn merge(&mut self, other: &HtmlShape) {
59 for entry in other.entries() {
60 self.add_entry(entry.clone())
61 }
62 for extend in other.extends() {
63 self.add_extends(extend)
64 }
65 match &self.svg_shape {
66 Some(_svg) => {
67 }
69 None => self.svg_shape.clone_from(&other.svg_shape),
70 }
71 }
72
73 pub fn svg_shape(&self) -> Option<String> {
74 self.svg_shape.clone()
75 }
76
77 pub fn set_svg_shape(&mut self, str: &str) {
78 self.svg_shape = Some(str.to_string());
79 }
80}