windjammer_ui/components/generated/
codeeditor.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
6pub struct CodeEditor {
7    pub code: String,
8    pub language: String,
9    pub theme: String,
10    pub line_numbers: bool,
11    pub readonly: bool,
12}
13
14impl CodeEditor {
15    #[inline]
16    pub fn new(code: String) -> CodeEditor {
17        CodeEditor {
18            code,
19            language: "rust".to_string(),
20            theme: "dark".to_string(),
21            line_numbers: true,
22            readonly: false,
23        }
24    }
25    #[inline]
26    pub fn language(mut self, language: String) -> CodeEditor {
27        self.language = language;
28        self
29    }
30    #[inline]
31    pub fn theme(mut self, theme: String) -> CodeEditor {
32        self.theme = theme;
33        self
34    }
35    #[inline]
36    pub fn line_numbers(mut self, show: bool) -> CodeEditor {
37        self.line_numbers = show;
38        self
39    }
40    #[inline]
41    pub fn readonly(mut self, readonly: bool) -> CodeEditor {
42        self.readonly = readonly;
43        self
44    }
45}
46
47impl Renderable for CodeEditor {
48    #[inline]
49    fn render(self) -> String {
50        let readonly_attr = {
51            if self.readonly {
52                " readonly".to_string()
53            } else {
54                "".to_string()
55            }
56        };
57        let line_numbers_class = {
58            if self.line_numbers {
59                " wj-editor-with-lines".to_string()
60            } else {
61                "".to_string()
62            }
63        };
64        format!(
65            "<div class='wj-code-editor wj-editor-{} wj-editor-theme-{}{}'>
66  <textarea{}>
67{}</textarea>
68</div>",
69            self.language, self.theme, line_numbers_class, readonly_attr, self.code
70        )
71    }
72}