Liquid template engine for Crystal.
Liquid templating language : http://shopify.github.io/liquid/
Add this to your application's shard.yml
:
dependencies:
liquid:
github: TechMagister/liquid.cr
require "liquid"
txt = "
{% if kenny.sick %}
Kenny is sick.
{% elsif kenny.dead %}
You killed Kenny! You ***!!!
{% else %}
Kenny looks okay --- so far
{% endif %}
"
ctx = Liquid::Context.new
ctx.set "kenny", { "sick" => false, "dead" => true}
tpl = Liquid::Template.parse txt # tpl can be cached and reused
result = tpl.render ctx
# result = "
# You killed Kenny! You ***!!!
#
# "
Tags can be escaped :
\{% assign myvar = 15 %}
will render {% assign myvar = 15 %}
Cache block ( only support caching using redis ) : https://github.com/TechMagister/liquid-cache.cr
- abs
- append
- camelcase | camelize
- capitalize
- ceil
- compact
- date
- default
- divided_by
- downcase
- escape
- escape_once
- first
- floor
- join
- last
- lstrip
- map
- minus
- modulo
- newline_to_br
- pluralize
- plus
- prepend
- remove
- remove_first
- replace
- replace_first
- reverse
- round
- rstrip
- size
- slice
- sort
- sort_natural
- split
- strip
- strip_html
- strip_newlines
- times
- truncate
- truncatewords
- underscore
- uniq
- upcase | uppercase
TODO:
- Basic For loops
- Basic If Elsif Else
- Add variable assignment ( {% assign var = "Hello World" %} )
- Add support for multiple operator ( no operator precedence support ( for now ))
- Add support for Array into for loop
- Add support for Hash into for loop ( {% for key, val in myhash %} )
- Add support for Float
- Add iteration over Arrays
- Improve data interface
- Add Filter support
- Add capture block
- Add increment block
- Add decrement block
- Add "contains" keyword
- Add support for Array into expressions
- Add case/when
- Add syntax checking
- Improve expression parsing
- Add Everything that's missing [https://shopify.github.io/liquid/]
- Fork it ( https://github.com/TechMagister/liquid.cr/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
- TechMagister Arnaud Fernandés - creator, maintainer
- docelic Davor Ocelic