xcomponent 0.6.9__tar.gz → 0.7.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.
Files changed (77) hide show
  1. {xcomponent-0.6.9 → xcomponent-0.7.0}/CHANGELOG.md +9 -1
  2. {xcomponent-0.6.9 → xcomponent-0.7.0}/Cargo.lock +1 -1
  3. {xcomponent-0.6.9 → xcomponent-0.7.0}/Cargo.toml +1 -1
  4. {xcomponent-0.6.9 → xcomponent-0.7.0}/PKG-INFO +1 -1
  5. {xcomponent-0.6.9 → xcomponent-0.7.0}/pyproject.toml +1 -1
  6. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/service/catalog.py +4 -1
  7. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/context.rs +7 -13
  8. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/grammar.pest +6 -1
  9. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/parser.rs +33 -1
  10. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_if_expr.py +4 -1
  11. xcomponent-0.7.0/tests/unittests/expression/test_str_dedent.py +114 -0
  12. {xcomponent-0.6.9 → xcomponent-0.7.0}/uv.lock +1 -1
  13. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/build-sdist.yml +0 -0
  14. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/build-wheels.yml +0 -0
  15. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/publish-doc.yml +0 -0
  16. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/publish-pypi.yml +0 -0
  17. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/release.yml +0 -0
  18. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/tests-artifacts.yml +0 -0
  19. {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/tests.yml +0 -0
  20. {xcomponent-0.6.9 → xcomponent-0.7.0}/.gitignore +0 -0
  21. {xcomponent-0.6.9 → xcomponent-0.7.0}/.python-version +0 -0
  22. {xcomponent-0.6.9 → xcomponent-0.7.0}/Justfile +0 -0
  23. {xcomponent-0.6.9 → xcomponent-0.7.0}/LICENSE +0 -0
  24. {xcomponent-0.6.9 → xcomponent-0.7.0}/README.md +0 -0
  25. {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/Makefile +0 -0
  26. {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/conf.py +0 -0
  27. {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/develop/.gitkeep +0 -0
  28. {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/index.md +0 -0
  29. {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/user/changelog.md +0 -0
  30. {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/user/getting_started.md +0 -0
  31. {xcomponent-0.6.9 → xcomponent-0.7.0}/scripts/get_version.py +0 -0
  32. {xcomponent-0.6.9 → xcomponent-0.7.0}/scripts/write_changelog.py +0 -0
  33. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/__init__.py +0 -0
  34. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/py.typed +0 -0
  35. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/service/__init__.py +0 -0
  36. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/xcore.pyi +0 -0
  37. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/catalog/catalog.rs +0 -0
  38. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/catalog/mod.rs +0 -0
  39. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/eval.rs +0 -0
  40. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/mod.rs +0 -0
  41. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/model.rs +0 -0
  42. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/parse.rs +0 -0
  43. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/mod.rs +0 -0
  44. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/tokens.rs +0 -0
  45. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/lib.rs +0 -0
  46. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/grammar.pest +0 -0
  47. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/mod.rs +0 -0
  48. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/parser.rs +0 -0
  49. {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/tokens.rs +0 -0
  50. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/__init__.py +0 -0
  51. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/__init__.py +0 -0
  52. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/conftest.py +0 -0
  53. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_binary_eq.py +0 -0
  54. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_binary_op.py +0 -0
  55. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_binary_op_bool.py +0 -0
  56. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_default_values.py +0 -0
  57. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_field_access.py +0 -0
  58. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_for_expr.py +0 -0
  59. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_func.py +0 -0
  60. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_let.py +0 -0
  61. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_nested.py +0 -0
  62. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_render_comment.py +0 -0
  63. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_script.py +0 -0
  64. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_str_method.py +0 -0
  65. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_types.py +0 -0
  66. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_unary.py +0 -0
  67. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_core.py +0 -0
  68. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_named_component.py +0 -0
  69. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_attributes.py +0 -0
  70. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_context.py +0 -0
  71. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_globals.py +0 -0
  72. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_globals_obj.py +0 -0
  73. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_globals_obj2.py +0 -0
  74. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_nested_dict.py +0 -0
  75. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_nested_node.py +0 -0
  76. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_node.py +0 -0
  77. {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_script.py +0 -0
@@ -1,8 +1,16 @@
1
+ ## 0.7.0 - 2025-10-10
2
+
3
+ * Release triple quote string with auto dedent.
4
+
5
+ ## 0.6.10 - 2025-10-05
6
+
7
+ * Fix truthy comparison for any python objects.
8
+
1
9
  ## 0.6.9 - 2025-10-04
2
10
 
3
11
  * Drop wheel for i686 for windows 11 for python 3.9,3.10 and 3.11 since
4
12
  it does not build anymore.
5
- * Update python setup to v6
13
+ * Update python setup to v6.
6
14
 
7
15
  ## 0.6.8 - 2025-10-04
8
16
 
@@ -595,7 +595,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
595
595
 
596
596
  [[package]]
597
597
  name = "xcore"
598
- version = "0.6.9"
598
+ version = "0.7.0"
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.6.9"
3
+ version = "0.7.0"
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.6.9
3
+ Version: 0.7.0
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.6.9"
3
+ version = "0.7.0"
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" }]
@@ -45,7 +45,10 @@ class Catalog:
45
45
  Render the given markup.
46
46
 
47
47
  :param content: The markup to render
48
- :param params: Global variables that does not need to do props drilling.
48
+ :param params: rendering context.
49
+ the special key "globals" of the rendering context is passed
50
+ to all children during the rendering, other variable requires
51
+ a "props drilling".
49
52
  :return: the rendered template.
50
53
  """
51
54
  return self._catalog.render(content, **params)
@@ -193,19 +193,13 @@ impl Truthy for Literal {
193
193
  Literal::Uuid(_) => true,
194
194
  Literal::XNode(_) => true,
195
195
  Literal::Callable(_) => true,
196
- Literal::Object(o) => {
197
- Python::with_gil(|py| {
198
- match o
199
- .obj()
200
- .into_pyobject(py)
201
- .unwrap()
202
- .call_method("__bool__", (), None)
203
- {
204
- Ok(b) => b.extract::<bool>().unwrap(),
205
- Err(_) => false, // or panic/log
206
- }
207
- })
208
- }
196
+ Literal::Object(o) => Python::with_gil(|py| {
197
+ let builtins = PyModule::import(py, "builtins").unwrap();
198
+ let boolcls = builtins.getattr("bool").unwrap();
199
+ let v = o.obj().into_pyobject(py).unwrap();
200
+ let ret: bool = boolcls.call1((v,)).unwrap().extract().unwrap();
201
+ ret
202
+ }),
209
203
  Literal::List(items) => !items.is_empty(),
210
204
  Literal::Dict(d) => !d.is_empty(),
211
205
  }
@@ -24,10 +24,15 @@ operator = { "+" | "-" | "*" | "/" | "and" | "or" | "==" | "!=" | ">=" | "<=" |
24
24
 
25
25
  boolean = { "true" | "false" }
26
26
  integer = @{ (ASCII_DIGIT | "_")+ }
27
- string = @{
27
+ dedent_string = @{
28
+ "\"\"\"" ~ (escape_sequence | !("\"\"\"" | "\\") ~ ANY)* ~ "\"\"\""
29
+ | "'''" ~ (escape_sequence | !("'''" | "\\") ~ ANY)* ~ "'''"
30
+ }
31
+ normal_string = @{
28
32
  ("\"" ~ (escape_sequence | !("\"" | "\\") ~ ANY)* ~ "\"")
29
33
  | ("'" ~ (escape_sequence | !("'" | "\\") ~ ANY)* ~ "'")
30
34
  }
35
+ string = _{ dedent_string | normal_string }
31
36
 
32
37
  keyword = { "for" | "in" | "if" | "else" | "not" | "and" | "or" | "let" }
33
38
  keyword_spaced = { keyword ~ (whitespace+ | ".") }
@@ -143,7 +143,39 @@ fn parse_expression_token(pair: Pair<Rule>) -> Result<ExpressionToken, String> {
143
143
  debug!("Pushing boolean {}", value);
144
144
  Ok(ExpressionToken::Boolean(value))
145
145
  }
146
- Rule::string => {
146
+ Rule::dedent_string => {
147
+ let value = pair.as_str();
148
+ let mut vstr = value[3..value.len() - 3].to_string();
149
+ if vstr.starts_with('\n') {
150
+ let lines: Vec<&str> = vstr[1..].split('\n').collect();
151
+ if !lines.is_empty() {
152
+ // Find the minimum leading whitespace from non-empty lines
153
+ let min_lpad = lines
154
+ .iter()
155
+ .filter(|line| !line.trim().is_empty())
156
+ .map(|line| line.chars().take_while(|c| c.is_whitespace()).count())
157
+ .min()
158
+ .unwrap_or(0);
159
+
160
+ // Dedent all lines by min_lpad
161
+ let dedented_lines: Vec<String> = lines
162
+ .iter()
163
+ .map(|line| {
164
+ if line.chars().take_while(|c| c.is_whitespace()).count() >= min_lpad {
165
+ line[min_lpad..].to_string()
166
+ } else {
167
+ line.to_string()
168
+ }
169
+ })
170
+ .collect();
171
+ vstr = dedented_lines.join("\n");
172
+ }
173
+ }
174
+
175
+ debug!("Pushing dedent string {}", vstr);
176
+ Ok(ExpressionToken::String(vstr))
177
+ }
178
+ Rule::normal_string => {
147
179
  let value = pair.as_str();
148
180
  let vstr = value[1..value.len() - 1].to_string();
149
181
  debug!("Pushing string {}", vstr);
@@ -1,3 +1,4 @@
1
+ from typing_extensions import Any
1
2
  import pytest
2
3
 
3
4
  from xcomponent import Catalog
@@ -41,7 +42,7 @@ def IfSelfClosedComponent(a: bool) -> str:
41
42
 
42
43
 
43
44
  @catalog.component
44
- def IfComponent(a: bool) -> str:
45
+ def IfComponent(a: Any) -> str:
45
46
  return """<>{if a { <p>Ha ha!</p> } }</>"""
46
47
 
47
48
 
@@ -83,6 +84,8 @@ def Hint(text: str | None = None) -> str:
83
84
  pytest.param(IfSelfClosedComponent(False), ""),
84
85
  pytest.param(IfComponent(True), "<p>Ha ha!</p>"),
85
86
  pytest.param(IfComponent(False), ""),
87
+ pytest.param(IfComponent(object()), "<p>Ha ha!</p>"),
88
+ pytest.param(IfComponent(None), ""),
86
89
  pytest.param(Hint(), ""),
87
90
  pytest.param(Hint("I exist"), "<span>I exist</span>"),
88
91
  ],
@@ -0,0 +1,114 @@
1
+ from xcomponent import Catalog
2
+
3
+ import pytest
4
+ import textwrap
5
+
6
+
7
+ @pytest.fixture(autouse=True)
8
+ def components(catalog: Catalog):
9
+ @catalog.component
10
+ def TripleSingleQuote() -> str:
11
+ return """
12
+ <>
13
+ {
14
+ '''
15
+ The lazy dog jumped over the quick brown fox.
16
+ The lazy dog jumped over the quick brown fox.
17
+ The lazy dog jumped over the quick brown fox.
18
+ '''
19
+ }
20
+ </>
21
+ """
22
+
23
+ @catalog.component
24
+ def TripleDoubleQuote() -> str:
25
+ return '''
26
+ <>
27
+ {
28
+ """
29
+ The lazy dog jumped over the quick brown fox.
30
+ The lazy dog jumped over the quick brown fox.
31
+ The lazy dog jumped over the quick brown fox.
32
+ """
33
+ }
34
+ </>
35
+ '''
36
+
37
+ @catalog.component
38
+ def SafeDedent() -> str:
39
+ return """
40
+ <>
41
+ {
42
+ '''The lazy dog jumped over the quick brown fox.
43
+ The lazy dog jumped over the quick brown fox.
44
+ The lazy dog jumped over the quick brown fox.
45
+ '''
46
+ }
47
+ </>
48
+ """
49
+
50
+ @catalog.component
51
+ def RevertDedent() -> str:
52
+ return """
53
+ <>
54
+ {
55
+ '''
56
+ The lazy dog jumped over the quick brown fox.
57
+ The lazy dog jumped over the quick brown fox.
58
+ The lazy dog jumped over the quick brown fox.
59
+ '''
60
+ }
61
+ </>
62
+ """
63
+
64
+ return TripleSingleQuote, TripleDoubleQuote, SafeDedent, RevertDedent
65
+
66
+
67
+ @pytest.mark.parametrize(
68
+ "template_string,expected",
69
+ [
70
+ pytest.param(
71
+ "<TripleSingleQuote />",
72
+ textwrap.dedent(
73
+ """\
74
+ The lazy dog jumped over the quick brown fox.
75
+ The lazy dog jumped over the quick brown fox.
76
+ The lazy dog jumped over the quick brown fox.
77
+ """
78
+ ),
79
+ id="single",
80
+ ),
81
+ pytest.param(
82
+ "<TripleDoubleQuote />",
83
+ textwrap.dedent(
84
+ """\
85
+ The lazy dog jumped over the quick brown fox.
86
+ The lazy dog jumped over the quick brown fox.
87
+ The lazy dog jumped over the quick brown fox.
88
+ """
89
+ ),
90
+ id="double",
91
+ ),
92
+ pytest.param(
93
+ "<SafeDedent />",
94
+ """The lazy dog jumped over the quick brown fox.
95
+ The lazy dog jumped over the quick brown fox.
96
+ The lazy dog jumped over the quick brown fox.
97
+ """,
98
+ id="safe",
99
+ ),
100
+ pytest.param(
101
+ "<RevertDedent />",
102
+ textwrap.dedent(
103
+ """\
104
+ The lazy dog jumped over the quick brown fox.
105
+ The lazy dog jumped over the quick brown fox.
106
+ The lazy dog jumped over the quick brown fox.
107
+ """
108
+ ),
109
+ id="revert",
110
+ ),
111
+ ],
112
+ )
113
+ def test_render_dedent_str(catalog: Catalog, template_string: str, expected: str):
114
+ assert catalog.render(template_string) == expected
@@ -598,7 +598,7 @@ wheels = [
598
598
 
599
599
  [[package]]
600
600
  name = "xcomponent"
601
- version = "0.6.9"
601
+ version = "0.7.0"
602
602
  source = { editable = "." }
603
603
 
604
604
  [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