Skip to content

Clojure library which provides StringTemplate-like functionality

Notifications You must be signed in to change notification settings

bowbahdoe/template-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Template Processing for Clojure

This library provides equivalent functionality to java.lang.StringTemplate.

NOTE: The underlying design of string templates seems set to change 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

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.

=> (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.

About

Clojure library which provides StringTemplate-like functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published