xcomponent 0.6.4__tar.gz → 0.6.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xcomponent-0.6.4 → xcomponent-0.6.6}/CHANGELOG.md +9 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/Cargo.lock +1 -1
- {xcomponent-0.6.4 → xcomponent-0.6.6}/Cargo.toml +1 -1
- {xcomponent-0.6.4 → xcomponent-0.6.6}/PKG-INFO +1 -1
- {xcomponent-0.6.4 → xcomponent-0.6.6}/pyproject.toml +1 -1
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/python/xcomponent/xcore.pyi +12 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/ast/eval.rs +33 -24
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/parser.rs +4 -3
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/markup/parser.rs +24 -10
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/markup/tokens.rs +80 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_binary_eq.py +6 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_binary_op.py +12 -4
- xcomponent-0.6.6/tests/unittests/expression/test_script.py +37 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/uv.lock +1 -1
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/build-sdist.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/build-wheels.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/publish-doc.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/publish-pypi.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/release.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/tests-artifacts.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.github/workflows/tests.yml +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.gitignore +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/.python-version +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/Justfile +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/LICENSE +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/README.md +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/docs/Makefile +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/docs/source/conf.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/docs/source/develop/.gitkeep +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/docs/source/index.md +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/docs/source/user/changelog.md +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/docs/source/user/getting_started.md +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/scripts/get_version.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/scripts/write_changelog.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/python/xcomponent/__init__.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/python/xcomponent/py.typed +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/python/xcomponent/service/__init__.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/python/xcomponent/service/catalog.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/catalog/catalog.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/catalog/mod.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/context.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/ast/mod.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/ast/model.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/ast/parse.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/grammar.pest +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/mod.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/expression/tokens.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/lib.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/markup/grammar.pest +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/src/rust/markup/mod.rs +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/__init__.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/__init__.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/conftest.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_binary_op_bool.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_default_values.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_field_access.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_for_expr.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_func.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_if_expr.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_let.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_nested.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_render_comment.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_str_method.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_types.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/expression/test_unary.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_core.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_named_component.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_attributes.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_context.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_globals.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_globals_obj.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_globals_obj2.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_nested_dict.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_nested_node.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_node.py +0 -0
- {xcomponent-0.6.4 → xcomponent-0.6.6}/tests/unittests/test_render_script.py +0 -0
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## 0.6.6 - 2025-09-12
|
|
2
|
+
|
|
3
|
+
* Add support of None for == operator.
|
|
4
|
+
* Improve error message for binary operators.
|
|
5
|
+
|
|
6
|
+
## 0.6.5 - 2025-09-09
|
|
7
|
+
|
|
8
|
+
* Fix string quote that are wrongly evaluated and eaten by the parser.
|
|
9
|
+
|
|
1
10
|
## 0.6.4 - 2025-09-01
|
|
2
11
|
|
|
3
12
|
* Fix expression that starts with a string
|
|
@@ -6,6 +6,7 @@ from collections.abc import Mapping, Callable
|
|
|
6
6
|
|
|
7
7
|
class NodeType(Enum):
|
|
8
8
|
Element = "Element"
|
|
9
|
+
ScriptElement = "ScriptElement"
|
|
9
10
|
Comment = "Comment"
|
|
10
11
|
Text = "Text"
|
|
11
12
|
Expression = "Expression"
|
|
@@ -28,6 +29,15 @@ class XElement:
|
|
|
28
29
|
self, name: str, attrs: dict[str, XNode], children: list[XNode]
|
|
29
30
|
) -> None: ...
|
|
30
31
|
|
|
32
|
+
class XScriptElement:
|
|
33
|
+
name: str
|
|
34
|
+
attrs: dict[str, XNode]
|
|
35
|
+
body: str
|
|
36
|
+
|
|
37
|
+
__match_args__ = ("name", "attrs", "body")
|
|
38
|
+
|
|
39
|
+
def __init__(self, name: str, attrs: dict[str, XNode], body: str) -> None: ...
|
|
40
|
+
|
|
31
41
|
class XText:
|
|
32
42
|
text: str
|
|
33
43
|
|
|
@@ -56,6 +66,8 @@ class XNode:
|
|
|
56
66
|
@staticmethod
|
|
57
67
|
def Element(element: XElement, /) -> XNode: ...
|
|
58
68
|
@staticmethod
|
|
69
|
+
def ScriptElement(element: XScriptElement, /) -> XNode: ...
|
|
70
|
+
@staticmethod
|
|
59
71
|
def Comment(text: XComment) -> XNode: ...
|
|
60
72
|
@staticmethod
|
|
61
73
|
def Text(text: XText) -> XNode: ...
|
|
@@ -22,9 +22,10 @@ fn eval_add(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
|
22
22
|
(Literal::Bool(a), Literal::Int(b)) => Ok(Literal::Int(a as isize + b)),
|
|
23
23
|
(Literal::Bool(a), Literal::Bool(b)) => Ok(Literal::Int(a as isize + b as isize)),
|
|
24
24
|
(Literal::Str(a), Literal::Str(b)) => Ok(Literal::Str(a + &b)),
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
25
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
26
|
+
"Cannot add {:?} + {:?}, type mismatch",
|
|
27
|
+
a, b
|
|
28
|
+
))),
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -34,9 +35,10 @@ fn eval_sub(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
|
34
35
|
(Literal::Int(a), Literal::Bool(b)) => Ok(Literal::Int(a - b as isize)),
|
|
35
36
|
(Literal::Bool(a), Literal::Int(b)) => Ok(Literal::Int(a as isize - b)),
|
|
36
37
|
(Literal::Bool(a), Literal::Bool(b)) => Ok(Literal::Int(a as isize - b as isize)),
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
38
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
39
|
+
"Cannot substract {:?} - {:?}, type mismatch",
|
|
40
|
+
a, b
|
|
41
|
+
))),
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -52,9 +54,10 @@ fn eval_mul(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
|
52
54
|
"".to_string()
|
|
53
55
|
})),
|
|
54
56
|
(Literal::Str(a), Literal::Bool(b)) => Ok(Literal::Str(a.repeat(b as usize))),
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
57
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
58
|
+
"Cannot multiply {:?} * {:?}, type mismatch",
|
|
59
|
+
a, b
|
|
60
|
+
))),
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
@@ -88,9 +91,10 @@ fn eval_div(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
|
88
91
|
Ok(Literal::Int(a as isize / b as isize))
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
95
|
+
"Cannot divide {:?} / {:?}, type mismatch",
|
|
96
|
+
a, b
|
|
97
|
+
))),
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
|
|
@@ -112,25 +116,28 @@ fn eval_or(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
|
|
115
|
-
fn eval_raw_eq(l: Literal, r: Literal) -> PyResult<bool> {
|
|
119
|
+
fn eval_raw_eq(l: Literal, r: Literal, op: String) -> PyResult<bool> {
|
|
116
120
|
match (l, r) {
|
|
117
121
|
(Literal::Int(a), Literal::Int(b)) => Ok(a == b),
|
|
118
122
|
(Literal::Int(a), Literal::Bool(b)) => Ok(a == b as isize),
|
|
119
123
|
(Literal::Bool(a), Literal::Int(b)) => Ok(a as isize == b),
|
|
120
124
|
(Literal::Bool(a), Literal::Bool(b)) => Ok(a == b),
|
|
121
125
|
(Literal::Str(a), Literal::Str(b)) => Ok(a == b),
|
|
122
|
-
_ =>
|
|
123
|
-
|
|
124
|
-
)
|
|
126
|
+
(Literal::None(()), _) => Ok(false),
|
|
127
|
+
(_, Literal::None(())) => Ok(false),
|
|
128
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
129
|
+
"Cannot compare {:?} {} {:?}, type mismatch",
|
|
130
|
+
a, op, b
|
|
131
|
+
))),
|
|
125
132
|
}
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
fn eval_eq(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
129
|
-
return eval_raw_eq(l, r).map(|b| Literal::Bool(b));
|
|
136
|
+
return eval_raw_eq(l, r, "==".to_string()).map(|b| Literal::Bool(b));
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
fn eval_neq(l: Literal, r: Literal) -> PyResult<Literal> {
|
|
133
|
-
return eval_raw_eq(l, r).map(|b| Literal::Bool(!b));
|
|
140
|
+
return eval_raw_eq(l, r, "!=".to_string()).map(|b| Literal::Bool(!b));
|
|
134
141
|
}
|
|
135
142
|
|
|
136
143
|
fn eval_raw_gt(l: Literal, r: Literal) -> PyResult<bool> {
|
|
@@ -140,9 +147,10 @@ fn eval_raw_gt(l: Literal, r: Literal) -> PyResult<bool> {
|
|
|
140
147
|
(Literal::Bool(a), Literal::Int(b)) => Ok(a as isize > b),
|
|
141
148
|
(Literal::Bool(a), Literal::Bool(b)) => Ok(a > b),
|
|
142
149
|
(Literal::Str(a), Literal::Str(b)) => Ok(a > b),
|
|
143
|
-
|
|
144
|
-
"
|
|
145
|
-
|
|
150
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
151
|
+
"Cannot compare {:?} > {:?}, type mismatch",
|
|
152
|
+
a, b
|
|
153
|
+
))),
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
156
|
|
|
@@ -153,9 +161,10 @@ fn eval_raw_lt(l: Literal, r: Literal) -> PyResult<bool> {
|
|
|
153
161
|
(Literal::Bool(a), Literal::Int(b)) => Ok((a as isize) < b),
|
|
154
162
|
(Literal::Bool(a), Literal::Bool(b)) => Ok(a < b),
|
|
155
163
|
(Literal::Str(a), Literal::Str(b)) => Ok(a < b),
|
|
156
|
-
|
|
157
|
-
"
|
|
158
|
-
|
|
164
|
+
(a, b) => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
165
|
+
"Cannot compare {:?} < {:?}, type mismatch",
|
|
166
|
+
a, b
|
|
167
|
+
))),
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
170
|
|
|
@@ -144,9 +144,10 @@ fn parse_expression_token(pair: Pair<Rule>) -> Result<ExpressionToken, String> {
|
|
|
144
144
|
Ok(ExpressionToken::Boolean(value))
|
|
145
145
|
}
|
|
146
146
|
Rule::string => {
|
|
147
|
-
let value = pair.as_str()
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
let value = pair.as_str();
|
|
148
|
+
let vstr = value[1..value.len() - 1].to_string();
|
|
149
|
+
debug!("Pushing string {}", vstr);
|
|
150
|
+
Ok(ExpressionToken::String(vstr))
|
|
150
151
|
}
|
|
151
152
|
Rule::component => {
|
|
152
153
|
debug!("Pushing component");
|
|
@@ -7,7 +7,9 @@ use pest::iterators::{Pair, Pairs};
|
|
|
7
7
|
use pest::Parser;
|
|
8
8
|
use pest_derive::Parser;
|
|
9
9
|
|
|
10
|
-
use crate::markup::tokens::{
|
|
10
|
+
use crate::markup::tokens::{
|
|
11
|
+
XComment, XDocType, XElement, XExpression, XFragment, XNode, XScriptElement, XText,
|
|
12
|
+
};
|
|
11
13
|
|
|
12
14
|
#[derive(Parser)]
|
|
13
15
|
#[grammar = "rust/markup/grammar.pest"]
|
|
@@ -32,16 +34,28 @@ fn parse_node(pair: Pair<Rule>) -> Option<XNode> {
|
|
|
32
34
|
let open_tag = inner.next().unwrap();
|
|
33
35
|
let (name, attrs) = parse_open_tag(open_tag);
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
match name.as_str() {
|
|
38
|
+
"script" | "style" => {
|
|
39
|
+
let body = inner.as_str();
|
|
40
|
+
Some(XNode::ScriptElement(XScriptElement::new(
|
|
41
|
+
name,
|
|
42
|
+
attrs,
|
|
43
|
+
body.to_string(),
|
|
44
|
+
)))
|
|
45
|
+
}
|
|
46
|
+
_ => {
|
|
47
|
+
let mut children = parse_nodes(inner);
|
|
48
|
+
// we make the distinctions between self closing element
|
|
49
|
+
// and normal element from the user input, we must ensure that
|
|
50
|
+
// the normal element are still rendered as normal element since
|
|
51
|
+
// it is a user choice.
|
|
52
|
+
if children.len() == 0 {
|
|
53
|
+
children.push(XNode::Text(XText::new("".to_string())));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Some(XNode::Element(XElement::new(name, attrs, children)))
|
|
57
|
+
}
|
|
42
58
|
}
|
|
43
|
-
|
|
44
|
-
Some(XNode::Element(XElement::new(name, attrs, children)))
|
|
45
59
|
}
|
|
46
60
|
Rule::fragment => {
|
|
47
61
|
debug!("Pushing fragment");
|
|
@@ -22,6 +22,7 @@ pub trait ToHtml {
|
|
|
22
22
|
pub enum NodeType {
|
|
23
23
|
DocType,
|
|
24
24
|
Fragment,
|
|
25
|
+
ScriptElement,
|
|
25
26
|
Element,
|
|
26
27
|
Expression,
|
|
27
28
|
Text,
|
|
@@ -67,6 +68,65 @@ impl ToHtml for XFragment {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
#[pyclass(eq)]
|
|
72
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
73
|
+
pub struct XScriptElement {
|
|
74
|
+
name: String,
|
|
75
|
+
attrs: HashMap<String, XNode>,
|
|
76
|
+
body: String,
|
|
77
|
+
}
|
|
78
|
+
#[pymethods]
|
|
79
|
+
impl XScriptElement {
|
|
80
|
+
#[new]
|
|
81
|
+
pub fn new(name: String, attrs: HashMap<String, XNode>, body: String) -> Self {
|
|
82
|
+
XScriptElement { name, attrs, body }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#[getter]
|
|
86
|
+
fn name(&self) -> &str {
|
|
87
|
+
self.name.as_str()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[getter]
|
|
91
|
+
fn attrs(&self) -> HashMap<String, XNode> {
|
|
92
|
+
self.attrs.clone()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[getter]
|
|
96
|
+
fn body(&self) -> &str {
|
|
97
|
+
self.body.as_str()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[classattr]
|
|
101
|
+
fn __match_args__() -> (&'static str, &'static str, &'static str) {
|
|
102
|
+
("name", "attrs", "body")
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
impl ToHtml for XScriptElement {
|
|
107
|
+
fn to_html<'py>(
|
|
108
|
+
&self,
|
|
109
|
+
_py: Python<'py>,
|
|
110
|
+
_catalog: &XCatalog,
|
|
111
|
+
_context: &mut RenderContext,
|
|
112
|
+
) -> PyResult<String> {
|
|
113
|
+
let mut result = String::new();
|
|
114
|
+
|
|
115
|
+
let joined_attrs = self
|
|
116
|
+
.attrs()
|
|
117
|
+
.iter()
|
|
118
|
+
.map(|(k, v)| format!(" {}=\"{}\"", k, v.__repr__()))
|
|
119
|
+
.collect::<String>();
|
|
120
|
+
|
|
121
|
+
result.push_str(format!("<{}{}>", self.name(), joined_attrs).as_str());
|
|
122
|
+
result.push_str(format!("{}", self.body()).as_str());
|
|
123
|
+
// The body ends wigh the closing tag, we don't need to add it.
|
|
124
|
+
// result.push_str(format!("</{}>", self.name()).as_str());
|
|
125
|
+
|
|
126
|
+
Ok(result)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
70
130
|
#[pyclass(eq)]
|
|
71
131
|
#[derive(Debug, Clone, PartialEq)]
|
|
72
132
|
pub struct XElement {
|
|
@@ -373,6 +433,7 @@ impl ToHtml for XExpression {
|
|
|
373
433
|
#[derive(Debug, Clone, PartialEq)]
|
|
374
434
|
pub enum XNode {
|
|
375
435
|
Fragment(XFragment),
|
|
436
|
+
ScriptElement(XScriptElement),
|
|
376
437
|
Element(XElement),
|
|
377
438
|
DocType(XDocType),
|
|
378
439
|
Text(XText),
|
|
@@ -403,6 +464,17 @@ impl std::fmt::Display for XNode {
|
|
|
403
464
|
write!(f, "</{}>", name)
|
|
404
465
|
}
|
|
405
466
|
}
|
|
467
|
+
XNode::ScriptElement(XScriptElement { name, attrs, body }) => {
|
|
468
|
+
let joined_attrs = attrs
|
|
469
|
+
.iter()
|
|
470
|
+
.map(|(k, v)| format!(" {}=\"{}\"", k, v.__repr__()))
|
|
471
|
+
.collect::<String>();
|
|
472
|
+
|
|
473
|
+
write!(f, "<{}{}>", name, joined_attrs)?;
|
|
474
|
+
write!(f, "{}", body)?;
|
|
475
|
+
write!(f, "</{}>", name)
|
|
476
|
+
}
|
|
477
|
+
|
|
406
478
|
XNode::Fragment(XFragment { children }) => {
|
|
407
479
|
write!(
|
|
408
480
|
f,
|
|
@@ -424,6 +496,7 @@ impl XNode {
|
|
|
424
496
|
fn kind(&self) -> NodeType {
|
|
425
497
|
match self {
|
|
426
498
|
XNode::Fragment(_) => NodeType::Fragment,
|
|
499
|
+
XNode::ScriptElement(_) => NodeType::ScriptElement,
|
|
427
500
|
XNode::Element(_) => NodeType::Element,
|
|
428
501
|
XNode::DocType(_) => NodeType::DocType,
|
|
429
502
|
XNode::Text(_) => NodeType::Text,
|
|
@@ -448,6 +521,12 @@ impl XNode {
|
|
|
448
521
|
.unwrap()
|
|
449
522
|
.into_any()
|
|
450
523
|
.unbind(),
|
|
524
|
+
XNode::ScriptElement(element) => element
|
|
525
|
+
.clone()
|
|
526
|
+
.into_pyobject(py)
|
|
527
|
+
.unwrap()
|
|
528
|
+
.into_any()
|
|
529
|
+
.unbind(),
|
|
451
530
|
XNode::Element(element) => element
|
|
452
531
|
.clone()
|
|
453
532
|
.into_pyobject(py)
|
|
@@ -500,6 +579,7 @@ impl ToHtml for XNode {
|
|
|
500
579
|
match self {
|
|
501
580
|
XNode::Fragment(f) => f.to_html(py, catalog, context),
|
|
502
581
|
XNode::Element(e) => e.to_html(py, catalog, context),
|
|
582
|
+
XNode::ScriptElement(e) => e.to_html(py, catalog, context),
|
|
503
583
|
XNode::DocType(d) => d.to_html(py, catalog, context),
|
|
504
584
|
XNode::Text(t) => t.to_html(py, catalog, context),
|
|
505
585
|
XNode::Comment(c) => c.to_html(py, catalog, context),
|
|
@@ -40,14 +40,17 @@ def Lte(a: int | bool | str, b: int | bool | str) -> str:
|
|
|
40
40
|
[
|
|
41
41
|
pytest.param(Eq(4, 2), "false", id="int-false"),
|
|
42
42
|
pytest.param(Eq(5, 5), "true", id="int-true"),
|
|
43
|
+
pytest.param(Eq(4, None), "false", id="int-None"),
|
|
43
44
|
pytest.param(Eq(True, 2), "false", id="bool and int-false"),
|
|
44
45
|
pytest.param(Eq(True, 1), "true", id="bool and int-true"),
|
|
45
46
|
pytest.param(Eq(False, 0), "true", id="bool and int-true"),
|
|
47
|
+
pytest.param(Eq(False, None), "false", id="bool-None"),
|
|
46
48
|
pytest.param(Eq(True, False), "false", id="true-false"),
|
|
47
49
|
pytest.param(Eq(False, False), "true", id="false-false"),
|
|
48
50
|
pytest.param(Eq(True, True), "true", id="add true-true"),
|
|
49
51
|
pytest.param(Eq("1", "2"), "false", id="str-false"),
|
|
50
52
|
pytest.param(Eq("1", "1"), "true", id="str-true"),
|
|
53
|
+
pytest.param(Eq("", None), "false", id="str-None"),
|
|
51
54
|
],
|
|
52
55
|
)
|
|
53
56
|
def test_eq(component: str, expected: str):
|
|
@@ -59,14 +62,17 @@ def test_eq(component: str, expected: str):
|
|
|
59
62
|
[
|
|
60
63
|
pytest.param(Neq(4, 2), "true", id="int-true"),
|
|
61
64
|
pytest.param(Neq(5, 5), "false", id="int-false"),
|
|
65
|
+
pytest.param(Neq(5, None), "true", id="int-None"),
|
|
62
66
|
pytest.param(Neq(True, 2), "true", id="bool and int-true"),
|
|
63
67
|
pytest.param(Neq(True, 1), "false", id="bool and int-false"),
|
|
68
|
+
pytest.param(Neq(True, None), "true", id="bool-None"),
|
|
64
69
|
pytest.param(Neq(False, 0), "false", id="bool and int-false"),
|
|
65
70
|
pytest.param(Neq(True, False), "true", id="true-false is true"),
|
|
66
71
|
pytest.param(Neq(False, False), "false", id="false-false is false"),
|
|
67
72
|
pytest.param(Neq(True, True), "false", id="add true-true is true"),
|
|
68
73
|
pytest.param(Neq("1", "2"), "true", id="str-true"),
|
|
69
74
|
pytest.param(Neq("1", "1"), "false", id="str-false"),
|
|
75
|
+
pytest.param(Neq("1", None), "true", id="str-None"),
|
|
70
76
|
],
|
|
71
77
|
)
|
|
72
78
|
def test_neq(component: str, expected: str):
|
|
@@ -95,7 +95,6 @@ def test_add(component: str, expected: str):
|
|
|
95
95
|
assert component == expected
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
|
|
99
98
|
@pytest.mark.parametrize(
|
|
100
99
|
"component,expected",
|
|
101
100
|
[
|
|
@@ -106,7 +105,6 @@ def test_add(component: str, expected: str):
|
|
|
106
105
|
pytest.param(AddOp(False, False), "0", id="add false-false"),
|
|
107
106
|
pytest.param(AddOp(True, True), "2", id="add true-true"),
|
|
108
107
|
pytest.param(AddOp("1", "2"), "12", id="concat str"),
|
|
109
|
-
|
|
110
108
|
],
|
|
111
109
|
)
|
|
112
110
|
def test_add_attr(component: str, expected: str):
|
|
@@ -164,8 +162,18 @@ def test_div(component: str, expected: str):
|
|
|
164
162
|
@pytest.mark.parametrize(
|
|
165
163
|
"component,args,expected",
|
|
166
164
|
[
|
|
167
|
-
pytest.param(
|
|
168
|
-
|
|
165
|
+
pytest.param(
|
|
166
|
+
AddOp,
|
|
167
|
+
(4, "2"),
|
|
168
|
+
'Cannot add Int(4) + Str("2"), type mismatch',
|
|
169
|
+
id="add int-str",
|
|
170
|
+
),
|
|
171
|
+
pytest.param(
|
|
172
|
+
SubOp,
|
|
173
|
+
("1", "2"),
|
|
174
|
+
'Cannot substract Str("1") - Str("2"), type mismatch',
|
|
175
|
+
id="sub str",
|
|
176
|
+
),
|
|
169
177
|
],
|
|
170
178
|
)
|
|
171
179
|
def test_type_error(component: Component, args: Any, expected: str):
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from xcomponent import Catalog
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.fixture(autouse=True)
|
|
7
|
+
def components(catalog: Catalog):
|
|
8
|
+
@catalog.component
|
|
9
|
+
def ScriptInside() -> str:
|
|
10
|
+
return """<><script>function onBtnClick(){alert('clicked');}</script>\
|
|
11
|
+
<div onclick="onBtnClick" /></>"""
|
|
12
|
+
|
|
13
|
+
@catalog.component
|
|
14
|
+
def StyleInside() -> str:
|
|
15
|
+
return """<style>body {background-color: olive;}</style>"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.parametrize(
|
|
19
|
+
"template_string,expected",
|
|
20
|
+
[
|
|
21
|
+
pytest.param(
|
|
22
|
+
"<ScriptInside />",
|
|
23
|
+
"""<script>function onBtnClick(){alert('clicked');}"""
|
|
24
|
+
"""</script><div onclick="onBtnClick"/>""",
|
|
25
|
+
id="script",
|
|
26
|
+
),
|
|
27
|
+
pytest.param(
|
|
28
|
+
"<StyleInside />",
|
|
29
|
+
"<style>body {background-color: olive;}</style>",
|
|
30
|
+
id="style",
|
|
31
|
+
),
|
|
32
|
+
],
|
|
33
|
+
)
|
|
34
|
+
def test_script_is_not_interpreted(
|
|
35
|
+
catalog: Catalog, template_string: str, expected: str
|
|
36
|
+
):
|
|
37
|
+
assert catalog.render(template_string) == expected
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|