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.
- {xcomponent-0.6.9 → xcomponent-0.7.0}/CHANGELOG.md +9 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/Cargo.lock +1 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/Cargo.toml +1 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/PKG-INFO +1 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/pyproject.toml +1 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/service/catalog.py +4 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/context.rs +7 -13
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/grammar.pest +6 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/parser.rs +33 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_if_expr.py +4 -1
- xcomponent-0.7.0/tests/unittests/expression/test_str_dedent.py +114 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/uv.lock +1 -1
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/build-sdist.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/build-wheels.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/publish-doc.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/publish-pypi.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/release.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/tests-artifacts.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.github/workflows/tests.yml +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.gitignore +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/.python-version +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/Justfile +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/LICENSE +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/README.md +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/Makefile +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/conf.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/develop/.gitkeep +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/index.md +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/user/changelog.md +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/docs/source/user/getting_started.md +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/scripts/get_version.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/scripts/write_changelog.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/__init__.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/py.typed +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/service/__init__.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/python/xcomponent/xcore.pyi +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/catalog/catalog.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/catalog/mod.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/eval.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/mod.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/model.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/ast/parse.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/mod.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/expression/tokens.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/lib.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/grammar.pest +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/mod.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/parser.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/src/rust/markup/tokens.rs +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/__init__.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/__init__.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/conftest.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_binary_eq.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_binary_op.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_binary_op_bool.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_default_values.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_field_access.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_for_expr.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_func.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_let.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_nested.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_render_comment.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_script.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_str_method.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_types.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/expression/test_unary.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_core.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_named_component.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_attributes.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_context.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_globals.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_globals_obj.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_globals_obj2.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_nested_dict.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_nested_node.py +0 -0
- {xcomponent-0.6.9 → xcomponent-0.7.0}/tests/unittests/test_render_node.py +0 -0
- {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
|
|
|
@@ -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:
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
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::
|
|
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:
|
|
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
|
|
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
|