xcomponent 0.8.2__tar.gz → 0.8.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 (89) hide show
  1. {xcomponent-0.8.2 → xcomponent-0.8.4}/CHANGELOG.md +8 -0
  2. {xcomponent-0.8.2 → xcomponent-0.8.4}/Cargo.lock +1 -1
  3. {xcomponent-0.8.2 → xcomponent-0.8.4}/Cargo.toml +1 -1
  4. {xcomponent-0.8.2 → xcomponent-0.8.4}/PKG-INFO +1 -1
  5. {xcomponent-0.8.2 → xcomponent-0.8.4}/pyproject.toml +1 -1
  6. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/i18n.rs +63 -3
  7. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/markup/tokens.rs +4 -4
  8. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/adapters/test_babel.py +156 -0
  9. {xcomponent-0.8.2 → xcomponent-0.8.4}/uv.lock +1 -1
  10. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/build-sdist.yml +0 -0
  11. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/build-wheels.yml +0 -0
  12. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/publish-doc.yml +0 -0
  13. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/publish-pypi.yml +0 -0
  14. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/release.yml +0 -0
  15. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/tests-artifacts.yml +0 -0
  16. {xcomponent-0.8.2 → xcomponent-0.8.4}/.github/workflows/tests.yml +0 -0
  17. {xcomponent-0.8.2 → xcomponent-0.8.4}/.gitignore +0 -0
  18. {xcomponent-0.8.2 → xcomponent-0.8.4}/.python-version +0 -0
  19. {xcomponent-0.8.2 → xcomponent-0.8.4}/Justfile +0 -0
  20. {xcomponent-0.8.2 → xcomponent-0.8.4}/LICENSE +0 -0
  21. {xcomponent-0.8.2 → xcomponent-0.8.4}/README.md +0 -0
  22. {xcomponent-0.8.2 → xcomponent-0.8.4}/docs/Makefile +0 -0
  23. {xcomponent-0.8.2 → xcomponent-0.8.4}/docs/source/conf.py +0 -0
  24. {xcomponent-0.8.2 → xcomponent-0.8.4}/docs/source/develop/.gitkeep +0 -0
  25. {xcomponent-0.8.2 → xcomponent-0.8.4}/docs/source/index.md +0 -0
  26. {xcomponent-0.8.2 → xcomponent-0.8.4}/docs/source/user/changelog.md +0 -0
  27. {xcomponent-0.8.2 → xcomponent-0.8.4}/docs/source/user/getting_started.md +0 -0
  28. {xcomponent-0.8.2 → xcomponent-0.8.4}/scripts/get_version.py +0 -0
  29. {xcomponent-0.8.2 → xcomponent-0.8.4}/scripts/write_changelog.py +0 -0
  30. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/__init__.py +0 -0
  31. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/adapters/__init__.py +0 -0
  32. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/adapters/babel.py +0 -0
  33. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/py.typed +0 -0
  34. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/service/__init__.py +0 -0
  35. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/service/catalog.py +0 -0
  36. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/python/xcomponent/xcore.pyi +0 -0
  37. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/catalog/catalog.rs +0 -0
  38. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/catalog/mod.rs +0 -0
  39. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/context.rs +0 -0
  40. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/ast/eval.rs +0 -0
  41. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/ast/mod.rs +0 -0
  42. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/ast/model.rs +0 -0
  43. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/ast/parse.rs +0 -0
  44. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/grammar.pest +0 -0
  45. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/mod.rs +0 -0
  46. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/parser.rs +0 -0
  47. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/expression/tokens.rs +0 -0
  48. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/lib.rs +0 -0
  49. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/markup/grammar.pest +0 -0
  50. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/markup/mod.rs +0 -0
  51. {xcomponent-0.8.2 → xcomponent-0.8.4}/src/rust/markup/parser.rs +0 -0
  52. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/__init__.py +0 -0
  53. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/__init__.py +0 -0
  54. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/i18n/__init__.py +0 -0
  55. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/i18n/babel.ini +0 -0
  56. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/i18n/fr.mo +0 -0
  57. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/i18n/fr.po +0 -0
  58. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/i18n/mydomain.pot +0 -0
  59. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/functionals/i18n/test_l10n.py +0 -0
  60. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/__init__.py +0 -0
  61. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/adapters/__init__.py +0 -0
  62. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/conftest.py +0 -0
  63. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_binary_eq.py +0 -0
  64. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_binary_op.py +0 -0
  65. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_binary_op_bool.py +0 -0
  66. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_default_values.py +0 -0
  67. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_field_access.py +0 -0
  68. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_for_expr.py +0 -0
  69. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_func.py +0 -0
  70. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_if_expr.py +0 -0
  71. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_let.py +0 -0
  72. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_nested.py +0 -0
  73. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_render_comment.py +0 -0
  74. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_script.py +0 -0
  75. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_str_dedent.py +0 -0
  76. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_str_method.py +0 -0
  77. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_types.py +0 -0
  78. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/expression/test_unary.py +0 -0
  79. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_core.py +0 -0
  80. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_named_component.py +0 -0
  81. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_attributes.py +0 -0
  82. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_context.py +0 -0
  83. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_globals.py +0 -0
  84. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_globals_obj.py +0 -0
  85. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_globals_obj2.py +0 -0
  86. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_nested_dict.py +0 -0
  87. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_nested_node.py +0 -0
  88. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_node.py +0 -0
  89. {xcomponent-0.8.2 → xcomponent-0.8.4}/tests/unittests/test_render_script.py +0 -0
