Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bowbahdoe/template-processor
Clojure library which provides StringTemplate-like functionality
https://github.com/bowbahdoe/template-processor
Last synced: 7 days ago
JSON representation
Clojure library which provides StringTemplate-like functionality
- Host: GitHub
- URL: https://github.com/bowbahdoe/template-processor
- Owner: bowbahdoe
- Created: 2024-03-05T01:24:23.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-03-09T19:07:44.000Z (8 months ago)
- Last Synced: 2024-03-09T20:24:28.416Z (8 months ago)
- Language: HTML
- Size: 16.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Template Processing for Clojure
This library provides equivalent functionality to
`java.lang.StringTemplate`.**NOTE**: The underlying design of string templates seems [set to change](https://mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004010.html)
and explicit template processors will probably go away. I'll try to update this once a JDK with those changes lands so the `<<` macro will still function once/if the `StringTemplate$Processor`
interface goes away.## Dependency Info
```clojure
io.github.bowbahdoe/template-processor {:git/sha "90bf859354405b62e9e98cd3aaa4e412006bf566"}
```## How to Use
Templates are initialized using the `<<` macro. Each
call to `<<` needs a template processor which determines
how the template will be processed and a string literal
that will be scanned for replacements.```clojure
=> (require '[io.github.bowbahdoe.template-processor
:as template-processor
:refer [<<]])
nil
=> (def name "bobbie")
#'name
=> (<< template-processor/str "Hello ~{name}")
"Hello bobbie"
=> (<< template-processor/str "Len: ~(.length name)")
"Len: 6"
=> (<< template-processor/sqlvec "SELECT * FROM table WHERE name=~{name}")
["SELECT * FROM table WHERE name=?" "bobbie"]
````~{}` is used for substituting constant values, `~()` for full expressions.