https://github.com/johnmai-dev/Jinja
A minimalistic Swift implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.
https://github.com/johnmai-dev/Jinja
Last synced: about 1 year ago
JSON representation
A minimalistic Swift implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.
- Host: GitHub
- URL: https://github.com/johnmai-dev/Jinja
- Owner: johnmai-dev
- License: mit
- Created: 2024-03-20T16:22:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-27T05:07:20.000Z (over 1 year ago)
- Last Synced: 2025-04-10T20:24:10.326Z (about 1 year ago)
- Language: Swift
- Size: 152 KB
- Stars: 47
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jinja
A minimalistic Swift implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.
## SwiftPM
To use `Jinja` with SwiftPM, you can add this to your `Package.swift`:
```
dependencies: [
.package(url: "https://github.com/maiqingqiang/Jinja", branch: "main")
]
```
And then, add the Transformers library as a dependency to your target:
```
targets: [
.target(
name: "YourTargetName",
dependencies: [
.product(name: "Jinja", package: "Jinja")
]
)
]
```
## Usage
```swift
import Jinja
let template = """
{% for item in items %}
{{ item }}
{% endfor %}
"""
let context = [
"items": [
"item1",
"item2",
"item3"
]
]
let result = try Template(template).render(context)
```