@@ -1,3 +1,11 @@
1
+ ## 0.8.4 - 2025-10-19
2
+
3
+ * Improve more messages extraction from nested fragment.
4
+
5
+ ## 0.8.3 - 2025-10-18
6
+
7
+ * Improve more messages extraction from nested expressions.
8
+
1
9
  ## 0.8.2 - 2025-10-18
2
10
 
3
11
  * Be tolerant in case of markup or expression error while extracting locales.
@@ -595,7 +595,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
595
595
 
596
596
  [[package]]
597
597
  name = "xcore"
598
- version = "0.8.2"
598
+ version = "0.8.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.8.2"
3
+ version = "0.8.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.8.2
3
+ Version: 0.8.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.8.2"
3
+ version = "0.8.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" }]
@@ -6,6 +6,7 @@ use crate::{
6
6
  ast::{model::AST, parse::parse},
7
7
  parser::tokenize,
8
8
  },
9
+ markup::tokens::XNode,
9
10
  };
10
11
 
11
12
  #[pyclass]
@@ -93,7 +94,7 @@ impl ExtractedMessage {
93
94
  }
94
95
  }
95
96
 
96
- fn extract_from_ast(ast: AST) -> Vec<ExtractedMessage> {
97
+ fn extract_from_ast(ast: AST) -> PyResult<Vec<ExtractedMessage>> {
97
98
  let mut res = Vec::new();
98
99
  match ast {
99
100
  AST::CallAccess {
@@ -266,11 +267,70 @@ fn extract_from_ast(ast: AST) -> Vec<ExtractedMessage> {
266
267
  },
267
268
  _ => {}
268
269
  },
270
+ AST::IfStatement {
271
+ condition: _,
272
+ then_branch,
273
+ else_branch,
274
+ } => {
275
+ res.extend(extract_from_ast(*then_branch.clone())?);
276
+ if else_branch.is_some() {
277
+ res.extend(extract_from_ast(*else_branch.unwrap().clone())?);
278
+ }
279
+ }
280
+ AST::ForStatement {
281
+ ident: _,
282
+ iterable: _,
283
+ body,
284
+ } => {
285
+ res.extend(extract_from_ast(*body.clone())?);
286
+ }
287
+ AST::LetStatement { ident: _, expr } => {
288
+ res.extend(extract_from_ast(*expr.clone())?);
289
+ }
290
+ AST::Literal(Literal::XNode(XNode::Element(node))) => {
291
+ for child in node.attrs().values() {
292
+ if let XNode::Expression(expr) = child {
293
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
294
+ }
295
+ }
296
+ for child in node.children() {
297
+ if let XNode::Expression(expr) = child {
298
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
299
+ }
300
+ }
301
+ }
302
+ AST::Literal(Literal::XNode(XNode::Fragment(node))) => {
303
+ for child in node.children() {
304
+ match child {
305
+ XNode::Expression(expr) => {
306
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
307
+ }
308
+ XNode::Element(node) => {
309
+ for child in node.attrs().values() {
310
+ if let XNode::Expression(expr) = child {
311
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
312
+ }
313
+ }
314
+ for child in node.children() {
315
+ if let XNode::Expression(expr) = child {
316
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
317
+ }
318
+ }
319
+ }
320
+ _ => {
321
+ warn!("Ignoring {:?} while extracting messages", child);
322
+ }
323
+ }
324
+ }
325
+ }
326
+ AST::Literal(Literal::XNode(XNode::Expression(expr))) => {
327
+ res.extend(extract_expr_i18n_messages(expr.expression())?);
328
+ }
269
329
  _ => {
270
330
  warn!("Ignoring {:?} while extracting messages", ast);
271
331
  }
272
332
  }
273
- res
333
+ Ok(res)
274
334
  }
275
335
 
276
336
  #[pyfunction]
@@ -278,5 +338,5 @@ pub(crate) fn extract_expr_i18n_messages(raw: &str) -> PyResult<Vec<ExtractedMes
278
338
  let token = tokenize(raw)?;
279
339
  let ast = parse(&[token], 0)?;
280
340
 
281
- Ok(extract_from_ast(ast))
341
+ extract_from_ast(ast)
282
342
  }
