xcomponent 0.8.4__tar.gz → 0.9.0__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.8.4 → xcomponent-0.9.0}/CHANGELOG.md +7 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/Cargo.lock +1 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/Cargo.toml +1 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/PKG-INFO +1 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/pyproject.toml +1 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/context.rs +14 -2
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/ast/eval.rs +1 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_binary_eq.py +4 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_types.py +31 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_node.py +41 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/uv.lock +1 -1
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/build-sdist.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/build-wheels.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/publish-doc.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/publish-pypi.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/release.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/tests-artifacts.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.github/workflows/tests.yml +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.gitignore +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/.python-version +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/Justfile +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/LICENSE +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/README.md +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/docs/Makefile +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/docs/source/conf.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/docs/source/develop/.gitkeep +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/docs/source/index.md +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/docs/source/user/changelog.md +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/docs/source/user/getting_started.md +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/scripts/get_version.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/scripts/write_changelog.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/adapters/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/adapters/babel.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/py.typed +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/service/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/service/catalog.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/python/xcomponent/xcore.pyi +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/catalog/catalog.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/catalog/mod.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/ast/mod.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/ast/model.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/ast/parse.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/grammar.pest +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/i18n.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/mod.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/parser.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/expression/tokens.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/lib.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/markup/grammar.pest +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/markup/mod.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/markup/parser.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/src/rust/markup/tokens.rs +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/i18n/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/i18n/babel.ini +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/i18n/fr.mo +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/i18n/fr.po +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/i18n/mydomain.pot +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/functionals/i18n/test_l10n.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/adapters/__init__.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/adapters/test_babel.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/conftest.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_binary_op.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_binary_op_bool.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_default_values.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_field_access.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_for_expr.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_func.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_if_expr.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_let.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_nested.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_render_comment.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_script.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_str_dedent.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_str_method.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/expression/test_unary.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_core.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_named_component.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_attributes.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_context.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_globals.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_globals_obj.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_globals_obj2.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_nested_dict.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_nested_node.py +0 -0
- {xcomponent-0.8.4 → xcomponent-0.9.0}/tests/unittests/test_render_script.py +0 -0
|
@@ -151,7 +151,12 @@ impl Literal {
|
|
|
151
151
|
.unbind()
|
|
152
152
|
.into_bound_py_any(py)
|
|
153
153
|
.unwrap(),
|
|
154
|
-
Literal::Uuid(v) =>
|
|
154
|
+
Literal::Uuid(v) => {
|
|
155
|
+
let uuidmod = PyModule::import(py, "uuid").unwrap();
|
|
156
|
+
let uuid_class = uuidmod.getattr("UUID").unwrap();
|
|
157
|
+
let args = (PyString::new(py, v.as_str()),);
|
|
158
|
+
uuid_class.call1(args).unwrap()
|
|
159
|
+
}
|
|
155
160
|
Literal::Int(v) => v.clone().into_pyobject(py).unwrap().into_any(),
|
|
156
161
|
Literal::Str(v) => v.clone().into_pyobject(py).unwrap().into_any(),
|
|
157
162
|
Literal::XNode(v) => v.clone().into_pyobject(py).unwrap().into_any(),
|
|
@@ -220,7 +225,14 @@ impl ToHtml for Literal {
|
|
|
220
225
|
Literal::Int(i) => Ok(format!("{}", i)),
|
|
221
226
|
Literal::Str(s) => Ok(format!("{}", s)),
|
|
222
227
|
Literal::Callable(s) => Ok(format!("{}()", s)),
|
|
223
|
-
Literal::Uuid(uuid) => Ok(format!(
|
|
228
|
+
Literal::Uuid(uuid) => Ok(format!(
|
|
229
|
+
"{}-{}-{}-{}-{}",
|
|
230
|
+
&uuid[0..8],
|
|
231
|
+
&uuid[8..12],
|
|
232
|
+
&uuid[12..16],
|
|
233
|
+
&uuid[16..20],
|
|
234
|
+
&uuid[20..32]
|
|
235
|
+
)),
|
|
224
236
|
Literal::List(l) => {
|
|
225
237
|
let mut out = String::new();
|
|
226
238
|
for item in l {
|
|
@@ -123,6 +123,7 @@ fn eval_raw_eq(l: Literal, r: Literal, op: String) -> PyResult<bool> {
|
|
|
123
123
|
(Literal::Bool(a), Literal::Int(b)) => Ok(a as isize == b),
|
|
124
124
|
(Literal::Bool(a), Literal::Bool(b)) => Ok(a == b),
|
|
125
125
|
(Literal::Str(a), Literal::Str(b)) => Ok(a == b),
|
|
126
|
+
(Literal::Uuid(a), Literal::Uuid(b)) => Ok(a == b),
|
|
126
127
|
(Literal::None(()), Literal::None(())) => Ok(true),
|
|
127
128
|
(Literal::None(()), _) => Ok(false),
|
|
128
129
|
(_, Literal::None(())) => Ok(false),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import pytest
|
|
2
|
+
from uuid import UUID
|
|
2
3
|
|
|
3
4
|
from xcomponent import Catalog
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ catalog = Catalog()
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
@catalog.component
|
|
9
|
-
def Eq(a: int | bool | str, b: int | bool | str) -> str:
|
|
10
|
+
def Eq(a: int | bool | str, b: int | bool | str | UUID) -> str:
|
|
10
11
|
return """<>{a == b}</>"""
|
|
11
12
|
|
|
12
13
|
|
|
@@ -50,6 +51,8 @@ def Lte(a: int | bool | str, b: int | bool | str) -> str:
|
|
|
50
51
|
pytest.param(Eq(True, True), "true", id="add true-true"),
|
|
51
52
|
pytest.param(Eq("1", "2"), "false", id="str-false"),
|
|
52
53
|
pytest.param(Eq("1", "1"), "true", id="str-true"),
|
|
54
|
+
pytest.param(Eq(UUID(int=1), UUID(int=1)), "true", id="uuid-true"),
|
|
55
|
+
pytest.param(Eq(UUID(int=1), UUID(int=2)), "false", id="uuid-false"),
|
|
53
56
|
pytest.param(Eq("", None), "false", id="str-None"),
|
|
54
57
|
pytest.param(Eq(None, None), "true", id="None-None"),
|
|
55
58
|
],
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
1
2
|
from typing import TypedDict
|
|
2
3
|
from uuid import UUID
|
|
3
4
|
from xcomponent import Catalog
|
|
@@ -43,6 +44,23 @@ def DynamicKeyDictComplexType(
|
|
|
43
44
|
return """<>{products[product_id].owner.username}</>"""
|
|
44
45
|
|
|
45
46
|
|
|
47
|
+
@dataclass
|
|
48
|
+
class UserModel:
|
|
49
|
+
username: str
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class ProductModel:
|
|
54
|
+
user_id: UUID
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@catalog.component
|
|
58
|
+
def DynamicKeyDictComplexType2(
|
|
59
|
+
users: dict[UUID, UserModel], product: ProductModel
|
|
60
|
+
) -> str:
|
|
61
|
+
return """<>{users[product.user_id].username}</>"""
|
|
62
|
+
|
|
63
|
+
|
|
46
64
|
@catalog.component
|
|
47
65
|
def DynamicKeyListComplexType(users: list[User], user_id: int) -> str:
|
|
48
66
|
return """<>{users[user_id].username}</>"""
|
|
@@ -53,7 +71,7 @@ def DynamicKeyListComplexType(users: list[User], user_id: int) -> str:
|
|
|
53
71
|
[
|
|
54
72
|
pytest.param(
|
|
55
73
|
Types(False, True, 2, "3", UUID(int=4), DummyNode(a="5")),
|
|
56
|
-
"false-true-2-3-
|
|
74
|
+
"false-true-2-3-00000000-0000-0000-0000-000000000004-<p>5</p>",
|
|
57
75
|
id="simpletypes",
|
|
58
76
|
),
|
|
59
77
|
pytest.param(
|
|
@@ -114,6 +132,18 @@ def DynamicKeyListComplexType(users: list[User], user_id: int) -> str:
|
|
|
114
132
|
"bernard",
|
|
115
133
|
id="key-dict-int",
|
|
116
134
|
),
|
|
135
|
+
pytest.param(
|
|
136
|
+
DynamicKeyDictComplexType2(
|
|
137
|
+
users={
|
|
138
|
+
UUID(int=1): User(username="alice"),
|
|
139
|
+
UUID(int=2): User(username="bob"),
|
|
140
|
+
UUID(int=3): User(username="bernard"),
|
|
141
|
+
},
|
|
142
|
+
product=ProductModel(user_id=UUID(int=3)),
|
|
143
|
+
),
|
|
144
|
+
"bernard",
|
|
145
|
+
id="nested-attribute-with-dataclass",
|
|
146
|
+
),
|
|
117
147
|
],
|
|
118
148
|
)
|
|
119
149
|
def test_types(component: str, expected: str):
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
from
|
|
1
|
+
from uuid import UUID
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
4
|
from bs4 import PageElement # type: ignore
|
|
5
|
+
from xcomponent import Catalog, Component, XNode
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
@pytest.fixture(autouse=True)
|
|
@@ -31,6 +32,20 @@ def Section(catalog: Catalog):
|
|
|
31
32
|
return Section
|
|
32
33
|
|
|
33
34
|
|
|
35
|
+
@pytest.fixture(autouse=True)
|
|
36
|
+
def Paragraph(catalog: Catalog):
|
|
37
|
+
@catalog.component
|
|
38
|
+
def Paragraph() -> str:
|
|
39
|
+
return """
|
|
40
|
+
<>
|
|
41
|
+
<p>The lazy <strong>dog</strong> jump over...</p>
|
|
42
|
+
<p>the lazy dog jumped over the <em>quick brown fox</em>.</p>
|
|
43
|
+
</>
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
return Paragraph
|
|
47
|
+
|
|
48
|
+
|
|
34
49
|
@pytest.fixture(autouse=True)
|
|
35
50
|
def HtmlHead(catalog: Catalog):
|
|
36
51
|
@catalog.component
|
|
@@ -80,6 +95,17 @@ def Layout(catalog: Catalog):
|
|
|
80
95
|
return Layout
|
|
81
96
|
|
|
82
97
|
|
|
98
|
+
@pytest.fixture(autouse=True)
|
|
99
|
+
def RenderUuid(catalog: Catalog):
|
|
100
|
+
@catalog.component
|
|
101
|
+
def RenderUuid(uuid: UUID) -> str:
|
|
102
|
+
return """
|
|
103
|
+
<input value={uuid}/>
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
return RenderUuid
|
|
107
|
+
|
|
108
|
+
|
|
83
109
|
def test_render_h1(catalog: Catalog):
|
|
84
110
|
assert catalog.render('<H1 title="Hello, world!" />') == "<h1>Hello, world!</h1>"
|
|
85
111
|
|
|
@@ -94,12 +120,26 @@ def test_render_h2(catalog: Catalog):
|
|
|
94
120
|
)
|
|
95
121
|
|
|
96
122
|
|
|
123
|
+
def test_render_uuid(catalog: Catalog):
|
|
124
|
+
assert (
|
|
125
|
+
catalog.render("<RenderUuid uuid={val} />", val=UUID(int=1))
|
|
126
|
+
== '<input value="00000000-0000-0000-0000-000000000001"/>'
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
97
130
|
def test_render_children(catalog: Catalog):
|
|
98
131
|
assert (
|
|
99
132
|
catalog.render("<Section />") == "<div><h1>hello</h1><h2>I - world</h2></div>"
|
|
100
133
|
)
|
|
101
134
|
|
|
102
135
|
|
|
136
|
+
def test_render_whitespace(catalog: Catalog):
|
|
137
|
+
assert catalog.render("<Paragraph />") == (
|
|
138
|
+
"<p>The lazy <strong>dog</strong> jump over...</p>"
|
|
139
|
+
"<p>the lazy dog jumped over the <em>quick brown fox</em>.</p>"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
103
143
|
def test_render_children_param(catalog: Catalog, Layout: Component):
|
|
104
144
|
# ensure we cam remder the HtmlHead before continuing
|
|
105
145
|
assert catalog.render('<HtmlHead title="happy world" />') == (
|
|
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
|
|
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
|