Lightweight, terse, templating language for Crystal.
Add this to your application's shard.yml
:
dependencies:
slang:
github: jeromegn/slang
Kilt is included as a dependency for this project. It should help integrating non-ECR template engines.
require "kilt/slang"
Kilt.render("path/to/file.slang") #=> <compiled template>
Example with Kemal (includes Kilt):
require "kilt/slang"
get "/" do
render "path/to/file.slang"
end
String.build do |str|
Slang.embed("path/to/file.slang", "str")
end
doctype html
html
head
title This is a title
body
span#some-id.classname
#hello.world.world2
- some_var = "hello world haha"
span
span data-some-var=some_var two-attr="fun" and a #{p("hello")}
span
span.deep_nested
= Process.pid
| text node
' other text node
span.alongside pid=Process.pid
custom-tag#with-id pid="#{Process.pid}"
- ["ah", "oh"].each do |s|
span = s
#amazing-div some-attr="hello"
Given the context:
some_var = "hello"
strings = ["ah", "oh"]
Compiles to HTML:
<!DOCTYPE html>
<html>
<head>
<title>This is a title</title>
</head>
<body>
<span id="some-id" class="classname">
<div id="hello" class="world world2">
<span>
<span data-some-var="hello world haha" two-attr="fun">and a hello</span>
<span>
<span class="deep_nested">
#{Process.pid}
text node
other text node
</span>
</span>
</span>
<span class="alongside" pid="#{Process.pid}">
<custom-tag id="with-id" pid="#{Process.pid}">
<span>ah</span>
<span>oh</span>
</custom-tag>
</span>
</div>
</span>
<div id="amazing-div" some-attr="hello"></div>
</body>
</html>
- Fix known limitations
- More tests
- Website
- Documentation
- Fork it ( https://github.com/jeromegn/slang/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request