Kilt
Generic template interface for Crystal
Install / Use
/learn @jeromegn/KiltREADME
Kilt 
Generic templating interface for Crystal.
Goal
Simplify developers' lives by abstracting template rendering for multiple template languages.
Supported out of the box
| Language | File extensions | Required libraries | Maintainer | | -------- | --------------- | ------------------ | ---------- | | ECR | .ecr | none (part of the stdlib) | | | Mustache | .mustache | crustache | @MakeNowJust | | Slang | .slang | slang | @jeromegn | | Temel | .temel | temel | @f | | Crikey | .crikey | crikey | @domgetter | | Liquid | .liquid | liquid | @docelic | | Jbuilder | .jbuilder | jbuilder | @shootingfly | | Water | .water | water | @shootingfly |
See also: Registering your own template engine.
Installation
Add this to your application's shard.yml:
dependencies:
kilt:
github: jeromegn/kilt
# Any other template languages Crystal shard
Usage
- Kilt essentially adds two macros
Kilt.embedandKilt.file, the code is really simple. - Add template language dependencies, as listed in the support table above.
Both macros take a filename and a io_name (the latter defaults to "__kilt_io__")
Example
require "kilt"
# For slang, add:
require "kilt/slang"
# With a Class
class YourView
Kilt.file("path/to/template.ecr") # Adds a to_s method
end
puts YourView.new.to_s # => <compiled template>
# Embedded
str = Kilt.render "path/to/template.slang"
# or
str = String.build do |__kilt_io__|
Kilt.embed "path/to/template.slang"
end
puts str # => <compiled template>
Registering your own template engine
Use Kilt.register_engine(extension, embed_command) macro:
require "kilt"
module MyEngine
macro embed(filename, io_name)
# ....
end
end
Kilt.register_engine("myeng", MyEngine.embed)
This can be part of your own my-engine library: in this case it should depend
on kilt directly, or this could be a part of adapter library, like:
kilt-my-engine, which will depend on both kilt and my-engine.
Contributing
Please contribute your own "adapter" if you create a template language for Crystal that's not yet supported here!
- Fork it ( https://github.com/jeromegn/kilt/fork )
- Create your feature branch (git checkout -b my-awesome-template-language)
- Commit your changes (git commit -am 'Add my-awesome-template-language')
- Push to the branch (git push origin my-awesome-template-language)
- Create a new Pull Request
Contributors
- jeromegn Jerome Gravel-Niquet - creator, maintainer
- waterlink Oleksii Fedorov
- MakeNowJust TSUYUSATO Kitsune
- f Fatih Kadir Akın
Related Skills
node-connect
341.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
