Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kaappi-template

Text and HTML template engine for Kaappi Scheme.

Pure Scheme — no C dependencies, no build step.

Install

thottam install kaappi-template

Quick start

(import (kaappi template))

;; Plain text (no escaping)
(template-render "Hello, {{.name}}!" '(("name" . "Alice")))
;=> "Hello, Alice!"

;; HTML (auto-escapes <>&"')
(template-render-html "<p>{{.content}}</p>"
  '(("content" . "<script>alert('xss')</script>")))
;=> "<p>&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;</p>"

Template syntax

Variables

{{.name}}          Access a key from the data alist
{{.user.email}}    Nested access (dotted path)
{{.}}              Current value (useful inside range)

Conditionals

{{if .show}}
  This is visible
{{end}}

{{if .logged_in}}
  Welcome!
{{else}}
  Please log in.
{{end}}

Falsy values: #f, 'null, "", (), 0

Loops

{{range .items}}
  Item: {{.}}
{{end}}

{{range .users}}
  {{.name}} ({{.email}})
{{end}}

API

(template-render template-string data)       ; plain text (no escaping)
(template-render-html template-string data)  ; HTML (auto-escapes)

Data is an alist: '(("key" . value) ...). Nested data uses nested alists.

Lower-level API

(template-parse template-string)             ; parse to AST (reusable)
(template-execute ast data escape-fn)        ; execute with custom escape
(html-escape string)                         ; HTML entity escaping

License

MIT

About

Go-style text and HTML template engine for Kaappi Scheme

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages