Skip to content

akond/string-template

Repository files navigation

Clojars Project

A Clojure wrapper around StringTemplate.

This is a Proof of concept. Do not use in production.

Rationale

  • A paper "Enforcing Strict Model-View Separation in Template Engines" by Terence Parr.
  • Cover the monstrosity of Java with joy and loveliness of Clojure
  • Labor est etiam ipse voluptas

Resources

Examples

Hello, world

(require '[com.github.akond.string-template.core :as st])
(let [t (st/template "Hello, <name>!")]
	(-> t (merge {:name "world"}) str))
=> "Hello, world!"

Using template groups

(let [g (st/group (io/file "example.stg"))]
	(-> g :greet (merge {:hellos ["Hi" "Guten morgen" "Buenos dias"]}) print))
=>
Hi, world!
Guten morgen, world!
Buenos dias, world!

File example.stg:

greet(hellos) ::= <<
<hellos: world()>
>>

world(item) ::= <<
<item>, world!

>>

See more examples in the tests.

About

A Clojure wrapper around StringTemplate

Resources

License

Stars

Watchers

Forks