-
Notifications
You must be signed in to change notification settings - Fork 152
Upgrade Jinja package to version 2.0.0 #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you very much for contributing this PR! I’ve run some tests and found a few issues:
let template = try Template("{{ 'invalid'|int(default=99) }}")
let result = try template.render([:])
#expect(result == "99", "Should return default value when conversion fails")import jinja2
template = jinja2.Template("""
{{ 'invalid'|int(default=99) }}
""")
print(template.render({}))
let context = [
"users": Value.array([
.object(["name": .string("John"), "age": .int(30)]),
.object(["name": .string("Jane"), "age": .int(25)]),
.object(["name": .string("Bob"), "age": .int(35)])
])
]
let template = try Template("{{ (users|max(attribute='age')).name }}")
let result = try template.render(context)
#expect(result == "Bob", "Should return user with highest age")import jinja2
template = jinja2.Template("""
{{ (users|max(attribute='age')).name }}
""")
print(template.render({
'users': [
{"name": "John", "age": 30},
{"name": "Jane", "age": 25},
{"name": "Bob", "age": 35}
]
}))
let context = [
"items": Value.array([
.string("hello"),
.string(""),
.string("world"),
.null,
.string("test")
])
]
let template = try Template("{{ items|select|join(',') }}")
let result = try template.render(context)
#expect(result == "hello,world,test", "Should select truthy values")import jinja2
template = jinja2.Template("""
{{ items|select|join(',') }}
""")
print(template.render({
'items': [
"hello",
"",
"world",
None,
"test"
]
}))
let template = try Template("{{ text|escape }}")
let result = try template.render(["text": .string("<\">& ")])
#expect(result == "<">& ", "Should use numeric entities for quotes")import jinja2
template = jinja2.Template("""
{{ text|escape }}
""")
print(template.render({
'text': '<">& '
})) |
11188db to
00172f6
Compare
|
@johnmai-dev That's super helpful! Thank you for going through everything with a fine-toothed comb. I just opened a PR fixing those issues here: huggingface/swift-jinja#3 |
e5c41be to
5830fc5
Compare
|
Converted to draft until 2.0.0 release is available and we can revert / drop 5830fc5. |
Related to huggingface/swift-jinja#26