https://github.com/joshday/stringtemplates.jl
Speedy customizable string interpolation for Julia.
https://github.com/joshday/stringtemplates.jl
julia julia-language string-interpolation
Last synced: 3 months ago
JSON representation
Speedy customizable string interpolation for Julia.
- Host: GitHub
- URL: https://github.com/joshday/stringtemplates.jl
- Owner: joshday
- License: mit
- Created: 2024-01-08T15:41:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-28T15:16:59.000Z (9 months ago)
- Last Synced: 2025-03-24T08:54:52.677Z (3 months ago)
- Topics: julia, julia-language, string-interpolation
- Language: Julia
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StringTemplates
[](https://github.com/joshday/StringTemplates.jl/actions/workflows/CI.yml?query=branch%3Amain)
Speedy customizable string interpolation for Julia.
## Usage
```julia
using StringTemplates, JSON3# Here's a template. It uses Julia's interpolation syntax.
t = @template "PlotlyJS.newPlot(\"my_id\", $data, {}, {})"# `render` with anything that has Symbol keys or with keyword arguments
render(t, data = "[{\"y\": [1, 2]}]")
# "PlotlyJS.newPlot(\"my_id\", [{\"y\":[1,2]}], {}, {})"# Alternatively, you can provide a custom print function
t2 = @template "PlotlyJS.newPlot(\"my_id\", $data, {}, {})" JSON3.writerender(t2, data=[(; y=1:2)])
# "PlotlyJS.newPlot(\"my_id\", [{\"y\":[1,2]}], {}, {})"
```## Benchmarks
In our two benchmarks at `benchmarks/suite.jl` we find that **StringTemplates** is:
- 1.7 - 2.5x faster than [Base string interpolation](https://docs.julialang.org/en/v1/manual/strings/#string-interpolation).
- 10.1 - 18.6x faster than [Mustache.jl](https://github.com/jverzani/Mustache.jl).