bowbahdoe / template-processor

Clojure library which provides StringTemplate-like functionality

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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


Languages

Language:HTML 65.1%Language:Clojure 34.9%