xcomponent 0.8.2__tar.gz → 0.8.3__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.2 → xcomponent-0.8.3}/CHANGELOG.md +4 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/Cargo.lock +1 -1
- {xcomponent-0.8.2 → xcomponent-0.8.3}/Cargo.toml +1 -1
- {xcomponent-0.8.2 → xcomponent-0.8.3}/PKG-INFO +1 -1
- {xcomponent-0.8.2 → xcomponent-0.8.3}/pyproject.toml +1 -1
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/i18n.rs +46 -3
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/markup/tokens.rs +4 -4
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/adapters/test_babel.py +127 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/uv.lock +1 -1
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/build-sdist.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/build-wheels.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/publish-doc.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/publish-pypi.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/release.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/tests-artifacts.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.github/workflows/tests.yml +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.gitignore +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/.python-version +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/Justfile +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/LICENSE +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/README.md +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/docs/Makefile +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/docs/source/conf.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/docs/source/develop/.gitkeep +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/docs/source/index.md +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/docs/source/user/changelog.md +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/docs/source/user/getting_started.md +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/scripts/get_version.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/scripts/write_changelog.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/adapters/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/adapters/babel.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/py.typed +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/service/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/service/catalog.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/python/xcomponent/xcore.pyi +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/catalog/catalog.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/catalog/mod.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/context.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/ast/eval.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/ast/mod.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/ast/model.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/ast/parse.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/grammar.pest +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/mod.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/parser.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/expression/tokens.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/lib.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/markup/grammar.pest +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/markup/mod.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/src/rust/markup/parser.rs +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/i18n/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/i18n/babel.ini +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/i18n/fr.mo +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/i18n/fr.po +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/i18n/mydomain.pot +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/functionals/i18n/test_l10n.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/adapters/__init__.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/conftest.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_binary_eq.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_binary_op.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_binary_op_bool.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_default_values.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_field_access.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_for_expr.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_func.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_if_expr.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_let.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_nested.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_render_comment.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_script.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_str_dedent.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_str_method.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_types.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/expression/test_unary.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_core.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_named_component.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_attributes.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_context.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_globals.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_globals_obj.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_globals_obj2.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_nested_dict.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_nested_node.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_node.py +0 -0
- {xcomponent-0.8.2 → xcomponent-0.8.3}/tests/unittests/test_render_script.py +0 -0
|
@@ -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,53 @@ 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
|
+
if let XNode::Expression(expr) = child {
|
|
305
|
+
res.extend(extract_expr_i18n_messages(expr.expression())?);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
AST::Literal(Literal::XNode(XNode::Expression(expr))) => {
|
|
310
|
+
res.extend(extract_expr_i18n_messages(expr.expression())?);
|
|
311
|
+
}
|
|
269
312
|
_ => {
|
|
270
313
|
warn!("Ignoring {:?} while extracting messages", ast);
|
|
271
314
|
}
|
|
272
315
|
}
|
|
273
|
-
res
|
|
316
|
+
Ok(res)
|
|
274
317
|
}
|
|
275
318
|
|
|
276
319
|
#[pyfunction]
|
|
@@ -278,5 +321,5 @@ pub(crate) fn extract_expr_i18n_messages(raw: &str) -> PyResult<Vec<ExtractedMes
|
|
|
278
321
|
let token = tokenize(raw)?;
|
|
279
322
|
let ast = parse(&[token], 0)?;
|
|
280
323
|
|
|
281
|
-
|
|
324
|
+
extract_from_ast(ast)
|
|
282
325
|
}
|
|
@@ -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,133 @@ 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 diamon",
|
|
335
|
+
),
|
|
336
|
+
pytest.param(
|
|
337
|
+
"""
|
|
338
|
+
<BaseLayout>
|
|
339
|
+
{ let trad = globals.gettext("here we go") }
|
|
340
|
+
<A href="/">{trad}</A>
|
|
341
|
+
</BaseLayout>
|
|
342
|
+
""",
|
|
343
|
+
[
|
|
344
|
+
(
|
|
345
|
+
1,
|
|
346
|
+
"gettext",
|
|
347
|
+
"here we go",
|
|
348
|
+
empty_comment,
|
|
349
|
+
),
|
|
350
|
+
],
|
|
351
|
+
id="let",
|
|
352
|
+
),
|
|
226
353
|
],
|
|
227
354
|
)
|
|
228
355
|
def test_extract_from_markup(markup: XNode, expected: list[ExtractionInfo]):
|
|
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
|
|
File without changes
|
|
File without changes
|