@@ -43,7 +43,7 @@ impl XFragment {
43
43
  }
44
44
 
45
45
  #[getter]
46
- fn children(&self) -> Vec<XNode> {
46
+ pub fn children(&self) -> Vec<XNode> {
47
47
  self.children.clone()
48
48
  }
49
49
 
@@ -152,12 +152,12 @@ impl XElement {
152
152
  }
153
153
 
154
154
  #[getter]
155
- fn attrs(&self) -> HashMap<String, XNode> {
155
+ pub fn attrs(&self) -> HashMap<String, XNode> {
156
156
  self.attrs.clone()
157
157
  }
158
158
 
159
159
  #[getter]
160
- fn children(&self) -> Vec<XNode> {
160
+ pub fn children(&self) -> Vec<XNode> {
161
161
  self.children.clone()
162
162
  }
163
163
 
@@ -396,7 +396,7 @@ impl XExpression {
396
396
  }
397
397
 
398
398
  #[getter]
399
- fn expression(&self) -> &str {
399
+ pub fn expression(&self) -> &str {
400
400
  self.expression.as_str()
401
401
  }
402
402
 
@@ -223,6 +223,162 @@ empty_comment: list[str] = []
223
223
  ],
224
224
  id="dnpgettext",
225
225
  ),
226
+ pytest.param(
227
+ """
228
+ <BaseLayout>
229
+ {
230
+ if authenticated {
231
+ <A href={globals.request.route_path('sign_out')} hx-disable>
232
+ {globals.pgettext("Sign out header link", "Sign Out")}
233
+ </A>
234
+ }
235
+ }
236
+ </BaseLayout>
237
+ """,
238
+ [
239
+ (
240
+ 1,
241
+ "pgettext",
242
+ (
243
+ "Sign out header link",
244
+ "Sign Out",
245
+ ),
246
+ empty_comment,
247
+ ),
248
+ ],
249
+ id="nested if",
250
+ ),
251
+ pytest.param(
252
+ """
253
+ <BaseLayout>
254
+ {
255
+ if authenticated {
256
+ <A href={globals.request.route_path('sign_out')} hx-disable>
257
+ {globals.pgettext("Sign out header link", "Sign Out")}
258
+ </A>
259
+ }
260
+ else {
261
+ <A aria-label={globals.gettext("Sign in link")} href={globals.request.route_path('sign_in')} hx-disable>
262
+ {globals.pgettext("Sign in header link", "Sign in")}
263
+ </A>
264
+ }
265
+ }
266
+ </BaseLayout>
267
+ """,
268
+ [
269
+ (
270
+ 1,
271
+ "pgettext",
272
+ (
273
+ "Sign out header link",
274
+ "Sign Out",
275
+ ),
276
+ empty_comment,
277
+ ),
278
+ (
279
+ 1,
280
+ "gettext",
281
+ "Sign in link",
282
+ empty_comment,
283
+ ),
284
+ (
285
+ 1,
286
+ "pgettext",
287
+ (
288
+ "Sign in header link",
289
+ "Sign in",
290
+ ),
291
+ empty_comment,
292
+ ),
293
+ ],
294
+ id="nested if-else",
295
+ ),
296
+ pytest.param(
297
+ """
298
+ <BaseLayout>
299
+ {
300
+ for item in menu {
301
+ <span>{globals.gettext("item {item}",item=item)}</span>
302
+ }
303
+ }
304
+ </BaseLayout>
305
+ """,
306
+ [
307
+ (
308
+ 1,
309
+ "gettext",
310
+ "item {item}",
311
+ empty_comment,
312
+ ),
313
+ ],
314
+ id="nested for",
315
+ ),
316
+ pytest.param(
317
+ """
318
+ <BaseLayout>
319
+ {
320
+ for item in menu {
321
+ <>{globals.gettext("item {item}",item=item)}</>
322
+ }
323
+ }
324
+ </BaseLayout>
325
+ """,
326
+ [
327
+ (
328
+ 1,
329
+ "gettext",
330
+ "item {item}",
331
+ empty_comment,
332
+ ),
333
+ ],
334
+ id="nested diamond",
335
+ ),
336
+ pytest.param(
337
+ """
338
+ <BaseLayout>
339
+ {
340
+ if authenticated {
341
+ <>
342
+ {globals.username}
343
+ -
344
+ <A href={globals.request.route_path('sign_out')} hx-disable>
345
+ {globals.pgettext("Sign out header link", "Sign Out")}
346
+ </A>
347
+ </>
348
+ }
349
+ }
350
+ </BaseLayout>
351
+ """,
352
+ [
353
+ (
354
+ 1,
355
+ "pgettext",
356
+ (
357
+ "Sign out header link",
358
+ "Sign Out",
359
+ ),
360
+ empty_comment,
361
+ ),
362
+ ],
363
+ id="if nested diamond",
364
+ ),
365
+ pytest.param(
366
+ """
367
+ <BaseLayout>
368
+ { let trad = globals.gettext("here we go") }
369
+ <A href="/">{trad}</A>
370
+ </BaseLayout>
371
+ """,
372
+ [
373
+ (
374
+ 1,
375
+ "gettext",
376
+ "here we go",
377
+ empty_comment,
378
+ ),
379
+ ],
380
+ id="let",
381
+ ),
226
382
  ],
227
383
  )
228
384
  def test_extract_from_markup(markup: XNode, expected: list[ExtractionInfo]):
@@ -1407,7 +1407,7 @@ wheels = [
1407
1407
 
1408
1408
  [[package]]
1409
1409
  name = "xcomponent"
1410
- version = "0.8.2"
1410
+ version = "0.8.4"
1411
1411
  source = { editable = "." }
1412
1412
 
1413
1413
  [package.optional-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes