xcomponent 0.10.2__tar.gz → 0.10.4__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.
Files changed (91) hide show
  1. {xcomponent-0.10.2 → xcomponent-0.10.4}/CHANGELOG.md +10 -0
  2. {xcomponent-0.10.2 → xcomponent-0.10.4}/Cargo.lock +1 -1
  3. {xcomponent-0.10.2 → xcomponent-0.10.4}/Cargo.toml +1 -1
  4. {xcomponent-0.10.2 → xcomponent-0.10.4}/PKG-INFO +1 -1
  5. {xcomponent-0.10.2 → xcomponent-0.10.4}/pyproject.toml +1 -1
  6. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/ast/eval.rs +13 -0
  7. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/markup/tokens.rs +1 -1
  8. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_binary_op.py +36 -1
  9. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_import_namespace.py +68 -0
  10. {xcomponent-0.10.2 → xcomponent-0.10.4}/uv.lock +1 -1
  11. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/build-sdist.yml +0 -0
  12. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/build-wheels.yml +0 -0
  13. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/publish-doc.yml +0 -0
  14. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/publish-pypi.yml +0 -0
  15. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/release.yml +0 -0
  16. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/tests-artifacts.yml +0 -0
  17. {xcomponent-0.10.2 → xcomponent-0.10.4}/.github/workflows/tests.yml +0 -0
  18. {xcomponent-0.10.2 → xcomponent-0.10.4}/.gitignore +0 -0
  19. {xcomponent-0.10.2 → xcomponent-0.10.4}/.python-version +0 -0
  20. {xcomponent-0.10.2 → xcomponent-0.10.4}/Justfile +0 -0
  21. {xcomponent-0.10.2 → xcomponent-0.10.4}/LICENSE +0 -0
  22. {xcomponent-0.10.2 → xcomponent-0.10.4}/README.md +0 -0
  23. {xcomponent-0.10.2 → xcomponent-0.10.4}/docs/Makefile +0 -0
  24. {xcomponent-0.10.2 → xcomponent-0.10.4}/docs/source/conf.py +0 -0
  25. {xcomponent-0.10.2 → xcomponent-0.10.4}/docs/source/develop/.gitkeep +0 -0
  26. {xcomponent-0.10.2 → xcomponent-0.10.4}/docs/source/index.md +0 -0
  27. {xcomponent-0.10.2 → xcomponent-0.10.4}/docs/source/user/changelog.md +0 -0
  28. {xcomponent-0.10.2 → xcomponent-0.10.4}/docs/source/user/getting_started.md +0 -0
  29. {xcomponent-0.10.2 → xcomponent-0.10.4}/scripts/get_version.py +0 -0
  30. {xcomponent-0.10.2 → xcomponent-0.10.4}/scripts/write_changelog.py +0 -0
  31. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/__init__.py +0 -0
  32. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/adapters/__init__.py +0 -0
  33. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/adapters/babel.py +0 -0
  34. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/py.typed +0 -0
  35. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/service/__init__.py +0 -0
  36. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/service/catalog.py +0 -0
  37. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/python/xcomponent/xcore.pyi +0 -0
  38. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/catalog/catalog.rs +0 -0
  39. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/catalog/mod.rs +0 -0
  40. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/context.rs +0 -0
  41. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/ast/mod.rs +0 -0
  42. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/ast/model.rs +0 -0
  43. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/ast/parse.rs +0 -0
  44. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/grammar.pest +0 -0
  45. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/i18n.rs +0 -0
  46. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/mod.rs +0 -0
  47. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/parser.rs +0 -0
  48. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/expression/tokens.rs +0 -0
  49. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/lib.rs +0 -0
  50. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/markup/grammar.pest +0 -0
  51. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/markup/mod.rs +0 -0
  52. {xcomponent-0.10.2 → xcomponent-0.10.4}/src/rust/markup/parser.rs +0 -0
  53. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/__init__.py +0 -0
  54. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/__init__.py +0 -0
  55. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/i18n/__init__.py +0 -0
  56. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/i18n/babel.ini +0 -0
  57. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/i18n/fr.mo +0 -0
  58. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/i18n/fr.po +0 -0
  59. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/i18n/mydomain.pot +0 -0
  60. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/functionals/i18n/test_l10n.py +0 -0
  61. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/__init__.py +0 -0
  62. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/adapters/__init__.py +0 -0
  63. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/adapters/test_babel.py +0 -0
  64. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/conftest.py +0 -0
  65. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_binary_eq.py +0 -0
  66. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_binary_op_bool.py +0 -0
  67. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_default_values.py +0 -0
  68. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_field_access.py +0 -0
  69. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_for_expr.py +0 -0
  70. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_func.py +0 -0
  71. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_if_expr.py +0 -0
  72. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_let.py +0 -0
  73. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_nested.py +0 -0
  74. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_render_comment.py +0 -0
  75. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_script.py +0 -0
  76. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_str_dedent.py +0 -0
  77. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_str_method.py +0 -0
  78. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_types.py +0 -0
  79. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/expression/test_unary.py +0 -0
  80. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_core.py +0 -0
  81. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_named_component.py +0 -0
  82. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_attributes.py +0 -0
  83. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_context.py +0 -0
  84. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_globals.py +0 -0
  85. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_globals_obj.py +0 -0
  86. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_globals_obj2.py +0 -0
  87. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_nested_dict.py +0 -0
  88. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_nested_node.py +0 -0
  89. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_node.py +0 -0
  90. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_properties.py +0 -0
  91. {xcomponent-0.10.2 → xcomponent-0.10.4}/tests/unittests/test_render_script.py +0 -0
@@ -1,3 +1,13 @@
1
+ ## 0.10.4 - 2025-12-22
2
+
3
+ * Fix lazy evuation of binary operator (and and or).
4
+ before this version, right arm branch was also evaluated leading to bugs,
5
+ and requires to add nested if statement to avoid them.
6
+
7
+ ## 0.10.3 - 2025-12-21
8
+
9
+ * Do not alter default templates parameter values.
10
+
1
11
  ## 0.10.2 - 2025-12-21
2
12
 
3
13
  * Fix i18n extraction for namescape components.
@@ -595,7 +595,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
595
595
 
596
596
  [[package]]
597
597
  name = "xcore"
598
- version = "0.10.2"
598
+ version = "0.10.4"
599
599
  dependencies = [
600
600
  "env_logger",
601
601
  "html-escape",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "xcore"
3
- version = "0.10.2"
3
+ version = "0.10.4"
4
4
  authors = ["Guillaume Gauvrit <guillaume@gauvr.it>"]
5
5
  edition = "2021"
6
6
  description = "JSX-like for python using maturin/pyo3 and pest."
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xcomponent
3
- Version: 0.10.2
3
+ Version: 0.10.4
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.11
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xcomponent"
3
- version = "0.10.2"
3
+ version = "0.10.4"
4
4
  description = "An embeded component base template engine - inspired by JSX"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Guillaume Gauvrit", email = "guillaume@gauvr.it" }]
@@ -211,6 +211,19 @@ pub fn eval_ast<'py>(
211
211
 
212
212
  AST::Binary { left, op, right } => {
213
213
  let l = eval_ast(py, left, catalog, context)?;
214
+ match op {
215
+ Operator::And => {
216
+ if !l.is_truthy() {
217
+ return Ok(l);
218
+ }
219
+ }
220
+ Operator::Or => {
221
+ if l.is_truthy() {
222
+ return Ok(l);
223
+ }
224
+ }
225
+ _ => (),
226
+ }
214
227
  let r = eval_ast(py, right, catalog, context)?;
215
228
 
216
229
  match op {
@@ -361,7 +361,7 @@ impl ToHtml for XNSElement {
361
361
  let pynamespaces: &Bound<'_, PyDict> = namespaces.bind(py).downcast().unwrap();
362
362
 
363
363
  let defaults = template.getattr(py, "defaults")?;
364
- let node_attrs: &Bound<'_, PyDict> = defaults.bind(py).downcast().unwrap();
364
+ let node_attrs = defaults.bind(py).downcast().unwrap().copy().unwrap();
365
365
 
366
366
  context.push_ns(py, pynamespaces.clone())?;
367
367
  for (name, attrnode) in self.attrs() {
@@ -1,9 +1,16 @@
1
+ from dataclasses import dataclass
1
2
  from typing import Any, Literal
2
- import pytest
3
3
 
4
+ import pytest
4
5
  from xcomponent import Catalog, XNode
5
6
  from xcomponent.service.catalog import Component
6
7
 
8
+
9
+ @dataclass
10
+ class Person:
11
+ name: str
12
+
13
+
7
14
  catalog = Catalog()
8
15
 
9
16
 
@@ -12,6 +19,20 @@ def AddOp(a: int | bool | str, b: int | bool | str) -> str:
12
19
  return """<>{a + b}</>"""
13
20
 
14
21
 
22
+ @catalog.component
23
+ def HelloWorld(person: Person | None) -> str:
24
+ return """
25
+ <>Hello { if person and person.name {<>{person.name}</>} else {<>World</>} }!</>
26
+ """
27
+
28
+
29
+ @catalog.component
30
+ def LazyOr(person: Person | None, person2: Person | None) -> str:
31
+ return """
32
+ <>Hello { person and person.name or person2.name }!</>
33
+ """
34
+
35
+
15
36
  @catalog.component
16
37
  def Button(
17
38
  children: XNode,
@@ -233,3 +254,17 @@ def test_precendence_op(component: str, expected: str):
233
254
  )
234
255
  def test_priority_op(component: str, expected: str):
235
256
  assert component == expected
257
+
258
+
259
+ @pytest.mark.parametrize(
260
+ "component,expected",
261
+ [
262
+ pytest.param(HelloWorld(None), "Hello World!"),
263
+ pytest.param(HelloWorld(Person(name="")), "Hello World!"),
264
+ pytest.param(HelloWorld(Person(name="Bob")), "Hello Bob!"),
265
+ pytest.param(LazyOr(Person(name="Alice"), None), "Hello Alice!"),
266
+ pytest.param(LazyOr(None, Person(name="Bob")), "Hello Bob!"),
267
+ ],
268
+ )
269
+ def test_lazy_evaluation(component: str, expected: str):
270
+ assert component == expected
@@ -1,7 +1,15 @@
1
+ from dataclasses import dataclass
2
+ from typing import Any
3
+
1
4
  import pytest
2
5
  from xcomponent import Catalog, XNode
3
6
 
4
7
 
8
+ @dataclass
9
+ class App:
10
+ name: str
11
+
12
+
5
13
  @pytest.fixture
6
14
  def base_catalog():
7
15
  base = Catalog()
@@ -96,6 +104,40 @@ def page_catalog(
96
104
  </layout.Layout>
97
105
  """
98
106
 
107
+ @page.component(use={"layout": layout_catalog, "app": app_catalog})
108
+ def Page5(children: XNode, title: str, apps: list[App]) -> str:
109
+ return """
110
+ <layout.Layout
111
+ title={title}
112
+ side_bar={<app.Sidebar/>}
113
+ >
114
+ {
115
+ for app in globals.apps {
116
+ <p>{app.name}</p>
117
+ }
118
+ }
119
+ </layout.Layout>
120
+ """
121
+
122
+ @page.component
123
+ def P(children: XNode) -> str:
124
+ return "<p>{children}</p>"
125
+
126
+ @page.component(use={"layout": layout_catalog, "app": app_catalog})
127
+ def Page6(children: XNode, title: str, apps: list[App]) -> str:
128
+ return """
129
+ <layout.Layout
130
+ title={title}
131
+ side_bar={<app.Sidebar/>}
132
+ >
133
+ {
134
+ for app in globals.apps {
135
+ <P>{app.name}</P>
136
+ }
137
+ }
138
+ </layout.Layout>
139
+ """
140
+
99
141
  return page
100
142
 
101
143
 
@@ -131,3 +173,29 @@ def page_catalog(
131
173
  def test_namespace(page_catalog: Catalog, doc: str, expected: str):
132
174
  page = page_catalog.render(doc)
133
175
  assert page == expected
176
+
177
+
178
+ @pytest.mark.parametrize(
179
+ "doc,params,expected",
180
+ [
181
+ pytest.param(
182
+ "<Page5 title='yolo'/>",
183
+ {"globals": {"apps": [App(name="foo"), App(name="bar")]}},
184
+ '<html><head><title>yolo</title></head><body><h1 class="xl">yolo</h1>'
185
+ '<div><aside><menu><li><a href="#">Parameters</a></li></menu></aside>'
186
+ "<div><p>foo</p><p>bar</p></div></div></body></html>",
187
+ id="override-local-name",
188
+ ),
189
+ pytest.param(
190
+ "<Page6 title='yolo'/>",
191
+ {"globals": {"apps": [App(name="foo"), App(name="bar")]}},
192
+ '<html><head><title>yolo</title></head><body><h1 class="xl">yolo</h1>'
193
+ '<div><aside><menu><li><a href="#">Parameters</a></li></menu></aside>'
194
+ "<div><p>foo</p><p>bar</p></div></div></body></html>",
195
+ id="override-local-name-with-component",
196
+ ),
197
+ ],
198
+ )
199
+ def test_namespace_params(page_catalog: Catalog, doc: str, params: Any, expected: str):
200
+ page = page_catalog.render(doc, **params)
201
+ assert page == expected
@@ -1418,7 +1418,7 @@ wheels = [
1418
1418
 
1419
1419
  [[package]]
1420
1420
  name = "xcomponent"
1421
- version = "0.10.2"
1421
+ version = "0.10.4"
1422
1422
  source = { editable = "." }
1423
1423
 
1424
1424
  [package.optional-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes